diff --git a/CHANGELOG.md b/CHANGELOG.md index e63bd7e..e113d07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,9 @@ - Resolver Support for Documents - Asynchronous Runtime Balancer, new option `priority` -- Export/Import Worker Indexes + Document Worker +- Export/Import Worker Indexes + Document Worker, new extern config options `export` and `import` - Improved interoperability of the different build packages, including source folder +- Support custom `filter` function for encoder (stop-word filter) ### v0.8.0 diff --git a/README.md b/README.md index 0bf18a5..2d6a788 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ FlexSearch v0.8: [Overview and Migration Guide](doc/0.8.0.md) + - Basic Start  •  API Reference  •  diff --git a/dist/db/clickhouse/index.cjs b/dist/db/clickhouse/index.cjs index eab72f8..81e9a05 100644 --- a/dist/db/clickhouse/index.cjs +++ b/dist/db/clickhouse/index.cjs @@ -28,7 +28,6 @@ function toArray(val, stringify){ return result; } -// COMPILER BLOCK --> const defaults = { host: "http://localhost", port: "8123", @@ -200,8 +199,8 @@ ClickhouseDB.prototype.open = async function(){ }; ClickhouseDB.prototype.close = function(){ - this.db.close(); - this.db = null; + //DB && DB.close(); + this.db = DB = null; return this; }; @@ -361,19 +360,18 @@ ClickhouseDB.prototype.enrich = async function(ids){ : result; }; -ClickhouseDB.prototype.has = function(id){ - return this.db.query(` - SELECT EXISTS( - SELECT 1 - FROM ${this.id}.reg - WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}} - LIMIT 1 - )`, +ClickhouseDB.prototype.has = async function(id){ + const result = await this.db.query(` + SELECT 1 as exist + FROM ${this.id}.reg + WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}} + LIMIT 1`, { params: { id }} ).toPromise(); + return !!(result && result[0] && result[0].exist); }; -ClickhouseDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = true, tags){ +ClickhouseDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ let rows; if(query.length > 1 && flexsearch.depth){ @@ -406,7 +404,7 @@ ClickhouseDB.prototype.search = function(flexsearch, query, limit = 100, offset ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM ${ this.id }.ctx${ this.field } WHERE ${ where } GROUP BY id @@ -472,7 +470,7 @@ ClickhouseDB.prototype.search = function(flexsearch, query, limit = 100, offset ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM ${ this.id }.map${ this.field } WHERE ${ where } GROUP BY id diff --git a/dist/db/indexeddb/index.js b/dist/db/indexeddb/index.js index daa5503..5ffc873 100644 --- a/dist/db/indexeddb/index.js +++ b/dist/db/indexeddb/index.js @@ -136,7 +136,7 @@ IdxDB.prototype.open = function(){ }; IdxDB.prototype.close = function(){ - this.db.close(); + this.db && this.db.close(); this.db = null; }; @@ -283,7 +283,9 @@ IdxDB.prototype.has = function(id){ const transaction = this.db.transaction("reg", "readonly"); const map = transaction.objectStore("reg"); const req = map.getKey(id); - return promisfy(req); + return promisfy(req).then(function(result){ + return !!result; + }); }; IdxDB.prototype.search = null; diff --git a/dist/db/mongodb/index.cjs b/dist/db/mongodb/index.cjs index 1502591..c6eb4a6 100644 --- a/dist/db/mongodb/index.cjs +++ b/dist/db/mongodb/index.cjs @@ -144,8 +144,9 @@ MongoDB.prototype.open = async function(){ }; MongoDB.prototype.close = function(){ - this.db.close(); - this.db = null; + //CLIENT && CLIENT.close(); + this.db = CLIENT = null; + DB[this.id] = null; return this; }; @@ -329,7 +330,9 @@ MongoDB.prototype.enrich = function(ids){ }; MongoDB.prototype.has = function(id){ - return this.db.collection("reg").countDocuments({ id }, { limit: 1 }); + return this.db.collection("reg").countDocuments({ id }, { limit: 1 }).then(function(result){ + return !!result; + }); }; MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ @@ -352,16 +355,17 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset keyword = term; } - let project = resolve - ? { _id: 1 } - : { _id: 1, res: 1 }; + + const project = { _id: 1 }; + if(!resolve) project["res"] = 1; + if(enrich) project["doc"] = 1; const stmt = [ { $match: { $or: params } }, { $group: { _id: "$id", - res: suggest ? { $sum: 1 } : { $min: 1 }, - count: { $sum: 1 } + count: { $sum: 1 }, + res: suggest ? { $sum: "$res" } : { $sum /*$min*/: "$res" } } } ]; @@ -403,15 +407,10 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset } stmt.push( - { $project: project }, + //{ $project: project }, { $match: match } ); } - else { - stmt.push( - { $project: project } - ); - } stmt.push( { $sort: suggest @@ -421,23 +420,23 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset { $limit: limit } ); - if(tags){ - project = { _id: 1 }; - if(!resolve) project["res"] = 1; - if(enrich) project["doc"] = 1; + // if(tags){ + // project = { _id: 1 }; + // if(!resolve) project["res"] = 1; + // if(enrich) project["doc"] = 1; + // } - stmt.push( - { $project: project } - ); - } + stmt.push( + { $project: project } + ); rows = await this.db.collection("ctx" + this.field).aggregate(stmt); } else { - let project = resolve - ? { _id: 1 } - : { _id: 1, res: 1 }; + const project = { _id: 1 }; + if(!resolve) project["res"] = 1; + if(enrich) project["doc"] = 1; const stmt = [ { $match: { @@ -445,8 +444,8 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset } }, { $group: { _id: "$id", - res: suggest ? { $sum: 1 } : { $min: 1 }, - count: { $sum: 1 } + count: { $sum: 1 }, + res: suggest ? { $sum: "$res" } : { $sum /*$min*/: "$res" } } } ]; @@ -488,15 +487,10 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset } stmt.push( - { $project: project }, + //{ $project: project }, { $match: match } ); } - else { - stmt.push( - { $project: project } - ); - } stmt.push( { $sort: suggest @@ -506,15 +500,15 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset { $limit: limit } ); - if(tags){ - project = { _id: 1 }; - if(!resolve) project["res"] = 1; - if(enrich) project["doc"] = 1; + // if(tags){ + // project = { _id: 1 }; + // if(!resolve) project["res"] = 1; + // if(enrich) project["doc"] = 1; + // } - stmt.push( - { $project: project } - ); - } + stmt.push( + { $project: project } + ); rows = await this.db.collection("map" + this.field).aggregate(stmt); } diff --git a/dist/db/postgres/index.cjs b/dist/db/postgres/index.cjs index 5fe210d..86f217e 100644 --- a/dist/db/postgres/index.cjs +++ b/dist/db/postgres/index.cjs @@ -28,7 +28,6 @@ function toArray(val, stringify){ return result; } -// COMPILER BLOCK --> const defaults = { schema: "flexsearch", user: "postgres", @@ -38,7 +37,7 @@ const defaults = { port: "5432" }; -const pgp = pg_promise({ noWarnings: false }); +const pgp = pg_promise(/*{ noWarnings: true }*/); const MAXIMUM_QUERY_VARS = 16000; const fields = ["map", "ctx", "reg", "tag", "cfg"]; const types = { @@ -67,7 +66,7 @@ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_]/g, ""); } -let DB, TRX; +let DB; /** * @constructor @@ -80,7 +79,7 @@ function PostgresDB(name, config = {}){ } if(typeof name === "object"){ config = name; - name = name.name; + name = config.name; } if(!name){ console.info("Default storage space was used, because a name was not passed."); @@ -206,8 +205,8 @@ PostgresDB.prototype.open = async function(){ }; PostgresDB.prototype.close = function(){ - this.db.close && this.db.close(); - this.db = DB = null; + //DB && DB.close && DB.close(); + this.db = /*DB =*/ null; return this; }; @@ -364,7 +363,9 @@ PostgresDB.prototype.enrich = async function(ids){ }; PostgresDB.prototype.has = function(id){ - return this.db.oneOrNone("SELECT EXISTS(SELECT 1 FROM " + this.id + ".reg WHERE id = $1)", [id]); + return this.db.oneOrNone("SELECT EXISTS(SELECT 1 FROM " + this.id + ".reg WHERE id = $1)", [id]).then(function(result){ + return !!(result && result.exists); + }); }; PostgresDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ @@ -402,7 +403,7 @@ PostgresDB.prototype.search = function(flexsearch, query, limit = 100, offset = ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM ${ this.id }.ctx${ this.field } WHERE ${ where } GROUP BY id @@ -471,7 +472,7 @@ PostgresDB.prototype.search = function(flexsearch, query, limit = 100, offset = ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM ${ this.id }.map${ this.field } WHERE ${ where } GROUP BY id @@ -571,17 +572,23 @@ PostgresDB.prototype.info = function(){ // }; PostgresDB.prototype.transaction = function(task){ - if(TRX){ - return task.call(this, TRX); - } const self = this; - return (TRX || this.db).tx(function(trx){ - return task.call(self, TRX = trx); - }).finally(function(){ - TRX = null; - }) + return this.db.tx(function(trx){ + return task.call(self, trx); + }); }; +// PostgresDB.prototype.transaction = async function(task){ +// if(TRX){ +// return await task.call(this, TRX); +// } +// const self = this; +// return this.db.tx(async function(trx){ +// await task.call(self, TRX = trx); +// TRX = null; +// }); +// }; + PostgresDB.prototype.commit = async function(flexsearch, _replace, _append){ // process cleanup tasks diff --git a/dist/db/redis/index.cjs b/dist/db/redis/index.cjs index db2c2c2..6366f57 100644 --- a/dist/db/redis/index.cjs +++ b/dist/db/redis/index.cjs @@ -24,7 +24,6 @@ function toArray(val, stringify){ return result; } -// COMPILER BLOCK --> const defaults = { host: "localhost", port: "6379", @@ -96,7 +95,6 @@ RedisDB.prototype.open = async function(){ }; RedisDB.prototype.close = async function(){ - await this.db.disconnect(); // this.db.client.disconnect(); this.db = null; return this; }; @@ -219,11 +217,11 @@ RedisDB.prototype.has = function(id){ RedisDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ let result; + let params = []; if(query.length > 1 && flexsearch.depth){ const key = this.id + "ctx" + this.field + ":"; - let params = []; let keyword = query[0]; let term; @@ -233,26 +231,39 @@ RedisDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, params.push(key + (swap ? term : keyword) + ":" + (swap ? keyword : term)); keyword = term; } - query = params; } else { const key = this.id + "map" + this.field + ":"; for(let i = 0; i < query.length; i++){ - query[i] = key + query[i]; + params.push(key + query[i]); } } + query = params; + const type = this.type; let key = this.id + "tmp:" + Math.random(); if(suggest){ + const multi = this.db.multi().zUnionStore(key, query, { AGGREGATE: "SUM" }); + // Strict Tag Intersection: it does not put tags into union, instead it calculates the + // intersection against the term match union. This was the default behavior + // of Tag-Search. But putting everything into union will also provide suggestions derived + // from tags when no term was matched. { - if(tags) for(let i = 0; i < tags.length; i += 2){ - query.push(this.id + "tag-" + sanitize(tags[i]) + ":" + tags[i + 1]); + if(tags){ + // copy over zInterStore into the same destination surprisingly works fine + // const key2 = key + ":2"; + query = [key]; + for(let i = 0; i < tags.length; i += 2){ + query.push(this.id + "tag-" + sanitize(tags[i]) + ":" + tags[i + 1]); + } + multi.zInterStore(key, query, { AGGREGATE: "SUM" }); + // .unlink(key) + // key = key2; } } - const multi = this.db.multi().zUnionStore(key, query, { AGGREGATE: "SUM" }); result = multi [(resolve ? "zRange" : "zRangeWithScores")](key, "" + offset, "" + (offset + limit - 1), { REV: true }) .unlink(key) diff --git a/dist/db/sqlite/index.cjs b/dist/db/sqlite/index.cjs index aa579f1..863e446 100644 --- a/dist/db/sqlite/index.cjs +++ b/dist/db/sqlite/index.cjs @@ -29,7 +29,7 @@ function toArray(val, stringify){ return result; } -// COMPILER BLOCK --> +//const sqlite3 = require("sqlite3").verbose(); const MAXIMUM_QUERY_VARS = 16000; const fields = ["map", "ctx", "reg", "tag", "cfg"]; const types = { @@ -223,7 +223,7 @@ SqliteDB.prototype.open = async function(){ }; SqliteDB.prototype.close = function(){ - this.db.close(); + this.db && this.db.close(); this.db = null; DB[this.id] = null; TRX[this.id] = null; @@ -431,7 +431,7 @@ SqliteDB.prototype.has = function(id){ stmt: `SELECT EXISTS(SELECT 1 FROM main.reg WHERE id = ?) as exist`, params: [id] }).then(function(result){ - return result && result.exist; + return !!(result && result.exist); }); }; @@ -470,7 +470,7 @@ SqliteDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM main.ctx${ this.field } WHERE ${ stmt } GROUP BY id @@ -540,7 +540,7 @@ SqliteDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM main.map${ this.field } WHERE ${ stmt } GROUP BY id @@ -594,15 +594,12 @@ SqliteDB.prototype.info = function(){ SqliteDB.prototype.transaction = function(task, callback){ - const self = this; - if(TRX[this.id]){ - return TRX[this.id].then(function(){ - return self.transaction(task, callback); - }); + return task.call(this); } const db = this.db; + const self = this; return TRX[this.id] = new Promise(function(resolve, reject){ db.exec("PRAGMA optimize"); @@ -822,10 +819,10 @@ SqliteDB.prototype.remove = function(ids){ this.db.run("DELETE FROM main.ctx" + self.field + " WHERE id IN (" + stmt + ")", ids); this.db.run("DELETE FROM main.tag" + self.field + " WHERE id IN (" + stmt + ")", ids); this.db.run("DELETE FROM main.reg WHERE id IN (" + stmt + ")", ids); - }).then(function(res){ + }).then(function(result){ return next ? self.remove(next) - : res; + : result; }); }; diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 854e5db..06315a5 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,36 +1,36 @@ /**! - * FlexSearch.js v0.8.123 (Bundle/Debug) + * FlexSearch.js v0.8.132 (Bundle/Debug) * 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 u; -function A(a, b, c) { - const e = typeof c, d = typeof a; +var t; +function A(a, c, b) { + const e = typeof b, d = typeof a; if ("undefined" !== e) { if ("undefined" !== d) { - if (c) { + if (b) { if ("function" === d && e === d) { - return function(k) { - return a(c(k)); + return function(h) { + return a(b(h)); }; } - b = a.constructor; - if (b === c.constructor) { - if (b === Array) { - return c.concat(a); + c = a.constructor; + if (c === b.constructor) { + if (c === Array) { + return b.concat(a); } - if (b === Map) { - var f = new Map(c); + if (c === Map) { + var f = new Map(b); for (var g of a) { f.set(g[0], g[1]); } return f; } - if (b === Set) { - g = new Set(c); + if (c === Set) { + g = new Set(b); for (f of a.values()) { g.add(f); } @@ -40,9 +40,9 @@ function A(a, b, c) { } return a; } - return c; + return b; } - return "undefined" === d ? b : a; + return "undefined" === d ? c : a; } function B() { return Object.create(null); @@ -54,28 +54,28 @@ function I(a) { return "object" === typeof a; } function aa(a) { - const b = []; - for (const c of a.keys()) { - b.push(c); + const c = []; + for (const b of a.keys()) { + c.push(b); } - return b; + return c; } -function ba(a, b) { - if (E(b)) { - a = a[b]; +function ba(a, c) { + if (E(c)) { + a = a[c]; } else { - for (let c = 0; a && c < b.length; c++) { - a = a[b[c]]; + for (let b = 0; a && b < c.length; b++) { + a = a[c[b]]; } } return a; } function ca(a) { - let b = 0; - for (let c = 0, e; c < a.length; c++) { - (e = a[c]) && b < e.length && (b = e.length); + let c = 0; + for (let b = 0, e; b < a.length; b++) { + (e = a[b]) && c < e.length && (c = e.length); } - return b; + return c; } ;var da = [["\u00aa", "a"], ["\u00b2", "2"], ["\u00b3", "3"], ["\u00b9", "1"], ["\u00ba", "o"], ["\u00bc", "1\u20444"], ["\u00bd", "1\u20442"], ["\u00be", "3\u20444"], ["\u00e0", "a"], ["\u00e1", "a"], ["\u00e2", "a"], ["\u00e3", "a"], ["\u00e4", "a"], ["\u00e5", "a"], ["\u00e7", "c"], ["\u00e8", "e"], ["\u00e9", "e"], ["\u00ea", "e"], ["\u00eb", "e"], ["\u00ec", "i"], ["\u00ed", "i"], ["\u00ee", "i"], ["\u00ef", "i"], ["\u00f1", "n"], ["\u00f2", "o"], ["\u00f3", "o"], ["\u00f4", "o"], ["\u00f5", "o"], ["\u00f6", "o"], ["\u00f9", "u"], ["\u00fa", "u"], ["\u00fb", "u"], ["\u00fc", "u"], ["\u00fd", "y"], ["\u00ff", "y"], ["\u0101", "a"], ["\u0103", "a"], ["\u0105", "a"], ["\u0107", "c"], ["\u0109", "c"], ["\u010b", "c"], ["\u010d", "c"], ["\u010f", "d"], ["\u0113", "e"], ["\u0115", "e"], ["\u0117", "e"], ["\u0119", "e"], ["\u011b", "e"], ["\u011d", "g"], ["\u011f", "g"], ["\u0121", "g"], ["\u0123", "g"], ["\u0125", "h"], ["\u0129", "i"], ["\u012b", "i"], ["\u012d", "i"], ["\u012f", "i"], ["\u0133", @@ -98,30 +98,30 @@ function J(a = {}) { this.assign(a); } } -u = J.prototype; -u.assign = function(a) { +t = J.prototype; +t.assign = function(a) { this.normalize = A(a.normalize, !0, this.normalize); - let b = a.include, c = b || a.exclude || a.split, e; - if (c || "" === c) { - if ("object" === typeof c && c.constructor !== RegExp) { + let c = a.include, b = c || a.exclude || a.split, e; + if (b || "" === b) { + if ("object" === typeof b && b.constructor !== RegExp) { let d = ""; - e = !b; - b || (d += "\\p{Z}"); - c.letter && (d += "\\p{L}"); - c.number && (d += "\\p{N}", e = !!b); - c.symbol && (d += "\\p{S}"); - c.punctuation && (d += "\\p{P}"); - c.control && (d += "\\p{C}"); - if (c = c.char) { - d += "object" === typeof c ? c.join("") : c; + e = !c; + c || (d += "\\p{Z}"); + b.letter && (d += "\\p{L}"); + b.number && (d += "\\p{N}", e = !!c); + b.symbol && (d += "\\p{S}"); + b.punctuation && (d += "\\p{P}"); + b.control && (d += "\\p{C}"); + if (b = b.char) { + d += "object" === typeof b ? b.join("") : b; } try { - this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); + this.split = new RegExp("[" + (c ? "^" : "") + d + "]+", "u"); } catch (f) { - console.error("Your split configuration:", c, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; + console.error("Your split configuration:", b, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { - this.split = c, e = !1 === c || 2 > "a1a".split(c).length; + this.split = b, e = !1 === b || 2 > "a1a".split(b).length; } this.numeric = A(a.numeric, e); } else { @@ -135,17 +135,18 @@ u.assign = function(a) { this.prepare = A(a.prepare, null, this.prepare); this.finalize = A(a.finalize, null, this.finalize); ja || (this.mapper = new Map(da)); - this.rtl = A(a.rtl, !1, this.rtl); + b = a.filter; + this.filter = "function" === typeof b ? b : A(b && new Set(b), null, this.filter); this.dedupe = A(a.dedupe, !1, this.dedupe); - this.filter = A((c = a.filter) && new Set(c), null, this.filter); - this.matcher = A((c = a.matcher) && new Map(c), null, this.matcher); - this.mapper = A((c = a.mapper) && new Map(c), null, this.mapper); - this.stemmer = A((c = a.stemmer) && new Map(c), null, this.stemmer); + this.matcher = A((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = A((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = A((b = a.stemmer) && new Map(b), null, this.stemmer); this.replacer = A(a.replacer, null, this.replacer); this.minlength = A(a.minlength, 1, this.minlength); this.maxlength = A(a.maxlength, 0, this.maxlength); - if (this.cache = c = A(a.cache, !0, this.cache)) { - this.H = null, this.S = "number" === typeof c ? c : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; + this.rtl = A(a.rtl, !1, this.rtl); + if (this.cache = b = A(a.cache, !0, this.cache)) { + this.H = null, this.S = "number" === typeof b ? b : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; this.M = null; @@ -163,112 +164,111 @@ u.assign = function(a) { } return this; }; -u.addStemmer = function(a, b) { +t.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); - this.stemmer.set(a, b); + this.stemmer.set(a, c); this.A += (this.A ? "|" : "") + a; this.N = null; - this.cache && L(this); + this.cache && K(this); return this; }; -u.addFilter = function(a) { - this.filter || (this.filter = new Set()); - this.filter.add(a); - this.cache && L(this); +t.addFilter = function(a) { + "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); + this.cache && K(this); return this; }; -u.addMapper = function(a, b) { +t.addMapper = function(a, c) { if ("object" === typeof a) { - return this.addReplacer(a, b); + return this.addReplacer(a, c); } if (1 < a.length) { - return this.addMatcher(a, b); + return this.addMatcher(a, c); } this.mapper || (this.mapper = new Map()); - this.mapper.set(a, b); - this.cache && L(this); + this.mapper.set(a, c); + this.cache && K(this); return this; }; -u.addMatcher = function(a, b) { +t.addMatcher = function(a, c) { if ("object" === typeof a) { - return this.addReplacer(a, b); + return this.addReplacer(a, c); } if (2 > a.length && (this.dedupe || this.mapper)) { - return this.addMapper(a, b); + return this.addMapper(a, c); } this.matcher || (this.matcher = new Map()); - this.matcher.set(a, b); + this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && L(this); + this.cache && K(this); return this; }; -u.addReplacer = function(a, b) { +t.addReplacer = function(a, c) { if ("string" === typeof a) { - return this.addMatcher(a, b); + return this.addMatcher(a, c); } this.replacer || (this.replacer = []); - this.replacer.push(a, b); - this.cache && L(this); + this.replacer.push(a, c); + this.cache && K(this); return this; }; -u.encode = function(a) { +t.encode = function(a) { if (this.cache && a.length <= this.K) { if (this.H) { if (this.B.has(a)) { return this.B.get(a); } } else { - this.H = setTimeout(L, 50, this); + this.H = setTimeout(K, 50, this); } } this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (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 c = [], e = this.split || "" === this.split ? a.split(this.split) : a; - for (let f = 0, g, k; f < e.length; f++) { - if ((g = k = e[f]) && !(g.length < this.minlength)) { - if (b) { - c.push(g); + const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); + let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; + for (let f = 0, g, h; f < e.length; f++) { + if ((g = h = e[f]) && !(g.length < this.minlength)) { + if (c) { + b.push(g); } else { - if (!this.filter || !this.filter.has(g)) { + if (!this.filter || ("function" === typeof this.filter ? this.filter(g) : !this.filter.has(g))) { if (this.cache && g.length <= this.L) { if (this.H) { var d = this.G.get(g); if (d || "" === d) { - d && c.push(d); + d && b.push(d); continue; } } else { - this.H = setTimeout(L, 50, this); + this.H = setTimeout(K, 50, this); } } - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.N, h => this.stemmer.get(h)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), d = g, g = g.replace(this.N, k => this.stemmer.get(k)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let h = 0, l = "", n, m; h < g.length; h++) { - n = g.charAt(h), n === l && this.dedupe || ((m = this.mapper && this.mapper.get(n)) || "" === m ? m === l && this.dedupe || !(l = m) || (d += m) : d += l = n); + for (let k = 0, l = "", m, n; k < g.length; k++) { + m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); } g = d; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); if (g && this.replacer) { for (d = 0; g && d < this.replacer.length; d += 2) { g = g.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); - g && c.push(g); + this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); + g && b.push(g); } } } } - this.finalize && (c = this.finalize(c) || c); - this.cache && a.length <= this.K && (this.B.set(a, c), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); - return c; + this.finalize && (b = this.finalize(b) || b); + this.cache && a.length <= this.K && (this.B.set(a, b), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); + return b; }; -function L(a) { +function K(a) { a.H = null; a.B.clear(); a.G.clear(); @@ -276,32 +276,32 @@ function L(a) { ;let M, N; async function ka(a) { a = a.data; - var b = a.task; - const c = a.id; + var c = a.task; + const b = a.id; let e = a.args; - switch(b) { + switch(c) { case "init": N = a.options || {}; - (b = a.factory) ? (Function("return " + b)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); - postMessage({id:c}); + (c = a.factory) ? (Function("return " + c)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); + postMessage({id:b}); break; default: let d; - if ("export" === b) { + if ("export" === c) { if (!N.export || "function" !== typeof N.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } e[1] ? (e[0] = N.export, e[2] = 0, e[3] = 1) : e = null; } - if ("import" === b) { + if ("import" === c) { if (!N.import || "function" !== typeof N.import) { 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 N.import.call(M, e[0]), M.import(e[0], a)); } else { - (d = e && M[b].apply(M, e)) && d.then && (d = await d); + (d = e && M[c].apply(M, e)) && d.then && (d = await d); } - postMessage("search" === b ? {id:c, msg:d} : {id:c}); + postMessage("search" === c ? {id:b, msg:d} : {id:b}); } } ;function la(a) { @@ -317,47 +317,47 @@ function qa() { } function ma(a) { this[a + "Async"] = function() { - const b = arguments; - var c = b[b.length - 1]; + const c = arguments; + var b = c[c.length - 1]; let e; - "function" === typeof c && (e = c, delete b[b.length - 1]); + "function" === typeof b && (e = b, delete c[c.length - 1]); na ? pa || (pa = Date.now() - oa >= this.priority * this.priority * 3) : (na = setTimeout(qa, 0), oa = Date.now()); if (pa) { const f = this; return new Promise(g => { setTimeout(function() { - g(f[a + "Async"].apply(f, b)); + g(f[a + "Async"].apply(f, c)); }, 0); }); } - const d = this[a].apply(this, b); - c = d.then ? d : new Promise(f => f(d)); - e && c.then(e); - return c; + const d = this[a].apply(this, c); + b = d.then ? d : new Promise(f => f(d)); + e && b.then(e); + return b; }; } ;let P = 0; function Q(a = {}) { - function b(g) { - function k(h) { - h = h.data || h; - const l = h.id, n = l && d.h[l]; - n && (n(h.msg), delete d.h[l]); + function c(g) { + function h(k) { + k = k.data || k; + const l = k.id, m = l && d.h[l]; + m && (m(k.msg), delete d.h[l]); } this.worker = g; this.h = B(); if (this.worker) { - e ? this.worker.on("message", k) : this.worker.onmessage = k; + e ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { - return new Promise(function(h) { + return new Promise(function(k) { d.h[++P] = function() { - h(d); + k(d); 1e9 < P && (P = 0); }; - d.worker.postMessage({id:P, task:"init", factory:c, options:a}); + d.worker.postMessage({id:P, task:"init", factory:b, options:a}); }); } - this.worker.postMessage({task:"init", factory:c, options:a}); + this.worker.postMessage({task:"init", factory:b, options:a}); this.priority = a.priority || 4; return this; } @@ -365,12 +365,12 @@ function Q(a = {}) { if (!this || this.constructor !== Q) { return new Q(a); } - let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; - c && (c = c.toString()); - const e = "undefined" === typeof window, d = this, f = ra(c, e, a.worker); + let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + b && (b = b.toString()); + const e = "undefined" === typeof window, d = this, f = ra(b, e, a.worker); return f.then ? f.then(function(g) { - return b.call(d, g); - }) : b.call(this, f); + return c.call(d, g); + }) : c.call(this, f); } R("add"); R("append"); @@ -383,141 +383,161 @@ R("import"); la(Q.prototype); function R(a) { Q.prototype[a] = function() { - const b = this, c = [].slice.call(arguments); - var e = c[c.length - 1]; + const c = this, b = [].slice.call(arguments); + var e = b[b.length - 1]; let d; - "function" === typeof e && (d = e, c.pop()); + "function" === typeof e && (d = e, b.pop()); e = new Promise(function(f) { - "export" === a && "function" === typeof c[0] && (c[0] = null); - b.h[++P] = f; - b.worker.postMessage({task:a, id:P, args:c}); + "export" === a && "function" === typeof b[0] && (b[0] = null); + c.h[++P] = f; + c.worker.postMessage({task:a, id:P, args:b}); }); return d ? (e.then(d), this) : e; }; } -function ra(a, b, c) { - return b ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof c ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function ra(a, c, b) { + return c ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;function sa(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 5000 | 0); +;function sa(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 5000 | 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 ta(a, b) { - b || (b = new Map()); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b.set(e[0], e[1]); + e.push(d), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } -function ua(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 1000 | 0); - for (const d of a.entries()) { - e.push([d[0], sa(d[1])[0]]), e.length === b && (c.push(e), e = []); +function ta(a, c) { + c || (c = new Map()); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c.set(e[0], e[1]); } - e.length && c.push(e); return c; } -function va(a, b) { - b || (b = new Map()); - for (let c = 0, e, d; c < a.length; c++) { - e = a[c], d = b.get(e[0]), b.set(e[0], ta(e[1], d)); +function ua(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 1000 | 0); + for (const d of a.entries()) { + e.push([d[0], sa(d[1])[0]]), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } +function va(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], ta(e[1], d)); + } + return c; +} function wa(a) { - let b = [], c = []; + let c = [], b = []; for (const e of a.keys()) { - c.push(e), 250000 === c.length && (b.push(c), c = []); + b.push(e), 250000 === b.length && (c.push(b), b = []); } - c.length && b.push(c); - return b; + b.length && c.push(b); + return c; } -function xa(a, b) { - b || (b = new Set()); - for (let c = 0; c < a.length; c++) { - b.add(a[c]); +function xa(a, c) { + c || (c = new Set()); + for (let b = 0; b < a.length; b++) { + c.add(a[b]); } - return b; + return c; } -function ya(a, b, c, e, d, f, g = 0) { - const k = e && e.constructor === Array; - var h = k ? e.shift() : e; - if (!h) { - return this.export(a, b, d, f + 1); +function ya(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((b ? b + "." : "") + (g + 1) + "." + c, 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 ya.call(l, a, b, c, k ? e : null, d, f, g + 1); + return k.then(function() { + return ya.call(l, a, c, b, h ? e : null, d, f, g + 1); }); } - return ya.call(this, a, b, c, k ? e : null, d, f, g + 1); + return ya.call(this, a, c, b, h ? e : null, d, f, g + 1); } -;function za(a, b, c, e) { +function za(a, c) { + let b = ""; + for (const e of a.entries()) { + a = e[0]; + const d = e[1]; + let f = ""; + for (let g = 0, h; g < d.length; g++) { + h = d[g] || [""]; + let k = ""; + for (let l = 0; l < h.length; l++) { + k += (k ? "," : "") + ("string" === c ? '"' + h[l] + '"' : h[l]); + } + k = "[" + k + "]"; + f += (f ? "," : "") + k; + } + f = '["' + a + '",[' + f + "]]"; + b += (b ? "," : "") + f; + } + return b; +} +;function Aa(a, c, b, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { - if (g = a.index[f], b >= g.length) { - b -= g.length; + if (g = a.index[f], c >= g.length) { + c -= g.length; } else { - b = g[e ? "splice" : "slice"](b, c); - const k = b.length; - if (k && (d = d.length ? d.concat(b) : b, c -= k, e && (a.length -= k), !c)) { + 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; } - b = 0; + c = 0; } } return d; } function S(a) { - if (!this) { + if (!this || this.constructor !== S) { return new S(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; - const b = this; - return new Proxy([], {get(c, e) { + const c = this; + return new Proxy([], {get(b, e) { if ("length" === e) { - return b.length; + return c.length; } if ("push" === e) { return function(d) { - b.index[b.index.length - 1].push(d); - b.length++; + c.index[c.index.length - 1].push(d); + c.length++; }; } if ("pop" === e) { return function() { - if (b.length) { - return b.length--, b.index[b.index.length - 1].pop(); + if (c.length) { + return c.length--, c.index[c.index.length - 1].pop(); } }; } if ("indexOf" === e) { return function(d) { let f = 0; - for (let g = 0, k, h; g < b.index.length; g++) { - k = b.index[g]; - h = k.indexOf(d); - if (0 <= h) { - return f + h; + for (let g = 0, h, k; g < c.index.length; g++) { + h = c.index[g]; + k = h.indexOf(d); + if (0 <= k) { + return f + k; } - f += k.length; + f += h.length; } return -1; }; } if ("includes" === e) { return function(d) { - for (let f = 0; f < b.index.length; f++) { - if (b.index[f].includes(d)) { + for (let f = 0; f < c.index.length; f++) { + if (c.index[f].includes(d)) { return !0; } } @@ -526,24 +546,24 @@ function S(a) { } if ("slice" === e) { return function(d, f) { - return za(b, d || 0, f || b.length, !1); + return Aa(c, d || 0, f || c.length, !1); }; } if ("splice" === e) { return function(d, f) { - return za(b, d || 0, f || b.length, !0); + return Aa(c, d || 0, f || c.length, !0); }; } if ("constructor" === e) { return Array; } if ("symbol" !== typeof e) { - return (c = b.index[e / 2 ** 31 | 0]) && c[e]; + return (b = c.index[e / 2 ** 31 | 0]) && b[e]; } - }, set(c, e, d) { - c = e / 2 ** 31 | 0; - (b.index[c] || (b.index[c] = []))[e] = d; - b.length++; + }, set(b, e, d) { + b = e / 2 ** 31 | 0; + (c.index[b] || (c.index[b] = []))[e] = d; + c.length++; return !0; }}); } @@ -556,113 +576,114 @@ S.prototype.destroy = function() { S.prototype.push = function() { }; function T(a = 8) { - if (!this) { + if (!this || this.constructor !== T) { return new T(a); } this.index = B(); - this.B = []; + this.h = []; this.size = 0; - 32 < a ? (this.h = Aa, this.A = BigInt(a)) : (this.h = Ba, this.A = a); + 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); } T.prototype.get = function(a) { - const b = this.index[this.h(a)]; - return b && b.get(a); + const c = this.index[this.B(a)]; + return c && c.get(a); }; -T.prototype.set = function(a, b) { - var c = this.h(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.B.push(e)); +T.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 U(a = 8) { - if (!this) { + if (!this || this.constructor !== U) { return new U(a); } this.index = B(); this.h = []; - 32 < a ? (this.B = Aa, this.A = BigInt(a)) : (this.B = Ba, this.A = a); + this.size = 0; + 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); } U.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)); + 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++); }; -u = T.prototype; -u.has = U.prototype.has = function(a) { - const b = this.index[this.B(a)]; - return b && b.has(a); +t = T.prototype; +t.has = U.prototype.has = function(a) { + const c = this.index[this.B(a)]; + return c && c.has(a); }; -u.delete = U.prototype.delete = function(a) { - const b = this.index[this.B(a)]; - b && b.delete(a) && this.size--; +t.delete = U.prototype.delete = function(a) { + const c = this.index[this.B(a)]; + c && c.delete(a) && this.size--; }; -u.clear = U.prototype.clear = function() { +t.clear = U.prototype.clear = function() { this.index = B(); this.h = []; this.size = 0; }; -u.values = U.prototype.values = function*() { +t.values = U.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { - for (let b of this.h[a].values()) { - yield b; + for (let c of this.h[a].values()) { + yield c; } } }; -u.keys = U.prototype.keys = function*() { +t.keys = U.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { - for (let b of this.h[a].keys()) { - yield b; + for (let c of this.h[a].keys()) { + yield c; } } }; -u.entries = U.prototype.entries = function*() { +t.entries = U.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { - for (let b of this.h[a].entries()) { - yield b; + for (let c of this.h[a].entries()) { + yield c; } } }; -function Ba(a) { - let b = 2 ** this.A - 1; +function Ca(a) { + let c = 2 ** this.A - 1; if ("number" == typeof a) { - return a & b; + return a & c; } - let c = 0, e = this.A + 1; + let b = 0, e = this.A + 1; for (let d = 0; d < a.length; d++) { - c = (c * e ^ a.charCodeAt(d)) & b; + b = (b * e ^ a.charCodeAt(d)) & c; } - return 32 === this.A ? c + 2 ** 31 : c; + return 32 === this.A ? b + 2 ** 31 : b; } -function Aa(a) { - let b = BigInt(2) ** this.A - BigInt(1); - var c = typeof a; - if ("bigint" === c) { - return a & b; +function Ba(a) { + let c = BigInt(2) ** this.A - BigInt(1); + var b = typeof a; + if ("bigint" === b) { + return a & c; } - if ("number" === c) { - return BigInt(a) & b; + if ("number" === b) { + return BigInt(a) & c; } - c = BigInt(0); + b = BigInt(0); let e = this.A + BigInt(1); for (let d = 0; d < a.length; d++) { - c = (c * e ^ BigInt(a.charCodeAt(d))) & b; + b = (b * e ^ BigInt(a.charCodeAt(d))) & c; } - return c; + return b; } -;V.prototype.add = function(a, b, c) { - I(a) && (b = a, a = ba(b, this.key)); - if (b && (a || 0 === a)) { - if (!c && this.reg.has(a)) { - return this.update(a, b); +;V.prototype.add = function(a, c, b) { + I(a) && (c = a, a = ba(c, this.key)); + if (c && (a || 0 === a)) { + if (!b && this.reg.has(a)) { + return this.update(a, c); } - for (let k = 0, h; k < this.field.length; k++) { - h = this.D[k]; - var e = this.index.get(this.field[k]); - if ("function" === typeof h) { - var d = h(b); + for (let h = 0, k; h < this.field.length; h++) { + k = this.D[h]; + var e = this.index.get(this.field[h]); + if ("function" === typeof k) { + var d = k(c); d && e.add(a, d, !1, !0); } else { - if (d = h.I, !d || d(b)) { - h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), Ca(b, h, this.J, 0, e, a, h[0], c); + if (d = k.I, !d || d(c)) { + k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), Da(c, k, this.J, 0, e, a, k[0], b); } } } @@ -670,34 +691,34 @@ function Aa(a) { for (e = 0; e < this.F.length; e++) { var f = this.F[e], g = this.R[e]; d = this.tag.get(g); - let k = B(); + let h = B(); if ("function" === typeof f) { - if (f = f(b), !f) { + if (f = f(c), !f) { continue; } } else { - const h = f.I; - if (h && !h(b)) { + const k = f.I; + if (k && !k(c)) { continue; } f.constructor === String && (f = "" + f); - f = ba(b, f); + f = ba(c, f); } if (d && f) { E(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 = []), !c || !n.includes(a))) { - if (n.length === 2 ** 31 - 1) { - g = new S(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 S(m); if (this.fastupdate) { - for (let m of this.reg.values()) { - m.includes(n) && (m[m.indexOf(n)] = g); + for (let n of this.reg.values()) { + n.includes(m) && (n[n.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 { @@ -705,138 +726,147 @@ function Aa(a) { } } } - if (this.store && (!c || !this.store.has(a))) { - let k; + if (this.store && (!b || !this.store.has(a))) { + let h; if (this.C) { - k = B(); - for (let h = 0, l; h < this.C.length; h++) { - l = this.C[h]; - if ((c = l.I) && !c(b)) { + h = B(); + for (let k = 0, l; k < this.C.length; k++) { + l = this.C[k]; + if ((b = l.I) && !b(c)) { continue; } - let n; + let m; if ("function" === typeof l) { - n = l(b); - if (!n) { + m = l(c); + if (!m) { continue; } l = [l.V]; } else if (E(l) || l.constructor === String) { - k[l] = b[l]; + h[l] = c[l]; continue; } - Da(b, k, l, 0, l[0], n); + Ea(c, h, l, 0, l[0], m); } } - this.store.set(a, k || b); + this.store.set(a, h || c); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Da(a, b, c, e, d, f) { +function Ea(a, c, b, e, d, f) { a = a[d]; - if (e === c.length - 1) { - b[d] = f || a; + if (e === b.length - 1) { + c[d] = f || a; } else if (a) { if (a.constructor === Array) { - for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { - Da(a, b, c, e, d); + for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { + Ea(a, c, b, e, d); } } else { - b = b[d] || (b[d] = B()), d = c[++e], Da(a, b, c, e, d); + c = c[d] || (c[d] = B()), d = b[++e], Ea(a, c, b, e, d); } } } -function Ca(a, b, c, e, d, f, g, k) { +function Da(a, c, b, e, d, f, g, h) { if (a = a[g]) { - if (e === b.length - 1) { + if (e === c.length - 1) { if (a.constructor === Array) { - if (c[e]) { - for (b = 0; b < a.length; b++) { - d.add(f, a[b], !0, !0); + if (b[e]) { + for (c = 0; c < a.length; c++) { + d.add(f, a[c], !0, !0); } return; } a = a.join(" "); } - d.add(f, a, k, !0); + d.add(f, a, h, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Ca(a, b, c, e, d, f, g, k); + Da(a, c, b, e, d, f, g, h); } } else { - g = b[++e], Ca(a, b, c, e, d, f, g, k); + g = c[++e], Da(a, c, b, e, d, f, g, h); } } } else { d.db && d.remove(f); } } -;function Ea(a, b, c, e, d, f, g) { - const k = a.length; - let h = [], l; - var n; +;function Fa(a, c, b, e, d, f, g) { + const h = a.length; + let k = [], l, m; l = B(); - for (let m = 0, q, p, t, r; m < b; m++) { - for (let v = 0; v < k; v++) { - if (t = a[v], m < t.length && (q = t[m])) { + for (let n = 0, q, r, p, v; n < c; n++) { + for (let u = 0; u < h; u++) { + if (p = a[u], n < p.length && (q = p[n])) { for (let x = 0; x < q.length; x++) { - p = q[x], (n = l[p]) ? l[p]++ : (n = 0, l[p] = 1), r = h[n] || (h[n] = []), g || (n = m + (v || !d ? 0 : f || 0), r = r[n] || (r[n] = [])), r.push(p); + r = q[x]; + (m = l[r]) ? l[r]++ : (m = 0, l[r] = 1); + v = k[m] || (k[m] = []); + if (!g) { + let y = n + (u || !d ? 0 : f || 0); + v = v[y] || (v[y] = []); + } + v.push(r); + if (g && b && m === h - 1 && v.length - e === b) { + return v; + } } } } } - if (a = h.length) { + if (a = k.length) { if (d) { - h = 1 < h.length ? Fa(h, c, e, g, f) : (h = h[0]).length > c || e ? h.slice(e, c + e) : h; + k = 1 < k.length ? Ga(k, b, e, g, f) : (k = k[0]).length > b || e ? k.slice(e, b + e) : k; } else { - if (a < k) { + if (a < h) { return []; } - h = h[a - 1]; - if (c || e) { + k = k[a - 1]; + if (b || e) { if (g) { - if (h.length > c || e) { - h = h.slice(e, c + e); + if (k.length > b || e) { + k = k.slice(e, b + e); } } else { d = []; - for (let m = 0, q; m < h.length; m++) { - if (q = h[m], q.length > e) { + for (let n = 0, q; n < k.length; n++) { + if (q = k[n], q.length > e) { e -= q.length; } else { - if (q.length > c || e) { - q = q.slice(e, c + e), c -= q.length, e && (e -= q.length); + if (q.length > b || e) { + q = q.slice(e, b + e), b -= q.length, e && (e -= q.length); } d.push(q); - if (!c) { + if (!b) { break; } } } - h = 1 < d.length ? [].concat.apply([], d) : d[0]; + k = 1 < d.length ? [].concat.apply([], d) : d[0]; } } } } - return h; + return k; } -function Fa(a, b, c, e, d) { +function Ga(a, c, b, e, d) { const f = [], g = B(); - let k; - var h = a.length; + let h; + var k = a.length; let l; if (e) { - for (d = h - 1; 0 <= d; d--) { + for (d = k - 1; 0 <= d; d--) { if (l = (e = a[d]) && e.length) { - for (h = 0; h < l; h++) { - if (k = e[h], !g[k]) { - if (g[k] = 1, c) { - c--; + 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 === b) { + if (f.push(h), f.length === c) { return f; } } @@ -845,18 +875,18 @@ function Fa(a, b, c, e, d) { } } } else { - for (let n = h - 1, m, q = 0; 0 <= n; n--) { - m = a[n]; - for (let p = 0; p < m.length; p++) { - if (l = (e = m[p]) && e.length) { - for (let t = 0; t < l; t++) { - if (k = e[t], !g[k]) { - if (g[k] = 1, c) { - c--; + for (let m = k - 1, n, q = 0; 0 <= m; m--) { + n = a[m]; + for (let r = 0; r < n.length; r++) { + if (l = (e = n[r]) && e.length) { + for (let p = 0; p < l; p++) { + if (h = e[p], !g[h]) { + if (g[h] = 1, b) { + b--; } else { - let r = (p + (n < h - 1 ? d || 0 : 0)) / (n + 1) | 0; - (f[r] || (f[r] = [])).push(k); - if (++q === b) { + let v = (r + (m < k - 1 ? d || 0 : 0)) / (m + 1) | 0; + (f[v] || (f[v] = [])).push(h); + if (++q === c) { return f; } } @@ -868,51 +898,51 @@ function Fa(a, b, c, e, d) { } return f; } -function Ga(a, b, c) { +function Ha(a, c, b) { const e = B(), d = []; - for (let f = 0, g; f < b.length; f++) { - g = b[f]; - for (let k = 0; k < g.length; k++) { - e[g[k]] = 1; + for (let f = 0, g; f < c.length; f++) { + g = c[f]; + for (let h = 0; h < g.length; h++) { + e[g[h]] = 1; } } - if (c) { + if (b) { for (let f = 0, g; f < a.length; f++) { g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { - for (let f = 0, g, k; f < a.result.length; f++) { - for (g = a.result[f], b = 0; b < g.length; b++) { - k = g[b], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); + for (let f = 0, g, h; f < a.result.length; f++) { + for (g = a.result[f], c = 0; c < g.length; c++) { + h = g[c], e[h] && ((d[f] || (d[f] = [])).push(h), e[h] = 0); } } } return d; } -;function Ha(a, b, c, e) { +;function Ia(a, c, b, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, e ? W.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; } let d = []; - for (let f = 0, g, k; f < a.length; f++) { - if ((g = a[f]) && (k = g.length)) { - if (c) { - if (c >= k) { - c -= k; + for (let f = 0, g, h; f < a.length; f++) { + if ((g = a[f]) && (h = g.length)) { + if (b) { + if (b >= h) { + b -= h; continue; } - c < k && (g = b ? g.slice(c, c + b) : g.slice(c), k = g.length, c = 0); + b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); } - k > b && (g = g.slice(0, b), k = b); - if (!d.length && k >= b) { + h > c && (g = g.slice(0, c), h = c); + if (!d.length && h >= c) { return e ? W.call(this, g) : g; } d.push(g); - b -= k; - if (!b) { + c -= h; + if (!c) { break; } } @@ -920,36 +950,36 @@ function Ga(a, b, c) { d = 1 < d.length ? [].concat.apply([], d) : d[0]; return e ? W.call(this, d) : d; } -;function Ia(a, b, c) { - var e = c[0]; +;function Ja(a, c, b) { + var e = b[0]; if (e.then) { - return Promise.all(c).then(function(n) { - return a[b].apply(a, n); + return Promise.all(b).then(function(m) { + return a[c].apply(a, m); }); } if (e[0] && e[0].index) { - return a[b].apply(a, e); + return a[c].apply(a, e); } e = []; - let d = [], f = 0, g = 0, k, h, l; - for (let n = 0, m; n < c.length; n++) { - if (m = c[n]) { + let d = [], f = 0, g = 0, h, k, l; + for (let m = 0, n; m < b.length; m++) { + if (n = b[m]) { let q; - if (m.constructor === X) { - q = m.result; - } else if (m.constructor === Array) { - q = m; + if (n.constructor === X) { + q = n.result; + } else if (n.constructor === Array) { + q = n; } else { - if (f = m.limit || 0, g = m.offset || 0, l = m.suggest, h = m.resolve, k = m.enrich && h, m.index) { - m.resolve = !1, m.enrich = !1, q = m.index.search(m).result, m.resolve = h, m.enrich = k; - } else if (m.and) { - q = a.and(m.and); - } else if (m.or) { - q = a.or(m.or); - } else if (m.xor) { - q = a.xor(m.xor); - } else if (m.not) { - q = a.not(m.not); + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { + n.resolve = !1, n.enrich = !1, q = n.index.search(n).result, n.resolve = k, n.enrich = h; + } else if (n.and) { + q = a.and(n.and); + } else if (n.or) { + q = a.or(n.or); + } else if (n.xor) { + q = a.xor(n.xor); + } else if (n.not) { + q = a.not(n.not); } else { continue; } @@ -957,129 +987,129 @@ function Ga(a, b, c) { if (q.then) { d.push(q); } else if (q.length) { - e[n] = q; - } else if (!l && ("and" === b || "xor" === b)) { + e[m] = q; + } else if (!l && ("and" === c || "xor" === c)) { e = []; break; } } } - return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; } ;X.prototype.or = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f} = Ia(this, "or", arguments); - return Ja.call(this, a, b, c, e, d, f); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ja(this, "or", arguments); + return Ka.call(this, a, c, b, e, d, f); }; -function Ja(a, b, c, e, d, f) { - if (b.length) { +function Ka(a, c, b, e, d, f) { + if (c.length) { const g = this; - return Promise.all(b).then(function(k) { + return Promise.all(c).then(function(h) { a = []; - for (let h = 0, l; h < k.length; h++) { - (l = k[h]).length && (a[h] = l); + for (let k = 0, l; k < h.length; k++) { + (l = h[k]).length && (a[k] = l); } - return Ja.call(g, a, [], c, e, d, f); + return Ka.call(g, a, [], b, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Fa(a, c, e, !1, this.h), e = 0)); - return f ? this.resolve(c, e, d) : this; + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ga(a, b, e, !1, this.h), e = 0)); + return f ? this.resolve(b, e, d) : this; } ;X.prototype.and = function() { - let a = this.result.length, b, c, e, d; + let a = this.result.length, c, b, e, d; if (!a) { const f = arguments[0]; - f && (a = !!f.suggest, d = f.resolve, b = f.limit, c = f.offset, e = f.enrich && d); + f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:n, suggest:m} = Ia(this, "and", arguments); - return Ka.call(this, f, g, k, h, l, n, m); + const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ja(this, "and", arguments); + return La.call(this, f, g, h, k, l, m, n); } - return d ? this.resolve(b, c, e) : this; + return d ? this.resolve(c, b, e) : this; }; -function Ka(a, b, c, e, d, f, g) { - if (b.length) { - const k = this; - return Promise.all(b).then(function(h) { +function La(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, n; l < h.length; l++) { - (n = h[l]).length && (a[l] = n); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return Ka.call(k, a, [], c, e, d, f, g); + return La.call(h, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - if (b = ca(a)) { - return this.result = Ea(a, b, c, e, g, this.h, f), f ? d ? W.call(this.index, this.result) : this.result : this; + if (c = ca(a)) { + return this.result = Fa(a, c, b, e, g, this.h, f), f ? d ? W.call(this.index, this.result) : this.result : this; } this.result = []; } } else { g || (this.result = a); } - return f ? this.resolve(c, e, d) : this; + return f ? this.resolve(b, e, d) : this; } ;X.prototype.xor = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ia(this, "xor", arguments); - return La.call(this, a, b, c, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "xor", arguments); + return Ma.call(this, a, c, b, e, d, f, g); }; -function La(a, b, c, e, d, f, g) { - if (b.length) { - const k = this; - return Promise.all(b).then(function(h) { +function Ma(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, n; l < h.length; l++) { - (n = h[l]).length && (a[l] = n); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return La.call(k, a, [], c, e, d, f, g); + return Ma.call(h, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = Ma.call(this, a, c, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Na.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } - return f ? this.resolve(c, e, d) : this; + return f ? this.resolve(b, e, d) : this; } -function Ma(a, b, c, e, d) { +function Na(a, c, b, e, d) { const f = [], g = B(); - let k = 0; - for (let h = 0, l; h < a.length; h++) { - if (l = a[h]) { - k < l.length && (k = l.length); - for (let n = 0, m; n < l.length; n++) { - if (m = l[n]) { - for (let q = 0, p; q < m.length; q++) { - p = m[q], g[p] = g[p] ? 2 : 1; + let h = 0; + for (let k = 0, l; k < a.length; k++) { + if (l = a[k]) { + h < l.length && (h = l.length); + for (let m = 0, n; m < l.length; m++) { + if (n = l[m]) { + for (let q = 0, r; q < n.length; q++) { + r = n[q], g[r] = g[r] ? 2 : 1; } } } } } - for (let h = 0, l, n = 0; h < k; h++) { - for (let m = 0, q; m < a.length; m++) { - if (q = a[m]) { - if (l = q[h]) { - for (let p = 0, t; p < l.length; p++) { - if (t = l[p], 1 === g[t]) { - if (c) { - c--; + for (let k = 0, l, m = 0; k < h; k++) { + for (let n = 0, q; n < a.length; n++) { + if (q = a[n]) { + if (l = q[k]) { + for (let r = 0, p; r < l.length; r++) { + if (p = l[r], 1 === g[p]) { + if (b) { + b--; } else { if (e) { - if (f.push(t), f.length === b) { + if (f.push(p), f.length === c) { return f; } } else { - const r = h + (m ? d : 0); - f[r] || (f[r] = []); - f[r].push(t); - if (++n === b) { + const v = k + (n ? d : 0); + f[v] || (f[v] = []); + f[v].push(p); + if (++m === c) { return f; } } @@ -1093,43 +1123,43 @@ function Ma(a, b, c, e, d) { return f; } ;X.prototype.not = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ia(this, "not", arguments); - return Na.call(this, a, b, c, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "not", arguments); + return Oa.call(this, a, c, b, e, d, f, g); }; -function Na(a, b, c, e, d, f, g) { - if (b.length) { - const k = this; - return Promise.all(b).then(function(h) { +function Oa(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, n; l < h.length; l++) { - (n = h[l]).length && (a[l] = n); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return Na.call(k, a, [], c, e, d, f, g); + return Oa.call(h, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Oa.call(this, a, c, e, f); + this.result = Pa.call(this, a, b, e, f); } else if (f) { - return this.resolve(c, e, d); + return this.resolve(b, e, d); } return f ? d ? W.call(this.index, this.result) : this.result : this; } -function Oa(a, b, c, e) { +function Pa(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, k = 0; f < this.result.length; f++) { + for (let f = 0, g, h = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let h = 0, l; h < g.length; h++) { - if (l = g[h], !a.has(l)) { - if (c) { - c--; + for (let k = 0, l; k < g.length; k++) { + if (l = g[k], !a.has(l)) { + if (b) { + b--; } else { if (e) { - if (d.push(l), d.length === b) { + if (d.push(l), d.length === c) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++k === b) { + if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { return d; } } @@ -1153,32 +1183,32 @@ function Oa(a, b, c, e) { } X.prototype.limit = function(a) { if (this.result.length) { - const b = []; - for (let c = 0, e; c < this.result.length; c++) { - if (e = this.result[c]) { + const c = []; + for (let b = 0, e; b < this.result.length; b++) { + if (e = this.result[b]) { if (e.length <= a) { - if (b[c] = e, a -= e.length, !a) { + if (c[b] = e, a -= e.length, !a) { break; } } else { - b[c] = e.slice(0, a); + c[b] = e.slice(0, a); break; } } } - this.result = b; + this.result = c; } return this; }; X.prototype.offset = function(a) { if (this.result.length) { - const b = []; - for (let c = 0, e; c < this.result.length; c++) { - if (e = this.result[c]) { - e.length <= a ? a -= e.length : (b[c] = e.slice(a), a = 0); + const c = []; + for (let b = 0, e; b < this.result.length; b++) { + if (e = this.result[b]) { + e.length <= a ? a -= e.length : (c[b] = e.slice(a), a = 0); } } - this.result = b; + this.result = c; } return this; }; @@ -1186,46 +1216,46 @@ X.prototype.boost = function(a) { this.h += a; return this; }; -X.prototype.resolve = function(a, b, c) { +X.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Ha.call(d, e, a || 100, b, c)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Ia.call(d, e, a || 100, c, b)) : e; }; B(); -V.prototype.search = function(a, b, c, e) { - c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); +V.prototype.search = function(a, c, b, e) { + b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); let d = [], f = [], g; + var h; let k; - let h; - let l, n = 0; - var m = !0; - let q; - if (c) { - c.constructor === Array && (c = {index:c}); - a = c.query || a; - g = c.pluck; - k = c.merge; - h = g || c.field || (h = c.index) && (h.index ? null : h); - var p = this.tag && c.tag; - var t = c.suggest; - m = !1 !== c.resolve; - if (!m && !g) { - if (h = h || this.field) { - E(h) ? g = h : (h.constructor === Array && 1 === h.length && (h = h[0]), g = h.field || h.index); + let l; + let m, n = 0; + var q = !0; + let r; + if (b) { + b.constructor === Array && (b = {index:b}); + a = b.query || a; + g = b.pluck; + k = b.merge; + l = g || b.field || (l = b.index) && (l.index ? null : l); + var p = this.tag && b.tag; + var v = b.suggest; + q = !1 !== b.resolve; + if (!q && !g) { + if (l = l || this.field) { + E(l) ? g = l : (l.constructor === Array && 1 === l.length && (l = l[0]), g = l.field || l.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."); } } - this.store && c.enrich && !m && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - var r = this.store && c.enrich && m; - q = c.highlight && r; - b = c.limit || b; - l = c.offset || 0; - b || (b = 100); + this.store && b.enrich && !q && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + r = (h = this.store && b.enrich && q) && b.highlight; + c = b.limit || c; + m = b.offset || 0; + c || (c = 100); if (p && (!this.db || !e)) { p.constructor !== Array && (p = [p]); - var v = []; + var u = []; for (let z = 0, w; z < p.length; z++) { w = p[z]; if (E(w)) { @@ -1235,46 +1265,46 @@ V.prototype.search = function(a, b, c, e) { var x = w.tag; if (x.constructor === Array) { for (var y = 0; y < x.length; y++) { - v.push(w.field, x[y]); + u.push(w.field, x[y]); } } else { - v.push(w.field, x); + u.push(w.field, x); } } else { x = Object.keys(w); for (let D = 0, H, C; D < x.length; D++) { if (H = x[D], C = w[H], C.constructor === Array) { for (y = 0; y < C.length; y++) { - v.push(H, C[y]); + u.push(H, C[y]); } } else { - v.push(H, C); + u.push(H, C); } } } } - if (!v.length) { + if (!u.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - p = v; + p = u; if (!a) { - t = []; - if (v.length) { - for (p = 0; p < v.length; p += 2) { + v = []; + if (u.length) { + for (p = 0; p < u.length; p += 2) { if (this.db) { - m = this.index.get(v[p]); - if (!m) { - console.warn("Tag '" + v[p] + ":" + v[p + 1] + "' will be skipped because there is no field '" + v[p] + "'."); + q = this.index.get(u[p]); + if (!q) { + console.warn("Tag '" + u[p] + ":" + u[p + 1] + "' will be skipped because there is no field '" + u[p] + "'."); continue; } - t.push(m = m.db.tag(v[p + 1], b, l, r)); + v.push(q = q.db.tag(u[p + 1], c, m, h)); } else { - m = Pa.call(this, v[p], v[p + 1], b, l, r); + q = Qa.call(this, u[p], u[p + 1], c, m, h); } - d.push({field:v[p], tag:v[p + 1], result:m}); + d.push({field:u[p], tag:u[p + 1], result:q}); } } - return t.length ? Promise.all(t).then(function(z) { + return v.length ? Promise.all(v).then(function(z) { for (let w = 0; w < z.length; w++) { d[w].result = z[w]; } @@ -1282,142 +1312,143 @@ V.prototype.search = function(a, b, c, e) { }) : d; } } - h && h.constructor !== Array && (h = [h]); + l && l.constructor !== Array && (l = [l]); } - h || (h = this.field); - v = !e && (this.worker || this.db) && []; + l || (l = this.field); + u = !e && (this.worker || this.db) && []; let F; - for (let z = 0, w, D, H; z < h.length; z++) { - D = h[z]; + for (let z = 0, w, D, H; z < l.length; z++) { + D = l[z]; if (this.db && this.tag && !this.D[z]) { continue; } let C; - E(D) || (C = D, D = C.field, a = C.query || a, b = C.limit || b, l = C.offset || l, t = C.suggest || t, r = this.store && (C.enrich || r)); + E(D) || (C = D, D = C.field, a = C.query || a, c = C.limit || c, m = C.offset || m, v = C.suggest || v, h = this.store && (C.enrich || h)); if (e) { w = e[z]; } else { - if (x = C || c, y = this.index.get(D), p && (this.db && (x.tag = p, F = y.db.support_tag_search, x.field = h), F || (x.enrich = !1)), v) { - v[z] = y.search(a, b, x); - x && r && (x.enrich = r); + if (x = C || b, y = this.index.get(D), p && (this.db && (x.tag = p, F = y.db.support_tag_search, x.field = l), F || (x.enrich = !1)), u) { + u[z] = y.search(a, c, x); + x && h && (x.enrich = h); continue; } else { - w = y.search(a, b, x), x && r && (x.enrich = r); + w = y.search(a, c, x), x && h && (x.enrich = h); } } - H = w && (m ? w.length : w.result.length); + H = w && (q ? w.length : w.result.length); if (p && H) { x = []; y = 0; if (this.db && e) { if (!F) { - for (let G = h.length; G < e.length; G++) { - let K = e[G]; - if (K && K.length) { - y++, x.push(K); - } else if (!t) { - return m ? d : new X(d); + for (let G = l.length; G < e.length; G++) { + let L = e[G]; + if (L && L.length) { + y++, x.push(L); + } else if (!v) { + return q ? d : new X(d); } } } } else { - for (let G = 0, K, qb; G < p.length; G += 2) { - K = this.tag.get(p[G]); - if (!K) { - if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), t) { + for (let G = 0, L, rb; G < p.length; G += 2) { + L = this.tag.get(p[G]); + if (!L) { + if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), v) { continue; } else { - return m ? d : new X(d); + return q ? d : new X(d); } } - if (qb = (K = K && K.get(p[G + 1])) && K.length) { - y++, x.push(K); - } else if (!t) { - return m ? d : new X(d); + if (rb = (L = L && L.get(p[G + 1])) && L.length) { + y++, x.push(L); + } else if (!v) { + return q ? d : new X(d); } } } if (y) { - w = Ga(w, x, m); + w = Ha(w, x, q); H = w.length; - if (!H && !t) { - return m ? w : new X(w); + if (!H && !v) { + return q ? w : new X(w); } y--; } } if (H) { f[n] = D, d.push(w), n++; - } else if (1 === h.length) { - return m ? d : new X(d); + } else if (1 === l.length) { + return q ? d : new X(d); } } - if (v) { + if (u) { if (this.db && p && p.length && !F) { - for (r = 0; r < p.length; r += 2) { - e = this.index.get(p[r]); + for (h = 0; h < p.length; h += 2) { + e = this.index.get(p[h]); if (!e) { - if (console.warn("Tag '" + p[r] + ":" + p[r + 1] + "' was not found because there is no field '" + p[r] + "'."), t) { + if (console.warn("Tag '" + p[h] + ":" + p[h + 1] + "' was not found because there is no field '" + p[h] + "'."), v) { continue; } else { - return m ? d : new X(d); + return q ? d : new X(d); } } - v.push(e.db.tag(p[r + 1], b, l, !1)); + u.push(e.db.tag(p[h + 1], c, m, !1)); } } const z = this; - return Promise.all(v).then(function(w) { - return w.length ? z.search(a, b, c, w) : w; + return Promise.all(u).then(function(w) { + return w.length ? z.search(a, c, b, w) : w; }); } if (!n) { - return m ? d : new X(d); + return q ? d : new X(d); } - if (g && (!r || !this.store)) { + if (g && (!h || !this.store)) { return d[0]; } - v = []; + u = []; for (let z = 0, w; z < f.length; z++) { w = d[z]; - r && w.length && !w[0].doc && (this.db ? v.push(w = this.index.get(this.field[0]).db.enrich(w)) : w = W.call(this, w)); + h && w.length && !w[0].doc && (this.db ? u.push(w = this.index.get(this.field[0]).db.enrich(w)) : w = W.call(this, w)); if (g) { - return m ? w : new X(w); + return q ? w : new X(w); } d[z] = {field:f[z], result:w}; } - if (r && this.db && v.length) { + if (h && this.db && u.length) { const z = this; - return Promise.all(v).then(function(w) { + return Promise.all(u).then(function(w) { for (let D = 0; D < w.length; D++) { d[D].result = w[D]; } - return k ? Qa(d, b) : q ? Ra(d, a, z.index, z.field, z.D, q) : d; + return k ? Ra(d, c) : r ? Sa(d, a, z.index, z.field, z.D, r) : d; }); } - return k ? Qa(d, b) : q ? Ra(d, a, this.index, this.field, this.D, q) : d; + return k ? Ra(d, c) : r ? Sa(d, a, this.index, this.field, this.D, r) : d; }; -function Ra(a, b, c, e, d, f) { - let g, k, h; - for (let n = 0, m, q, p, t, r; n < a.length; n++) { - m = a[n].result; - q = a[n].field; - t = c.get(q); - p = t.encoder; - h = t.tokenize; - r = d[e.indexOf(q)]; - p !== g && (g = p, k = g.encode(b)); - for (let v = 0; v < m.length; v++) { +function Sa(a, c, b, e, d, f) { + console.log("template", f); + let g, h, k; + for (let m = 0, n, q, r, p, v; m < a.length; m++) { + n = a[m].result; + q = a[m].field; + p = b.get(q); + r = p.encoder; + k = p.tokenize; + v = d[e.indexOf(q)]; + r !== g && (g = r, h = g.encode(c)); + for (let u = 0; u < n.length; u++) { let x = ""; - var l = ba(m[v].doc, r); + var l = ba(n[u].doc, v); let y = g.encode(l); l = l.split(g.split); for (let F = 0, z, w; F < y.length; F++) { z = y[F]; w = l[F]; let D; - for (let H = 0, C; H < k.length; H++) { - if (C = k[H], "strict" === h) { + for (let H = 0, C; H < h.length; H++) { + if (C = h[H], "strict" === k) { if (z === C) { x += (x ? " " : "") + f.replace("$1", w); D = !0; @@ -1434,38 +1465,38 @@ function Ra(a, b, c, e, d, f) { } D || (x += (x ? " " : "") + l[F]); } - m[v].highlight = x; + n[u].highlight = x; } } return a; } -function Qa(a, b) { - const c = [], e = B(); +function Ra(a, c) { + const b = [], e = B(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; - for (let k = 0, h, l, n; k < g.length; k++) { - if (l = g[k], "object" !== typeof l && (l = {id:l}), h = l.id, n = e[h]) { - n.push(f.field); + for (let h = 0, k, l, m; h < g.length; h++) { + if (l = g[h], "object" !== typeof l && (l = {id:l}), k = l.id, m = e[k]) { + m.push(f.field); } else { - if (c.length === b) { - return c; + if (b.length === c) { + return b; } - l.field = e[h] = [f.field]; - c.push(l); + l.field = e[k] = [f.field]; + b.push(l); } } } - return c; + return b; } -function Pa(a, b, c, e, d) { +function Qa(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(b)) && f.length - e) && 0 < a) { - if (a > c || e) { - f = f.slice(e, e + c); + if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { + if (a > b || e) { + f = f.slice(e, e + b); } d && (f = W.call(this, f)); return f; @@ -1475,45 +1506,45 @@ function W(a) { if (!this || !this.store) { return a; } - const b = Array(a.length); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b[c] = {id:e, doc:this.store.get(e)}; + const c = Array(a.length); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c[b] = {id:e, doc:this.store.get(e)}; } - return b; + return c; } ;function V(a) { if (!this || this.constructor !== V) { return new V(a); } - const b = a.document || a.doc || a; - let c, e; + const c = a.document || a.doc || a; + let b, e; this.D = []; this.field = []; this.J = []; - this.key = (c = b.key || b.id) && Sa(c, this.J) || "id"; + this.key = (b = c.key || c.id) && Ta(b, this.J) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; this.reg = !this.fastupdate || a.worker || a.db ? e ? new U(e) : new Set() : e ? new T(e) : new Map(); - this.C = (c = b.store || null) && c && !0 !== c && []; - this.store = c && (e ? new T(e) : new Map()); - this.cache = (c = a.cache || null) && new Y(c); + this.C = (b = c.store || null) && b && !0 !== b && []; + this.store = b && (e ? new T(e) : new Map()); + this.cache = (b = a.cache || null) && new Y(b); a.cache = !1; this.worker = a.worker; this.priority = a.priority || 4; - this.index = Ta.call(this, a, b); + this.index = Ua.call(this, a, c); this.tag = null; - if (c = b.tag) { - if ("string" === typeof c && (c = [c]), c.length) { + if (b = c.tag) { + if ("string" === typeof b && (b = [b]), b.length) { this.tag = new Map(); this.F = []; this.R = []; - for (let d = 0, f, g; d < c.length; d++) { - f = c[d]; + for (let d = 0, f, g; d < b.length; d++) { + f = b[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.F[d] = f.custom : (this.F[d] = Sa(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); + f.custom ? this.F[d] = f.custom : (this.F[d] = Ta(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); this.R[d] = g; this.tag.set(g, new Map()); } @@ -1529,9 +1560,9 @@ function W(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]; - k[1].then && d.index.set(h, f[g++]); + for (const h of d.index.entries()) { + const k = h[0]; + h[1].then && d.index.set(k, f[g++]); } return d; }); @@ -1540,103 +1571,103 @@ function W(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -u = V.prototype; -u.mount = function(a) { +t = V.prototype; +t.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); } - let b = this.field; + let c = this.field; if (this.tag) { for (let d = 0, f; d < this.R.length; d++) { f = this.R[d]; - var c = void 0; - this.index.set(f, c = new O({}, this.reg)); - b === this.field && (b = b.slice(0)); - b.push(f); - c.tag = this.tag.get(f); + var b = void 0; + this.index.set(f, b = new O({}, this.reg)); + c === this.field && (c = c.slice(0)); + c.push(f); + b.tag = this.tag.get(f); } } - c = []; + b = []; const e = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let d = 0, f, g; d < b.length; d++) { - e.field = g = b[d]; + for (let d = 0, f, g; d < c.length; d++) { + e.field = g = c[d]; f = this.index.get(g); - const k = new a.constructor(a.id, e); - k.id = a.id; - c[d] = k.mount(f); + const h = new a.constructor(a.id, e); + h.id = a.id; + b[d] = h.mount(f); f.document = !0; d ? f.bypass = !0 : f.store = this.store; } this.db = !0; - return Promise.all(c); + return Promise.all(b); }; -u.commit = async function(a, b) { - const c = []; +t.commit = async function(a, c) { + const b = []; for (const e of this.index.values()) { - c.push(e.db.commit(e, a, b)); + b.push(e.commit(e, a, c)); } - await Promise.all(c); + await Promise.all(b); this.reg.clear(); }; -u.destroy = function() { +t.destroy = function() { const a = []; - for (const b of this.index.values()) { - a.push(b.destroy()); + for (const c of this.index.values()) { + a.push(c.destroy()); } return Promise.all(a); }; -function Ta(a, b) { - const c = new Map(); - let e = b.index || b.field || b; +function Ua(a, c) { + const b = new Map(); + let e = c.index || c.field || c; E(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { f = e[d]; E(f) || (g = f, f = f.field); g = I(g) ? Object.assign({}, a, g) : a; if (this.worker) { - const k = new Q(g); - c.set(f, k); + const h = new Q(g); + b.set(f, h); } - this.worker || c.set(f, new O(g, this.reg)); - g.custom ? this.D[d] = g.custom : (this.D[d] = Sa(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)); + this.worker || b.set(f, new O(g, this.reg)); + g.custom ? this.D[d] = g.custom : (this.D[d] = Ta(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)); this.field[d] = f; } if (this.C) { - a = b.store; + a = c.store; E(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Sa(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ta(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); } } - return c; + return b; } -function Sa(a, b) { - const c = a.split(":"); +function Ta(a, c) { + const b = a.split(":"); let e = 0; - for (let d = 0; d < c.length; d++) { - a = c[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[e] = !0), a && (c[e++] = a); + for (let d = 0; d < b.length; d++) { + a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); } - e < c.length && (c.length = e); - return 1 < e ? c : c[0]; + e < b.length && (b.length = e); + return 1 < e ? b : b[0]; } -u.append = function(a, b) { - return this.add(a, b, !0); +t.append = function(a, c) { + return this.add(a, c, !0); }; -u.update = function(a, b) { - return this.remove(a).add(a, b); +t.update = function(a, c) { + return this.remove(a).add(a, c); }; -u.remove = function(a) { +t.remove = function(a) { I(a) && (a = ba(a, this.key)); - for (var b of this.index.values()) { - b.remove(a, !0); + for (var c of this.index.values()) { + c.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]; + for (let b of this.tag.values()) { + for (let e of b) { + c = e[0]; const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : c.delete(b)); + -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); } } } @@ -1646,113 +1677,116 @@ u.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -u.clear = function() { - for (const a of this.index.values()) { - a.clear(); +t.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 a of this.tag.values()) { - a.clear(); + for (const c of this.tag.values()) { + c.clear(); } } this.store && this.store.clear(); - return this; + this.cache && this.cache.clear(); + return a.length ? Promise.all(a) : this; }; -u.contain = function(a) { +t.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; -u.cleanup = function() { +t.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -u.get = function(a) { - return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { - return b[0] && b[0].doc; +t.get = function(a) { + return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(c) { + return c[0] && c[0].doc; }) : this.store.get(a); }; -u.set = function(a, b) { - this.store.set(a, b); +t.set = function(a, c) { + this.store.set(a, c); return this; }; -u.searchCache = Ua; -u.export = function(a, b, c = 0, e = 0) { - if (c < this.field.length) { - const g = this.field[c]; - if ((b = this.index.get(g).export(a, g, c, e = 1)) && b.then) { - const k = this; - return b.then(function() { - return k.export(a, g, c + 1); +t.searchCache = Va; +t.export = function(a, c, b = 0, e = 0) { + if (b < this.field.length) { + const g = this.field[b]; + if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { + const h = this; + return c.then(function() { + return h.export(a, g, b + 1); }); } - return this.export(a, g, c + 1); + return this.export(a, g, b + 1); } let d, f; switch(e) { case 0: d = "reg"; f = wa(this.reg); - b = null; + c = null; break; case 1: d = "tag"; f = this.tag && ua(this.tag, this.reg.size); - b = null; + c = null; break; case 2: d = "doc"; f = this.store && sa(this.store); - b = null; + c = null; break; default: return; } - return ya.call(this, a, b, d, f, c, e); + return ya.call(this, a, c, d, f, b, e); }; -u.import = function(a, b) { - var c = a.split("."); - "json" === c[c.length - 1] && c.pop(); - const e = 2 < c.length ? c[0] : ""; - c = 2 < c.length ? c[2] : c[1]; +t.import = function(a, c) { + var b = a.split("."); + "json" === b[b.length - 1] && b.pop(); + const e = 2 < b.length ? b[0] : ""; + b = 2 < b.length ? b[2] : b[1]; if (this.worker && e) { return this.index.get(e).import(a); } - if (b) { - "string" === typeof b && (b = JSON.parse(b)); + if (c) { + "string" === typeof c && (c = JSON.parse(c)); if (e) { - return this.index.get(e).import(c, b); + return this.index.get(e).import(b, c); } - switch(c) { + switch(b) { case "reg": this.fastupdate = !1; - this.reg = xa(b, this.reg); + this.reg = xa(c, this.reg); for (let d = 0, f; d < this.field.length; d++) { f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg; } if (this.worker) { - b = []; + c = []; for (const d of this.index.values()) { - b.push(d.import(a)); + c.push(d.import(a)); } - return Promise.all(b); + return Promise.all(c); } break; case "tag": - this.tag = va(b, this.tag); + this.tag = va(c, this.tag); break; case "doc": - this.store = ta(b, this.store); + this.store = ta(c, this.store); } } }; la(V.prototype); -function Ua(a, b, c) { +function Va(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); let e = this.cache.get(a); if (!e) { - e = this.search(a, b, c); + e = this.search(a, c, b); if (e.then) { const d = this; e.then(function(f) { @@ -1769,99 +1803,99 @@ function Y(a) { this.cache = new Map(); this.h = ""; } -Y.prototype.set = function(a, b) { - this.cache.set(this.h = a, b); +Y.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); }; Y.prototype.get = function(a) { - const b = this.cache.get(a); - b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); - return b; + const c = this.cache.get(a); + c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); + return c; }; Y.prototype.remove = function(a) { - for (const b of this.cache) { - const c = b[0]; - b[1].includes(a) && this.cache.delete(c); + for (const c of this.cache) { + const b = c[0]; + c[1].includes(a) && this.cache.delete(b); } }; Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Va = {normalize:function(a) { +const Wa = {normalize:function(a) { return a.toLowerCase(); }}; -const Wa = 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 Xa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ya = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const Za = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const $a = /[\x00-\x7F]+/g; +const Xa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const Ya = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Za = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const $a = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; const ab = /[\x00-\x7F]+/g; const bb = /[\x00-\x7F]+/g; -var cb = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Va, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Wa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Wa, matcher:Xa, replacer:Ya}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Wa, replacer:Ya.concat([/(?!^)[aeo]/g, ""]), matcher:Xa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { - for (let c = 0; c < a.length; c++) { - var b = a[c]; - let e = b.charAt(0), d = Za[e]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Za[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { +const cb = /[\x00-\x7F]+/g; +var db = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Wa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Xa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Xa, matcher:Ya, replacer:Za}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Xa, replacer:Za.concat([/(?!^)[aeo]/g, ""]), matcher:Ya}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { + for (let b = 0; b < a.length; b++) { + var c = a[b]; + let e = c.charAt(0), d = $a[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = $a[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[c] = e; + a[b] = e; } }}, ArabicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace($a, " "); + return ("" + a).replace(ab, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(ab, ""); + return ("" + a).replace(bb, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(bb, " "); + return ("" + a).replace(cb, " "); }}}; -const db = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -O.prototype.add = function(a, b, c, e) { - if (b && (a || 0 === a)) { - if (!e && !c && this.reg.has(a)) { - return this.update(a, b); +const eb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +O.prototype.add = function(a, c, b, e) { + if (c && (a || 0 === a)) { + if (!e && !b && this.reg.has(a)) { + return this.update(a, c); } - b = this.encoder.encode(b); - if (e = b.length) { - const l = B(), n = B(), m = this.depth, q = this.resolution; - for (let p = 0; p < e; p++) { - let t = b[this.rtl ? e - 1 - p : p]; - var d = t.length; - if (d && (m || !n[t])) { - var f = this.score ? this.score(b, t, p, null, 0) : eb(q, e, p), g = ""; + c = this.encoder.encode(c); + if (e = c.length) { + const l = B(), m = B(), n = this.depth, q = this.resolution; + for (let r = 0; r < e; r++) { + let p = c[this.rtl ? e - 1 - r : r]; + var d = p.length; + if (d && (n || !m[p])) { + var f = this.score ? this.score(c, p, r, null, 0) : fb(q, e, r), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let r = 0, v; r < d; r++) { - for (f = d; f > r; f--) { - g = t.substring(r, f); - v = this.rtl ? d - 1 - r : r; - var k = this.score ? this.score(b, t, p, g, v) : eb(q, e, p, d, v); - fb(this, n, g, k, a, c); + for (let v = 0, u; v < d; v++) { + for (f = d; f > v; f--) { + g = p.substring(v, f); + u = this.rtl ? d - 1 - v : v; + var h = this.score ? this.score(c, p, r, g, u) : fb(q, e, r, d, u); + gb(this, m, g, h, a, b); } } break; } case "reverse": if (1 < d) { - for (k = d - 1; 0 < k; k--) { - g = t[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(b, t, p, g, k) : eb(q, e, p, d, k); - fb(this, n, g, h, a, c); + for (h = d - 1; 0 < h; h--) { + g = p[this.rtl ? d - 1 - h : h] + g; + var k = this.score ? this.score(c, p, r, g, h) : fb(q, e, r, d, h); + gb(this, m, g, k, a, b); } g = ""; } case "forward": if (1 < d) { - for (k = 0; k < d; k++) { - g += t[this.rtl ? d - 1 - k : k], fb(this, n, g, f, a, c); + for (h = 0; h < d; h++) { + g += p[this.rtl ? d - 1 - h : h], gb(this, m, g, f, a, b); } break; } default: - if (fb(this, n, t, f, a, c), m && 1 < e && p < e - 1) { - for (d = B(), g = this.U, f = t, k = Math.min(m + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { - if ((t = b[this.rtl ? e - 1 - p - h : p + h]) && !d[t]) { - d[t] = 1; - const r = this.score ? this.score(b, f, p, t, h - 1) : eb(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && t > f; - fb(this, l, v ? f : t, r, a, c, v ? t : f); + if (gb(this, m, p, f, a, b), n && 1 < e && r < e - 1) { + for (d = B(), g = this.U, f = p, h = Math.min(n + 1, this.rtl ? r + 1 : e - r), d[f] = 1, k = 1; k < h; k++) { + if ((p = c[this.rtl ? e - 1 - r - k : r + k]) && !d[p]) { + d[p] = 1; + const v = this.score ? this.score(c, f, r, p, k - 1) : fb(g + (e / 2 > g ? 0 : 1), e, r, h - 1, k - 1), u = this.bidirectional && p > f; + gb(this, l, u ? f : p, v, a, b, u ? p : f); } } } @@ -1870,105 +1904,105 @@ O.prototype.add = function(a, b, c, e) { } this.fastupdate || this.reg.add(a); } else { - b = ""; + c = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && gb(this)); + this.db && (c || this.commit_task.push({del:a}), this.T && hb(this)); return this; }; -function fb(a, b, c, e, d, f, g) { - let k = g ? a.ctx : a.map, h; - if (!b[c] || g && !(h = b[c])[g]) { - if (g ? (b = h || (b[c] = B()), b[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : b[c] = 1, (h = k.get(c)) ? k = h : k.set(c, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { - if (k.length === 2 ** 31 - 1) { - b = new S(k); +function gb(a, c, b, e, d, f, g) { + let h = g ? a.ctx : a.map, k; + if (!c[b] || g && !(k = c[b])[g]) { + if (g ? (c = k || (c[b] = B()), 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 = k = []), h = h[e] || (h[e] = []), !f || !h.includes(d)) { + if (h.length === 2 ** 31 - 1) { + c = new S(h); if (a.fastupdate) { for (let l of a.reg.values()) { - l.includes(k) && (l[l.indexOf(k)] = b); + l.includes(h) && (l[l.indexOf(h)] = c); } } - h[e] = k = b; + k[e] = h = c; } - k.push(d); - a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); + h.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(h) : a.reg.set(d, [h])); } } } -function eb(a, b, c, e, d) { - return c && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; +function fb(a, c, b, e, d) { + return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;O.prototype.search = function(a, b, c) { - c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); - let e = [], d, f, g, k = 0, h, l, n, m, q; - c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, q = (h = !1 !== c.resolve) && c.enrich, n = c.boost, m = c.resolution, l = this.db && c.tag) : h = this.resolve; - let p = this.encoder.encode(a); - d = p.length; - b = b || (h ? 100 : 0); +;O.prototype.search = function(a, c, b) { + b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); + let e = [], d, f, g, h = 0, k, l, m, n, q; + b ? (a = b.query || a, c = b.limit || c, h = b.offset || 0, f = b.context, g = b.suggest, q = (k = !1 !== b.resolve) && b.enrich, m = b.boost, n = b.resolution, l = this.db && b.tag) : k = this.resolve; + let r = this.encoder.encode(a); + d = r.length; + c = c || (k ? 100 : 0); if (1 === d) { - return hb.call(this, p[0], "", b, k, h, q, l); + return ib.call(this, r[0], "", c, h, k, q, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return hb.call(this, p[0], p[1], b, k, h, q, l); + return ib.call(this, r[0], r[1], c, h, k, q, l); } - let t = B(), r = 0, v; - 1 < d && f && (v = p[0], r = 1); - m || 0 === m || (m = v ? this.U : this.resolution); + let p = B(), v = 0, u; + 1 < d && f && (u = r[0], v = 1); + n || 0 === n || (n = u ? this.U : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, p, b, k, g, h, q, l), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, r, c, h, g, k, q, l), !1 !== a)) { return a; } const x = this; return async function() { - for (let y, F; r < d; r++) { - if ((F = p[r]) && !t[F]) { - t[F] = 1; - y = await ib(x, F, v, 0, 0, !1, !1); - if (y = jb(y, e, g, m)) { + for (let y, F; v < d; v++) { + if ((F = r[v]) && !p[F]) { + p[F] = 1; + y = await jb(x, F, u, 0, 0, !1, !1); + if (y = kb(y, e, g, n)) { e = y; break; } - v && (g && y && e.length || (v = F)); + u && (g && y && e.length || (u = F)); } - g && v && r === d - 1 && !e.length && (m = x.resolution, v = "", r = -1, t = B()); + g && u && v === d - 1 && !e.length && (n = x.resolution, u = "", v = -1, p = B()); } - return kb(e, m, b, k, g, n, h); + return lb(e, n, c, h, g, m, k); }(); } - for (let x, y; r < d; r++) { - if ((y = p[r]) && !t[y]) { - t[y] = 1; - x = ib(this, y, v, 0, 0, !1, !1); - if (x = jb(x, e, g, m)) { + for (let x, y; v < d; v++) { + if ((y = r[v]) && !p[y]) { + p[y] = 1; + x = jb(this, y, u, 0, 0, !1, !1); + if (x = kb(x, e, g, n)) { e = x; break; } - v && (g && x && e.length || (v = y)); + u && (g && x && e.length || (u = y)); } - g && v && r === d - 1 && !e.length && (m = this.resolution, v = "", r = -1, t = B()); + g && u && v === d - 1 && !e.length && (n = this.resolution, u = "", v = -1, p = B()); } - return kb(e, m, b, k, g, n, h); + return lb(e, n, c, h, g, m, k); }; -function kb(a, b, c, e, d, f, g) { - let k = a.length, h = a; - if (1 < k) { - h = Ea(a, b, c, e, d, f, g); - } else if (1 === k) { - return g ? Ha.call(null, a[0], c, e) : new X(a[0]); +function lb(a, c, b, e, d, f, g) { + let h = a.length, k = a; + if (1 < h) { + k = Fa(a, c, b, e, d, f, g); + } else if (1 === h) { + return g ? Ia.call(null, a[0], b, e) : new X(a[0]); } - return g ? h : new X(h); + return g ? k : new X(k); } -function hb(a, b, c, e, d, f, g) { - a = ib(this, a, b, c, e, d, f, g); - return this.db ? a.then(function(k) { - return d ? k || [] : new X(k); - }) : a && a.length ? d ? Ha.call(this, a, c, e) : new X(a) : d ? [] : new X(); +function ib(a, c, b, e, d, f, g) { + a = jb(this, a, c, b, e, d, f, g); + return this.db ? a.then(function(h) { + return d ? h || [] : new X(h); + }) : a && a.length ? d ? Ia.call(this, a, b, e) : new X(a) : d ? [] : new X(); } -function jb(a, b, c, e) { +function kb(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { - b.push(a); + c.push(a); return; } for (let f = 0, g; f < e; f++) { @@ -1977,122 +2011,123 @@ function jb(a, b, c, e) { } } if (d.length) { - b.push(d); + c.push(d); return; } } - if (!c) { + if (!b) { return d; } } -function ib(a, b, c, e, d, f, g, k) { - let h; - c && (h = a.bidirectional && b > c) && (h = c, c = b, b = h); +function jb(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(b, c, e, d, f, g, k); + return a.db.get(c, b, e, d, f, g, h); } - a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); + a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;O.prototype.remove = function(a, b) { - const c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); - if (c) { +;O.prototype.remove = function(a, c) { + const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (b) { if (this.fastupdate) { - for (let e = 0, d; e < c.length; e++) { - if (d = c[e]) { + for (let e = 0, d; e < b.length; e++) { + if (d = b[e]) { if (2 > d.length) { d.pop(); } else { const f = d.indexOf(a); - f === c.length - 1 ? d.pop() : d.splice(f, 1); + f === b.length - 1 ? d.pop() : d.splice(f, 1); } } } } else { - lb(this.map, a), this.depth && lb(this.ctx, a); + mb(this.map, a), this.depth && mb(this.ctx, a); } - b || this.reg.delete(a); + c || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && gb(this)); + this.db && (this.commit_task.push({del:a}), this.T && hb(this)); this.cache && this.cache.remove(a); return this; }; -function lb(a, b) { - let c = 0; +function mb(a, c) { + let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { if ((d = a[e]) && d.length) { - if (f = d.indexOf(b), 0 <= f) { - 1 < d.length ? (d.splice(f, 1), c++) : delete a[e]; + if (f = d.indexOf(c), 0 <= f) { + 1 < d.length ? (d.splice(f, 1), b++) : delete a[e]; break; } else { - c++; + b++; } } } } else { for (let e of a.entries()) { - const d = e[0], f = lb(e[1], b); - f ? c += f : a.delete(d); + const d = e[0], f = mb(e[1], c); + f ? b += f : a.delete(d); } } - return c; + return b; } -;function O(a, b) { +;function O(a, c) { if (!this || this.constructor !== O) { return new O(a); } if (a) { - var c = E(a) ? a : a.preset; - c && (db[c] || console.warn("Preset not found: " + c), a = Object.assign({}, db[c], a)); + var b = E(a) ? a : a.preset; + b && (eb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, eb[b], a)); } else { a = {}; } - c = a.context; - const e = !0 === c ? {depth:1} : c || {}, d = E(a.encoder) ? cb[a.encoder] : a.encode || a.encoder || Va; + b = a.context; + const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? db[a.encoder] : a.encode || a.encoder || Wa; this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = (c = a.tokenize) && "default" !== c && c || "strict"; - this.depth = "strict" === c && e.depth || 0; + this.tokenize = b = (b = a.tokenize) && "default" !== b && b || "strict"; + this.depth = "strict" === b && e.depth || 0; this.bidirectional = !1 !== e.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; - (c = a.keystore || 0) && (this.keystore = c); - this.map = c ? new T(c) : new Map(); - this.ctx = c ? new T(c) : new Map(); - this.reg = b || (this.fastupdate ? c ? new T(c) : new Map() : c ? new U(c) : new Set()); + e && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); + (b = a.keystore || 0) && (this.keystore = b); + this.map = b ? new T(b) : new Map(); + this.ctx = b ? new T(b) : new Map(); + this.reg = c || (this.fastupdate ? b ? new T(b) : new Map() : b ? new U(b) : new Set()); this.U = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new Y(c); + this.cache = (b = a.cache || null) && new Y(b); this.resolve = !1 !== a.resolve; - if (c = a.db) { - this.db = this.mount(c); + if (b = a.db) { + this.db = this.mount(b); } this.T = !1 !== a.commit; this.commit_task = []; this.commit_timer = null; this.priority = a.priority || 4; } -u = O.prototype; -u.mount = function(a) { +t = O.prototype; +t.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -u.commit = function(a, b) { +t.commit = function(a, c) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); - return this.db.commit(this, a, b); + return this.db.commit(this, a, c); }; -u.destroy = function() { +t.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function gb(a) { +function hb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); }, 1)); } -u.clear = function() { +t.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); @@ -2100,40 +2135,40 @@ u.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -u.append = function(a, b) { - return this.add(a, b, !0); +t.append = function(a, c) { + return this.add(a, c, !0); }; -u.contain = function(a) { +t.contain = function(a) { return this.db ? this.db.has(a) : this.reg.has(a); }; -u.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); +t.update = function(a, c) { + const b = this, e = this.remove(a); + return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function mb(a) { - let b = 0; +function nb(a) { + let c = 0; if (a.constructor === Array) { - for (let c = 0, e; c < a.length; c++) { - (e = a[c]) && (b += e.length); + for (let b = 0, e; b < a.length; b++) { + (e = a[b]) && (c += e.length); } } else { - for (const c of a) { - const e = c[0], d = mb(c[1]); - d ? b += d : a.delete(e); + for (const b of a.entries()) { + const e = b[0], d = nb(b[1]); + d ? c += d : a.delete(e); } } - return b; + return c; } -u.cleanup = function() { +t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - mb(this.map); - this.depth && mb(this.ctx); + nb(this.map); + this.depth && nb(this.ctx); return this; }; -u.searchCache = Ua; -u.export = function(a, b, c = 0, e = 0) { +t.searchCache = Va; +t.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: @@ -2155,230 +2190,203 @@ u.export = function(a, b, c = 0, e = 0) { default: return; } - return ya.call(this, a, b, d, f, c, e); + return ya.call(this, a, c, d, f, b, e); }; -u.import = function(a, b) { - if (b) { - switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { +t.import = function(a, c) { + if (c) { + switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = xa(b, this.reg); + this.reg = xa(c, this.reg); break; case "map": - this.map = ta(b, this.map); + this.map = ta(c, this.map); break; case "ctx": - this.ctx = va(b, this.ctx); + this.ctx = va(c, this.ctx); } } }; -u.serialize = function(a = !0) { - if (!this.reg.size) { - return ""; - } - let b = "", c = ""; - for (var e of this.reg.keys()) { - c || (c = typeof e), b += (b ? "," : "") + ("string" === c ? '"' + e + '"' : e); - } - b = "index.reg=new Set([" + b + "]);"; - e = ""; - for (var d of this.map.entries()) { - var f = d[0], g = d[1], k = ""; - for (let n = 0, m; n < g.length; n++) { - m = g[n] || [""]; - var h = ""; - for (var l = 0; l < m.length; l++) { - h += (h ? "," : "") + ("string" === c ? '"' + m[l] + '"' : m[l]); - } - h = "[" + h + "]"; - k += (k ? "," : "") + h; +t.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 ? "," : "") + ("string" === f ? '"' + d + '"' : d); } - k = '["' + f + '",[' + k + "]]"; - e += (e ? "," : "") + k; - } - e = "index.map=new Map([" + e + "]);"; - d = ""; - for (const n of this.ctx.entries()) { - f = n[0]; - g = n[1]; - for (const m of g.entries()) { - g = m[0]; - k = m[1]; - h = ""; - for (let q = 0, p; q < k.length; q++) { - p = k[q] || [""]; - l = ""; - for (let t = 0; t < p.length; t++) { - l += (l ? "," : "") + ("string" === c ? '"' + p[t] + '"' : p[t]); - } - l = "[" + l + "]"; - h += (h ? "," : "") + l; - } - h = 'new Map([["' + g + '",[' + h + "]]])"; - h = '["' + f + '",' + h + "]"; - d += (d ? "," : "") + h; + c = "index.reg=new Set([" + c + "]);"; + b = za(this.map, f); + b = "index.map=new Map([" + b + "]);"; + for (const g of this.ctx.entries()) { + d = g[0]; + let h = za(g[1], f); + h = "new Map([" + h + "])"; + h = '["' + d + '",' + h + "]"; + e += (e ? "," : "") + h; } + e = "index.ctx=new Map([" + e + "]);"; } - d = "index.ctx=new Map([" + d + "]);"; - return a ? "function inject(index){" + b + e + d + "}" : b + e + d; + return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; la(O.prototype); -const nb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), ob = ["map", "ctx", "tag", "reg", "cfg"]; -function pb(a, b = {}) { +const ob = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), pb = ["map", "ctx", "tag", "reg", "cfg"]; +function qb(a, c = {}) { if (!this) { - return new pb(a, b); + return new qb(a, c); } - "object" === typeof a && (b = a, a = a.name); + "object" === typeof a && (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 = b.field ? b.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; - this.type = b.type; + 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 = {}; } -u = pb.prototype; -u.mount = function(a) { +t = qb.prototype; +t.mount = function(a) { if (!a.encoder) { return a.mount(this); } a.db = this; return this.open(); }; -u.open = function() { +t.open = function() { let a = this; navigator.storage && navigator.storage.persist(); - return this.db || new Promise(function(b, c) { - const e = nb.open(a.id + (a.field ? ":" + a.field : ""), 1); + return this.db || new Promise(function(c, b) { + const e = ob.open(a.id + (a.field ? ":" + a.field : ""), 1); e.onupgradeneeded = function() { const d = a.db = this.result; - ob.forEach(f => { + pb.forEach(f => { d.objectStoreNames.contains(f) || d.createObjectStore(f); }); }; e.onblocked = function(d) { console.error("blocked", d); - c(); + b(); }; e.onerror = function(d) { console.error(this.error, d); - c(); + b(); }; e.onsuccess = function() { a.db = this.result; a.db.onversionchange = function() { a.close(); }; - b(a); + c(a); }; }); }; -u.close = function() { - this.db.close(); +t.close = function() { + this.db && this.db.close(); this.db = null; }; -u.destroy = function() { - const a = nb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); +t.destroy = function() { + const a = ob.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); return Z(a); }; -u.clear = function() { - const a = this.db.transaction(ob, "readwrite"); - for (let b = 0; b < ob.length; b++) { - a.objectStore(ob[b]).clear(); +t.clear = function() { + const a = this.db.transaction(pb, "readwrite"); + for (let c = 0; c < pb.length; c++) { + a.objectStore(pb[c]).clear(); } return Z(a); }; -u.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { - a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); +t.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { + a = this.db.transaction(c ? "ctx" : "map", "readonly").objectStore(c ? "ctx" : "map").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 (!c && !e && 1 === k.length) { - return k[0]; + if (!b && !e && 1 === h.length) { + 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 m = c ? e + Math.min(n.length - e, c) : n.length; - for (let q = e; q < m; q++) { - h.push(n[q]); + const n = b ? e + Math.min(m.length - e, b) : m.length; + for (let q = e; q < n; q++) { + k.push(m[q]); } e = 0; - if (h.length === c) { + if (k.length === b) { break; } } } - return f ? g.enrich(h) : h; + return f ? g.enrich(k) : k; } - return k; + return h; }); }; -u.tag = function(a, b = 0, c = 0, e = !1) { +t.tag = function(a, c = 0, b = 0, e = !1) { a = this.db.transaction("tag", "readonly").objectStore("tag").get(a); const d = this; return Z(a).then(function(f) { - if (!f || !f.length || c >= f.length) { + if (!f || !f.length || b >= f.length) { return []; } - if (!b && !c) { + if (!c && !b) { return f; } - f = f.slice(c, c + b); + f = f.slice(b, b + c); return e ? d.enrich(f) : f; }); }; -u.enrich = function(a) { +t.enrich = function(a) { "object" !== typeof a && (a = [a]); - const b = this.db.transaction("reg", "readonly").objectStore("reg"), c = []; + const c = this.db.transaction("reg", "readonly").objectStore("reg"), b = []; for (let e = 0; e < a.length; e++) { - c[e] = Z(b.get(a[e])); + b[e] = Z(c.get(a[e])); } - return Promise.all(c).then(function(e) { + return Promise.all(b).then(function(e) { for (let d = 0; d < e.length; d++) { e[d] = {id:a[d], doc:e[d] ? JSON.parse(e[d]) : null}; } return e; }); }; -u.has = function(a) { +t.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Z(a); -}; -u.search = null; -u.info = function() { -}; -u.transaction = function(a, b, c) { - let e = this.h[a + ":" + b]; - if (e) { - return c.call(this, e); - } - let d = this.db.transaction(a, b); - this.h[a + ":" + b] = e = d.objectStore(a); - return new Promise((f, g) => { - d.onerror = h => { - d.abort(); - d = e = null; - g(h); - }; - d.oncomplete = h => { - d = e = null; - f(h || !0); - }; - const k = c.call(this, e); - this.h[a + ":" + b] = null; - return k; + return Z(a).then(function(c) { + return !!c; }); }; -u.commit = async function(a, b, c) { - if (b) { +t.search = null; +t.info = function() { +}; +t.transaction = function(a, c, b) { + let e = this.h[a + ":" + c]; + if (e) { + return b.call(this, e); + } + let d = this.db.transaction(a, c); + this.h[a + ":" + c] = e = d.objectStore(a); + return new Promise((f, g) => { + d.onerror = k => { + d.abort(); + d = e = null; + g(k); + }; + d.oncomplete = k => { + d = e = null; + f(k || !0); + }; + const h = b.call(this, e); + this.h[a + ":" + c] = null; + return h; + }); +}; +t.commit = async function(a, c, b) { + if (c) { await this.clear(), a.commit_task = []; } else { let e = a.commit_task; @@ -2386,66 +2394,66 @@ u.commit = async function(a, b, c) { for (let d = 0, f; d < e.length; d++) { if (f = e[d], f.clear) { await this.clear(); - b = !0; + c = !0; break; } else { e[d] = f.W; } } - b || (c || (e = e.concat(aa(a.reg))), e.length && await this.remove(e)); + c || (b || (e = e.concat(aa(a.reg))), e.length && await this.remove(e)); } 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 && (b ? 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, m, q; n < l; n++) { - if ((q = g[n]) && q.length) { - if ((m = k[n]) && m.length) { - for (h = 0; h < q.length; h++) { - m.push(q[h]); + g.length && (c ? e.put(g, f) : 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, n, q; m < l; m++) { + if ((q = g[m]) && q.length) { + if ((n = h[m]) && n.length) { + for (k = 0; k < q.length; k++) { + n.push(q[k]); } } else { - k[n] = q; + h[m] = q; } - 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 && (b ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { - let n = this.result; - var m; - if (n && n.length) { - const q = Math.max(n.length, l.length); - for (let p = 0, t, r; p < q; p++) { - if ((r = l[p]) && r.length) { - if ((t = n[p]) && t.length) { - for (m = 0; m < r.length; m++) { - t.push(r[m]); + for (const h of g) { + const k = h[0], l = h[1]; + l.length && (c ? e.put(l, f + ":" + k) : e.get(f + ":" + k).onsuccess = function() { + let m = this.result; + var n; + if (m && m.length) { + const q = Math.max(m.length, l.length); + for (let r = 0, p, v; r < q; r++) { + if ((v = l[r]) && v.length) { + if ((p = m[r]) && p.length) { + for (n = 0; n < v.length; n++) { + p.push(v[n]); } } else { - n[p] = r; + m[r] = v; } - m = 1; + n = 1; } } } else { - n = l, m = 1; + m = l, n = 1; } - m && e.put(n, f + ":" + h); + n && e.put(m, f + ":" + k); }); } } @@ -2462,75 +2470,75 @@ u.commit = async function(a, b, c) { 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 rb(a, b, c) { +function sb(a, c, b) { const e = a.value; let d, f, g = 0; - for (let k = 0, h; k < e.length; k++) { - if (h = c ? e : e[k]) { - for (let l = 0, n, m; l < b.length; l++) { - if (m = b[l], n = h.indexOf(f ? parseInt(m, 10) : m), 0 > n && !f && "string" === typeof m && !isNaN(m) && (n = h.indexOf(parseInt(m, 10))) && (f = 1), 0 <= n) { - if (d = 1, 1 < h.length) { - h.splice(n, 1); + for (let h = 0, k; h < e.length; h++) { + if (k = b ? e : e[h]) { + for (let l = 0, m, n; l < c.length; l++) { + if (n = c[l], m = k.indexOf(f ? parseInt(n, 10) : n), 0 > m && !f && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (f = 1), 0 <= m) { + if (d = 1, 1 < k.length) { + k.splice(m, 1); } else { - e[k] = []; + e[h] = []; break; } } } - g += h.length; + g += k.length; } - if (c) { + if (b) { break; } } g ? d && a.update(e) : a.delete(); a.continue(); } -u.remove = function(a) { +t.remove = function(a) { "object" !== typeof a && (a = [a]); - return Promise.all([this.transaction("map", "readwrite", function(b) { - b.openCursor().onsuccess = function() { - const c = this.result; - c && rb(c, a); + return Promise.all([this.transaction("map", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && sb(b, a); }; - }), this.transaction("ctx", "readwrite", function(b) { - b.openCursor().onsuccess = function() { - const c = this.result; - c && rb(c, a); + }), this.transaction("ctx", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && sb(b, a); }; - }), this.transaction("tag", "readwrite", function(b) { - b.openCursor().onsuccess = function() { - const c = this.result; - c && rb(c, a, !0); + }), this.transaction("tag", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && sb(b, a, !0); }; - }), this.transaction("reg", "readwrite", function(b) { - for (let c = 0; c < a.length; c++) { - b.delete(a[c]); + }), this.transaction("reg", "readwrite", function(c) { + for (let b = 0; b < a.length; b++) { + c.delete(a[b]); } })]); }; function Z(a) { - return new Promise((b, c) => { + return new Promise((c, b) => { a.onsuccess = function() { - b(this.result); + c(this.result); }; a.oncomplete = function() { - b(this.result); + c(this.result); }; - a.onerror = c; + a.onerror = b; a = null; }); } -;const sb = {Index:O, Charset:cb, Encoder:J, Document:V, Worker:Q, Resolver:X, IndexedDB:pb, Language:{}}, tb = self; -let ub; -(ub = tb.define) && ub.amd ? ub([], function() { - return sb; -}) : "object" === typeof tb.exports ? tb.exports = sb : tb.FlexSearch = sb; +;const tb = {Index:O, Charset:db, Encoder:J, Document:V, Worker:Q, Resolver:X, IndexedDB:qb, Language:{}}, ub = self; +let vb; +(vb = ub.define) && vb.amd ? vb([], function() { + return tb; +}) : "object" === typeof ub.exports ? ub.exports = tb : ub.FlexSearch = tb; }(this||self)); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index 4f50729..39423f9 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,102 +1,103 @@ /**! - * FlexSearch.js v0.8.123 (Bundle) + * FlexSearch.js v0.8.132 (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 u;function A(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(k){return a(c(k))};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"undefined"===d?b:a}function B(){return Object.create(null)}function E(a){return"string"===typeof a} +(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var t;function A(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&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"undefined"===d?b:a}function B(){return Object.create(null)}function E(a){return"string"===typeof a} function I(a){return"object"===typeof a}function aa(a){const b=[];for(const c of a.keys())b.push(c);return b}function ba(a,b){if(E(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; -this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,ea)}catch(d){this.split=/\s+/}this.numeric=A(a.numeric,A(this.numeric,!0))}this.prepare=A(a.prepare,null,this.prepare);this.finalize=A(a.finalize,null,this.finalize);ja||(this.mapper=new Map(da));this.rtl=A(a.rtl,!1,this.rtl);this.dedupe=A(a.dedupe,!1,this.dedupe);this.filter=A((c=a.filter)&&new Set(c),null,this.filter);this.matcher=A((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=A((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= -A((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=A(a.replacer,null,this.replacer);this.minlength=A(a.minlength,1,this.minlength);this.maxlength=A(a.maxlength,0,this.maxlength);if(this.cache=c=A(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= -(this.A?"|":"")+d;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&L(this);return this};u.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&L(this);return this};u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&L(this);return this};u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&L(this);return this}; -u.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(L,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d -this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(b=a.factory)?(Function("return "+b)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[b].apply(M,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} +["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]];const ea=/[^\p{L}\p{N}]+/u,fa=/(\d{3})/g,ha=/(\D)(\d{3})/g,ia=/(\d{3})(\D)/g,ja="".normalize&&/[\u0300-\u036f]/g;function J(a={}){if(!this||this.constructor!==J)return new J(...arguments);if(arguments.length)for(a=0;a"a1a".split(c).length; +this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,ea)}catch(d){this.split=/\s+/}this.numeric=A(a.numeric,A(this.numeric,!0))}this.prepare=A(a.prepare,null,this.prepare);this.finalize=A(a.finalize,null,this.finalize);ja||(this.mapper=new Map(da));c=a.filter;this.filter="function"===typeof c?c:A(c&&new Set(c),null,this.filter);this.dedupe=A(a.dedupe,!1,this.dedupe);this.matcher=A((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=A((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= +A((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=A(a.replacer,null,this.replacer);this.minlength=A(a.minlength,1,this.minlength);this.maxlength=A(a.maxlength,0,this.maxlength);this.rtl=A(a.rtl,!1,this.rtl);if(this.cache=c=A(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= +(this.A?"|":"")+d;return this};t.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&K(this);return this};t.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&K(this);return this}; +t.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&K(this);return this}; +t.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&K(this);return this}; +t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(K,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),d!==g&&this.filter&& +g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function K(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(b=a.factory)?(Function("return "+b)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[b].apply(M,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} function ma(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);na?pa||(pa=Date.now()-oa>=this.priority*this.priority*3):(na=setTimeout(qa,0),oa=Date.now());if(pa){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 P=0; -function Q(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,n=l&&d.h[l];n&&(n(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++P]=function(){h(d);1E9=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const k=b.length;if(k&&(d=d.length?d.concat(b):b,c-=k,e&&(a.length-=k),!c))break;b=0}return d} -function S(a){if(!this)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,k,h;gc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let m=0,q;me)e-= -q.length;else{if(q.length>c||e)q=q.slice(e,c+e),c-=q.length,e&&(e-=q.length);d.push(q);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?W.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Fa(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:n,suggest:m}=Ia(this,"and",arguments);return Ka.call(this,f,g,k,h,l,n,m)}return d?this.resolve(b,c,e):this}; -function Ka(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Ea(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ia(this,"xor",arguments);return La.call(this,a,b,c,e,d,f,g)}; -function La(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=Ma.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} -function Ma(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Va={normalize:function(a){return a.toLowerCase()}};const Wa=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 Xa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Ya=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Za={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const $a=/[\x00-\x7F]+/g;const ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;var cb={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Va,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Wa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Wa,matcher:Xa,replacer:Ya},LatinExtra:{normalize:!0,dedupe:!0,mapper:Wa,replacer:Ya.concat([/(?!^)[aeo]/g,""]),matcher:Xa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;ct;f--){g=r.substring(t,f);v=this.rtl?d-1-t:t;var k=this.score?this.score(b,r,p,g,v):eb(q,e,p,d,v); -fb(this,n,g,k,a,c)}break}case "reverse":if(1g?0:1),e,p,k-1,h-1),v=this.bidirectional&& -r>f;fb(this,l,v?f:r,t,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&gb(this));return this}; -function fb(a,b,c,e,d,f,g){let k=g?a.ctx:a.map,h;if(!b[c]||g&&!(h=b[c])[g])if(g?(b=h||(b[c]=B()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new S(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} -function eb(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else lb(this.map,a),this.depth&&lb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&gb(this));this.cache&&this.cache.remove(a);return this}; -function lb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; -function mb(a){let b=0;if(a.constructor===Array)for(let c=0,e;c{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; -u.close=function(){this.db.close();this.db=null};u.destroy=function(){const a=nb.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};u.clear=function(){const a=this.db.transaction(ob,"readwrite");for(let b=0;b=n.length){e-=n.length;continue}const m=c?e+Math.min(n.length-e,c):n.length;for(let q=e;q=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; -u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{d.onerror=h=>{d.abort();d=e=null;g(h)};d.oncomplete=h=>{d=e=null;f(h||!0)};const k=c.call(this,e);this.h[a+":"+b]=null;return k})}; -u.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dn&&!f&&"string"===typeof m&&!isNaN(m)&&(n=h.indexOf(parseInt(m,10)))&&(f=1),0<=n)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const sb={Index:O,Charset:cb,Encoder:J,Document:V,Worker:Q,Resolver:X,IndexedDB:qb,Language:{}},tb=self;let ub;(ub=tb.define)&&ub.amd?ub([],function(){return sb}):"object"===typeof tb.exports?tb.exports=sb:tb.FlexSearch=sb;}(this||self)); +function ya(a,b,c,e,d,f,g=0){const h=e&&e.constructor===Array;var k=h?e.shift():e;if(!k)return this.export(a,b,d,f+1);if((k=a((b?b+".":"")+(g+1)+"."+c,JSON.stringify(k)))&&k.then){const l=this;return k.then(function(){return ya.call(l,a,b,c,h?e:null,d,f,g+1)})}return ya.call(this,a,b,c,h?e:null,d,f,g+1)} +function za(a,b){let c="";for(const e of a.entries()){a=e[0];const d=e[1];let f="";for(let g=0,h;g=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 S(a){if(!this||this.constructor!==S)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;gc||e?k.slice(e,c+e):k;else{if(ac||e)k=k.slice(e,c+e)}else{d=[];for(let n= +0,p;ne)e-=p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=b);if(!d.length&&h>=b)return e?W.call(this,g):g;d.push(g);b-=h;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,m,n)}return d?this.resolve(b,c,e):this}; +function La(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; +function Ma(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function Na(a,b,c,e,d){const f=[],g=B();let h=0;for(let k=0,l;kc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:function(a){return a.toLowerCase()}};const Xa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Ya=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const $a={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;var db={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Wa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Xa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{normalize:!0,dedupe:!0,mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cu;f--){g=q.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(b,q,r,g,v):fb(p,e,r,d,v); +gb(this,m,g,h,a,c)}break}case "reverse":if(1g?0:1),e,r,h-1,k-1),v=this.bidirectional&& +q>f;gb(this,l,v?f:q,u,a,c,v?q:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&hb(this));return this}; +function gb(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){b=new S(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 fb(a,b,c,e,d){return c&&1c)&&(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};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&hb(this));this.cache&&this.cache.remove(a);return this}; +function mb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; +function nb(a){let b=0;if(a.constructor===Array)for(let c=0,e;c{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; +t.close=function(){this.db&&this.db.close();this.db=null};t.destroy=function(){const a=ob.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(pb,"readwrite");for(let b=0;b=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let p=e;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; +t.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{d.onerror=k=>{d.abort();d=e=null;g(k)};d.oncomplete=k=>{d=e=null;f(k||!0)};const h=c.call(this,e);this.h[a+":"+b]=null;return h})}; +t.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dm&&!f&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const tb={Index:O,Charset:db,Encoder:J,Document:V,Worker:Q,Resolver:X,IndexedDB:rb,Language:{}},ub=self;let vb;(vb=ub.define)&&vb.amd?vb([],function(){return tb}):"object"===typeof ub.exports?ub.exports=tb:ub.FlexSearch=tb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index 4f33c7e..d2a45b0 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,35 +1,35 @@ /**! - * FlexSearch.js v0.8.123 (Bundle/Module/Debug) + * FlexSearch.js v0.8.132 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var u; -function A(a, b, c) { - const e = typeof c, d = typeof a; +var t; +function A(a, c, b) { + const e = typeof b, d = typeof a; if ("undefined" !== e) { if ("undefined" !== d) { - if (c) { + if (b) { if ("function" === d && e === d) { - return function(k) { - return a(c(k)); + return function(h) { + return a(b(h)); }; } - b = a.constructor; - if (b === c.constructor) { - if (b === Array) { - return c.concat(a); + c = a.constructor; + if (c === b.constructor) { + if (c === Array) { + return b.concat(a); } - if (b === Map) { - var f = new Map(c); + if (c === Map) { + var f = new Map(b); for (var g of a) { f.set(g[0], g[1]); } return f; } - if (b === Set) { - g = new Set(c); + if (c === Set) { + g = new Set(b); for (f of a.values()) { g.add(f); } @@ -39,9 +39,9 @@ function A(a, b, c) { } return a; } - return c; + return b; } - return "undefined" === d ? b : a; + return "undefined" === d ? c : a; } function B() { return Object.create(null); @@ -53,28 +53,28 @@ function I(a) { return "object" === typeof a; } function aa(a) { - const b = []; - for (const c of a.keys()) { - b.push(c); + const c = []; + for (const b of a.keys()) { + c.push(b); } - return b; + return c; } -function ba(a, b) { - if (E(b)) { - a = a[b]; +function ba(a, c) { + if (E(c)) { + a = a[c]; } else { - for (let c = 0; a && c < b.length; c++) { - a = a[b[c]]; + for (let b = 0; a && b < c.length; b++) { + a = a[c[b]]; } } return a; } function ca(a) { - let b = 0; - for (let c = 0, e; c < a.length; c++) { - (e = a[c]) && b < e.length && (b = e.length); + let c = 0; + for (let b = 0, e; b < a.length; b++) { + (e = a[b]) && c < e.length && (c = e.length); } - return b; + return c; } ;var da = [["\u00aa", "a"], ["\u00b2", "2"], ["\u00b3", "3"], ["\u00b9", "1"], ["\u00ba", "o"], ["\u00bc", "1\u20444"], ["\u00bd", "1\u20442"], ["\u00be", "3\u20444"], ["\u00e0", "a"], ["\u00e1", "a"], ["\u00e2", "a"], ["\u00e3", "a"], ["\u00e4", "a"], ["\u00e5", "a"], ["\u00e7", "c"], ["\u00e8", "e"], ["\u00e9", "e"], ["\u00ea", "e"], ["\u00eb", "e"], ["\u00ec", "i"], ["\u00ed", "i"], ["\u00ee", "i"], ["\u00ef", "i"], ["\u00f1", "n"], ["\u00f2", "o"], ["\u00f3", "o"], ["\u00f4", "o"], ["\u00f5", "o"], ["\u00f6", "o"], ["\u00f9", "u"], ["\u00fa", "u"], ["\u00fb", "u"], ["\u00fc", "u"], ["\u00fd", "y"], ["\u00ff", "y"], ["\u0101", "a"], ["\u0103", "a"], ["\u0105", "a"], ["\u0107", "c"], ["\u0109", "c"], ["\u010b", "c"], ["\u010d", "c"], ["\u010f", "d"], ["\u0113", "e"], ["\u0115", "e"], ["\u0117", "e"], ["\u0119", "e"], ["\u011b", "e"], ["\u011d", "g"], ["\u011f", "g"], ["\u0121", "g"], ["\u0123", "g"], ["\u0125", "h"], ["\u0129", "i"], ["\u012b", "i"], ["\u012d", "i"], ["\u012f", "i"], ["\u0133", @@ -97,30 +97,30 @@ function J(a = {}) { this.assign(a); } } -u = J.prototype; -u.assign = function(a) { +t = J.prototype; +t.assign = function(a) { this.normalize = A(a.normalize, !0, this.normalize); - let b = a.include, c = b || a.exclude || a.split, e; - if (c || "" === c) { - if ("object" === typeof c && c.constructor !== RegExp) { + let c = a.include, b = c || a.exclude || a.split, e; + if (b || "" === b) { + if ("object" === typeof b && b.constructor !== RegExp) { let d = ""; - e = !b; - b || (d += "\\p{Z}"); - c.letter && (d += "\\p{L}"); - c.number && (d += "\\p{N}", e = !!b); - c.symbol && (d += "\\p{S}"); - c.punctuation && (d += "\\p{P}"); - c.control && (d += "\\p{C}"); - if (c = c.char) { - d += "object" === typeof c ? c.join("") : c; + e = !c; + c || (d += "\\p{Z}"); + b.letter && (d += "\\p{L}"); + b.number && (d += "\\p{N}", e = !!c); + b.symbol && (d += "\\p{S}"); + b.punctuation && (d += "\\p{P}"); + b.control && (d += "\\p{C}"); + if (b = b.char) { + d += "object" === typeof b ? b.join("") : b; } try { - this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); + this.split = new RegExp("[" + (c ? "^" : "") + d + "]+", "u"); } catch (f) { - console.error("Your split configuration:", c, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; + console.error("Your split configuration:", b, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { - this.split = c, e = !1 === c || 2 > "a1a".split(c).length; + this.split = b, e = !1 === b || 2 > "a1a".split(b).length; } this.numeric = A(a.numeric, e); } else { @@ -134,17 +134,18 @@ u.assign = function(a) { this.prepare = A(a.prepare, null, this.prepare); this.finalize = A(a.finalize, null, this.finalize); ja || (this.mapper = new Map(da)); - this.rtl = A(a.rtl, !1, this.rtl); + b = a.filter; + this.filter = "function" === typeof b ? b : A(b && new Set(b), null, this.filter); this.dedupe = A(a.dedupe, !1, this.dedupe); - this.filter = A((c = a.filter) && new Set(c), null, this.filter); - this.matcher = A((c = a.matcher) && new Map(c), null, this.matcher); - this.mapper = A((c = a.mapper) && new Map(c), null, this.mapper); - this.stemmer = A((c = a.stemmer) && new Map(c), null, this.stemmer); + this.matcher = A((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = A((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = A((b = a.stemmer) && new Map(b), null, this.stemmer); this.replacer = A(a.replacer, null, this.replacer); this.minlength = A(a.minlength, 1, this.minlength); this.maxlength = A(a.maxlength, 0, this.maxlength); - if (this.cache = c = A(a.cache, !0, this.cache)) { - this.H = null, this.S = "number" === typeof c ? c : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; + this.rtl = A(a.rtl, !1, this.rtl); + if (this.cache = b = A(a.cache, !0, this.cache)) { + this.H = null, this.S = "number" === typeof b ? b : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; this.M = null; @@ -162,112 +163,111 @@ u.assign = function(a) { } return this; }; -u.addStemmer = function(a, b) { +t.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); - this.stemmer.set(a, b); + this.stemmer.set(a, c); this.A += (this.A ? "|" : "") + a; this.N = null; - this.cache && L(this); + this.cache && K(this); return this; }; -u.addFilter = function(a) { - this.filter || (this.filter = new Set()); - this.filter.add(a); - this.cache && L(this); +t.addFilter = function(a) { + "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); + this.cache && K(this); return this; }; -u.addMapper = function(a, b) { +t.addMapper = function(a, c) { if ("object" === typeof a) { - return this.addReplacer(a, b); + return this.addReplacer(a, c); } if (1 < a.length) { - return this.addMatcher(a, b); + return this.addMatcher(a, c); } this.mapper || (this.mapper = new Map()); - this.mapper.set(a, b); - this.cache && L(this); + this.mapper.set(a, c); + this.cache && K(this); return this; }; -u.addMatcher = function(a, b) { +t.addMatcher = function(a, c) { if ("object" === typeof a) { - return this.addReplacer(a, b); + return this.addReplacer(a, c); } if (2 > a.length && (this.dedupe || this.mapper)) { - return this.addMapper(a, b); + return this.addMapper(a, c); } this.matcher || (this.matcher = new Map()); - this.matcher.set(a, b); + this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && L(this); + this.cache && K(this); return this; }; -u.addReplacer = function(a, b) { +t.addReplacer = function(a, c) { if ("string" === typeof a) { - return this.addMatcher(a, b); + return this.addMatcher(a, c); } this.replacer || (this.replacer = []); - this.replacer.push(a, b); - this.cache && L(this); + this.replacer.push(a, c); + this.cache && K(this); return this; }; -u.encode = function(a) { +t.encode = function(a) { if (this.cache && a.length <= this.K) { if (this.H) { if (this.B.has(a)) { return this.B.get(a); } } else { - this.H = setTimeout(L, 50, this); + this.H = setTimeout(K, 50, this); } } this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (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 c = [], e = this.split || "" === this.split ? a.split(this.split) : a; - for (let f = 0, g, k; f < e.length; f++) { - if ((g = k = e[f]) && !(g.length < this.minlength)) { - if (b) { - c.push(g); + const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); + let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; + for (let f = 0, g, h; f < e.length; f++) { + if ((g = h = e[f]) && !(g.length < this.minlength)) { + if (c) { + b.push(g); } else { - if (!this.filter || !this.filter.has(g)) { + if (!this.filter || ("function" === typeof this.filter ? this.filter(g) : !this.filter.has(g))) { if (this.cache && g.length <= this.L) { if (this.H) { var d = this.G.get(g); if (d || "" === d) { - d && c.push(d); + d && b.push(d); continue; } } else { - this.H = setTimeout(L, 50, this); + this.H = setTimeout(K, 50, this); } } - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.N, h => this.stemmer.get(h)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), d = g, g = g.replace(this.N, k => this.stemmer.get(k)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let h = 0, l = "", n, m; h < g.length; h++) { - n = g.charAt(h), n === l && this.dedupe || ((m = this.mapper && this.mapper.get(n)) || "" === m ? m === l && this.dedupe || !(l = m) || (d += m) : d += l = n); + for (let k = 0, l = "", m, n; k < g.length; k++) { + m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); } g = d; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); if (g && this.replacer) { for (d = 0; g && d < this.replacer.length; d += 2) { g = g.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); - g && c.push(g); + this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); + g && b.push(g); } } } } - this.finalize && (c = this.finalize(c) || c); - this.cache && a.length <= this.K && (this.B.set(a, c), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); - return c; + this.finalize && (b = this.finalize(b) || b); + this.cache && a.length <= this.K && (this.B.set(a, b), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); + return b; }; -function L(a) { +function K(a) { a.H = null; a.B.clear(); a.G.clear(); @@ -275,32 +275,32 @@ function L(a) { ;let M, N; async function ka(a) { a = a.data; - var b = a.task; - const c = a.id; + var c = a.task; + const b = a.id; let e = a.args; - switch(b) { + switch(c) { case "init": N = a.options || {}; - (b = a.factory) ? (Function("return " + b)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); - postMessage({id:c}); + (c = a.factory) ? (Function("return " + c)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); + postMessage({id:b}); break; default: let d; - if ("export" === b) { + if ("export" === c) { if (!N.export || "function" !== typeof N.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } e[1] ? (e[0] = N.export, e[2] = 0, e[3] = 1) : e = null; } - if ("import" === b) { + if ("import" === c) { if (!N.import || "function" !== typeof N.import) { 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 N.import.call(M, e[0]), M.import(e[0], a)); } else { - (d = e && M[b].apply(M, e)) && d.then && (d = await d); + (d = e && M[c].apply(M, e)) && d.then && (d = await d); } - postMessage("search" === b ? {id:c, msg:d} : {id:c}); + postMessage("search" === c ? {id:b, msg:d} : {id:b}); } } ;function la(a) { @@ -316,47 +316,47 @@ function qa() { } function ma(a) { this[a + "Async"] = function() { - const b = arguments; - var c = b[b.length - 1]; + const c = arguments; + var b = c[c.length - 1]; let e; - "function" === typeof c && (e = c, delete b[b.length - 1]); + "function" === typeof b && (e = b, delete c[c.length - 1]); na ? pa || (pa = Date.now() - oa >= this.priority * this.priority * 3) : (na = setTimeout(qa, 0), oa = Date.now()); if (pa) { const f = this; return new Promise(g => { setTimeout(function() { - g(f[a + "Async"].apply(f, b)); + g(f[a + "Async"].apply(f, c)); }, 0); }); } - const d = this[a].apply(this, b); - c = d.then ? d : new Promise(f => f(d)); - e && c.then(e); - return c; + const d = this[a].apply(this, c); + b = d.then ? d : new Promise(f => f(d)); + e && b.then(e); + return b; }; } ;let P = 0; function Q(a = {}) { - function b(g) { - function k(h) { - h = h.data || h; - const l = h.id, n = l && d.h[l]; - n && (n(h.msg), delete d.h[l]); + function c(g) { + function h(k) { + k = k.data || k; + const l = k.id, m = l && d.h[l]; + m && (m(k.msg), delete d.h[l]); } this.worker = g; this.h = B(); if (this.worker) { - e ? this.worker.on("message", k) : this.worker.onmessage = k; + e ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { - return new Promise(function(h) { + return new Promise(function(k) { d.h[++P] = function() { - h(d); + k(d); 1e9 < P && (P = 0); }; - d.worker.postMessage({id:P, task:"init", factory:c, options:a}); + d.worker.postMessage({id:P, task:"init", factory:b, options:a}); }); } - this.worker.postMessage({task:"init", factory:c, options:a}); + this.worker.postMessage({task:"init", factory:b, options:a}); this.priority = a.priority || 4; return this; } @@ -364,12 +364,12 @@ function Q(a = {}) { if (!this || this.constructor !== Q) { return new Q(a); } - let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; - c && (c = c.toString()); - const e = "undefined" === typeof window, d = this, f = ra(c, e, a.worker); + let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + b && (b = b.toString()); + const e = "undefined" === typeof window, d = this, f = ra(b, e, a.worker); return f.then ? f.then(function(g) { - return b.call(d, g); - }) : b.call(this, f); + return c.call(d, g); + }) : c.call(this, f); } R("add"); R("append"); @@ -382,141 +382,161 @@ R("import"); la(Q.prototype); function R(a) { Q.prototype[a] = function() { - const b = this, c = [].slice.call(arguments); - var e = c[c.length - 1]; + const c = this, b = [].slice.call(arguments); + var e = b[b.length - 1]; let d; - "function" === typeof e && (d = e, c.pop()); + "function" === typeof e && (d = e, b.pop()); e = new Promise(function(f) { - "export" === a && "function" === typeof c[0] && (c[0] = null); - b.h[++P] = f; - b.worker.postMessage({task:a, id:P, args:c}); + "export" === a && "function" === typeof b[0] && (b[0] = null); + c.h[++P] = f; + c.worker.postMessage({task:a, id:P, args:b}); }); return d ? (e.then(d), this) : e; }; } -function ra(a, b, c) { - return b ? "undefined" !== typeof module ? 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=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof c ? c : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function ra(a, c, b) { + return c ? "undefined" !== typeof module ? 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=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;function sa(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 5000 | 0); +;function sa(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 5000 | 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 ta(a, b) { - b || (b = new Map()); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b.set(e[0], e[1]); + e.push(d), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } -function ua(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 1000 | 0); - for (const d of a.entries()) { - e.push([d[0], sa(d[1])[0]]), e.length === b && (c.push(e), e = []); +function ta(a, c) { + c || (c = new Map()); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c.set(e[0], e[1]); } - e.length && c.push(e); return c; } -function va(a, b) { - b || (b = new Map()); - for (let c = 0, e, d; c < a.length; c++) { - e = a[c], d = b.get(e[0]), b.set(e[0], ta(e[1], d)); +function ua(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 1000 | 0); + for (const d of a.entries()) { + e.push([d[0], sa(d[1])[0]]), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } +function va(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], ta(e[1], d)); + } + return c; +} function wa(a) { - let b = [], c = []; + let c = [], b = []; for (const e of a.keys()) { - c.push(e), 250000 === c.length && (b.push(c), c = []); + b.push(e), 250000 === b.length && (c.push(b), b = []); } - c.length && b.push(c); - return b; + b.length && c.push(b); + return c; } -function xa(a, b) { - b || (b = new Set()); - for (let c = 0; c < a.length; c++) { - b.add(a[c]); +function xa(a, c) { + c || (c = new Set()); + for (let b = 0; b < a.length; b++) { + c.add(a[b]); } - return b; + return c; } -function ya(a, b, c, e, d, f, g = 0) { - const k = e && e.constructor === Array; - var h = k ? e.shift() : e; - if (!h) { - return this.export(a, b, d, f + 1); +function ya(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((b ? b + "." : "") + (g + 1) + "." + c, 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 ya.call(l, a, b, c, k ? e : null, d, f, g + 1); + return k.then(function() { + return ya.call(l, a, c, b, h ? e : null, d, f, g + 1); }); } - return ya.call(this, a, b, c, k ? e : null, d, f, g + 1); + return ya.call(this, a, c, b, h ? e : null, d, f, g + 1); } -;function za(a, b, c, e) { +function za(a, c) { + let b = ""; + for (const e of a.entries()) { + a = e[0]; + const d = e[1]; + let f = ""; + for (let g = 0, h; g < d.length; g++) { + h = d[g] || [""]; + let k = ""; + for (let l = 0; l < h.length; l++) { + k += (k ? "," : "") + ("string" === c ? '"' + h[l] + '"' : h[l]); + } + k = "[" + k + "]"; + f += (f ? "," : "") + k; + } + f = '["' + a + '",[' + f + "]]"; + b += (b ? "," : "") + f; + } + return b; +} +;function Aa(a, c, b, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { - if (g = a.index[f], b >= g.length) { - b -= g.length; + if (g = a.index[f], c >= g.length) { + c -= g.length; } else { - b = g[e ? "splice" : "slice"](b, c); - const k = b.length; - if (k && (d = d.length ? d.concat(b) : b, c -= k, e && (a.length -= k), !c)) { + 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; } - b = 0; + c = 0; } } return d; } function S(a) { - if (!this) { + if (!this || this.constructor !== S) { return new S(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; - const b = this; - return new Proxy([], {get(c, e) { + const c = this; + return new Proxy([], {get(b, e) { if ("length" === e) { - return b.length; + return c.length; } if ("push" === e) { return function(d) { - b.index[b.index.length - 1].push(d); - b.length++; + c.index[c.index.length - 1].push(d); + c.length++; }; } if ("pop" === e) { return function() { - if (b.length) { - return b.length--, b.index[b.index.length - 1].pop(); + if (c.length) { + return c.length--, c.index[c.index.length - 1].pop(); } }; } if ("indexOf" === e) { return function(d) { let f = 0; - for (let g = 0, k, h; g < b.index.length; g++) { - k = b.index[g]; - h = k.indexOf(d); - if (0 <= h) { - return f + h; + for (let g = 0, h, k; g < c.index.length; g++) { + h = c.index[g]; + k = h.indexOf(d); + if (0 <= k) { + return f + k; } - f += k.length; + f += h.length; } return -1; }; } if ("includes" === e) { return function(d) { - for (let f = 0; f < b.index.length; f++) { - if (b.index[f].includes(d)) { + for (let f = 0; f < c.index.length; f++) { + if (c.index[f].includes(d)) { return !0; } } @@ -525,24 +545,24 @@ function S(a) { } if ("slice" === e) { return function(d, f) { - return za(b, d || 0, f || b.length, !1); + return Aa(c, d || 0, f || c.length, !1); }; } if ("splice" === e) { return function(d, f) { - return za(b, d || 0, f || b.length, !0); + return Aa(c, d || 0, f || c.length, !0); }; } if ("constructor" === e) { return Array; } if ("symbol" !== typeof e) { - return (c = b.index[e / 2 ** 31 | 0]) && c[e]; + return (b = c.index[e / 2 ** 31 | 0]) && b[e]; } - }, set(c, e, d) { - c = e / 2 ** 31 | 0; - (b.index[c] || (b.index[c] = []))[e] = d; - b.length++; + }, set(b, e, d) { + b = e / 2 ** 31 | 0; + (c.index[b] || (c.index[b] = []))[e] = d; + c.length++; return !0; }}); } @@ -555,113 +575,114 @@ S.prototype.destroy = function() { S.prototype.push = function() { }; function T(a = 8) { - if (!this) { + if (!this || this.constructor !== T) { return new T(a); } this.index = B(); - this.B = []; + this.h = []; this.size = 0; - 32 < a ? (this.h = Aa, this.A = BigInt(a)) : (this.h = Ba, this.A = a); + 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); } T.prototype.get = function(a) { - const b = this.index[this.h(a)]; - return b && b.get(a); + const c = this.index[this.B(a)]; + return c && c.get(a); }; -T.prototype.set = function(a, b) { - var c = this.h(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.B.push(e)); +T.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 U(a = 8) { - if (!this) { + if (!this || this.constructor !== U) { return new U(a); } this.index = B(); this.h = []; - 32 < a ? (this.B = Aa, this.A = BigInt(a)) : (this.B = Ba, this.A = a); + this.size = 0; + 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); } U.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)); + 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++); }; -u = T.prototype; -u.has = U.prototype.has = function(a) { - const b = this.index[this.B(a)]; - return b && b.has(a); +t = T.prototype; +t.has = U.prototype.has = function(a) { + const c = this.index[this.B(a)]; + return c && c.has(a); }; -u.delete = U.prototype.delete = function(a) { - const b = this.index[this.B(a)]; - b && b.delete(a) && this.size--; +t.delete = U.prototype.delete = function(a) { + const c = this.index[this.B(a)]; + c && c.delete(a) && this.size--; }; -u.clear = U.prototype.clear = function() { +t.clear = U.prototype.clear = function() { this.index = B(); this.h = []; this.size = 0; }; -u.values = U.prototype.values = function*() { +t.values = U.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { - for (let b of this.h[a].values()) { - yield b; + for (let c of this.h[a].values()) { + yield c; } } }; -u.keys = U.prototype.keys = function*() { +t.keys = U.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { - for (let b of this.h[a].keys()) { - yield b; + for (let c of this.h[a].keys()) { + yield c; } } }; -u.entries = U.prototype.entries = function*() { +t.entries = U.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { - for (let b of this.h[a].entries()) { - yield b; + for (let c of this.h[a].entries()) { + yield c; } } }; -function Ba(a) { - let b = 2 ** this.A - 1; +function Ca(a) { + let c = 2 ** this.A - 1; if ("number" == typeof a) { - return a & b; + return a & c; } - let c = 0, e = this.A + 1; + let b = 0, e = this.A + 1; for (let d = 0; d < a.length; d++) { - c = (c * e ^ a.charCodeAt(d)) & b; + b = (b * e ^ a.charCodeAt(d)) & c; } - return 32 === this.A ? c + 2 ** 31 : c; + return 32 === this.A ? b + 2 ** 31 : b; } -function Aa(a) { - let b = BigInt(2) ** this.A - BigInt(1); - var c = typeof a; - if ("bigint" === c) { - return a & b; +function Ba(a) { + let c = BigInt(2) ** this.A - BigInt(1); + var b = typeof a; + if ("bigint" === b) { + return a & c; } - if ("number" === c) { - return BigInt(a) & b; + if ("number" === b) { + return BigInt(a) & c; } - c = BigInt(0); + b = BigInt(0); let e = this.A + BigInt(1); for (let d = 0; d < a.length; d++) { - c = (c * e ^ BigInt(a.charCodeAt(d))) & b; + b = (b * e ^ BigInt(a.charCodeAt(d))) & c; } - return c; + return b; } -;V.prototype.add = function(a, b, c) { - I(a) && (b = a, a = ba(b, this.key)); - if (b && (a || 0 === a)) { - if (!c && this.reg.has(a)) { - return this.update(a, b); +;V.prototype.add = function(a, c, b) { + I(a) && (c = a, a = ba(c, this.key)); + if (c && (a || 0 === a)) { + if (!b && this.reg.has(a)) { + return this.update(a, c); } - for (let k = 0, h; k < this.field.length; k++) { - h = this.D[k]; - var e = this.index.get(this.field[k]); - if ("function" === typeof h) { - var d = h(b); + for (let h = 0, k; h < this.field.length; h++) { + k = this.D[h]; + var e = this.index.get(this.field[h]); + if ("function" === typeof k) { + var d = k(c); d && e.add(a, d, !1, !0); } else { - if (d = h.I, !d || d(b)) { - h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), Ca(b, h, this.J, 0, e, a, h[0], c); + if (d = k.I, !d || d(c)) { + k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), Da(c, k, this.J, 0, e, a, k[0], b); } } } @@ -669,34 +690,34 @@ function Aa(a) { for (e = 0; e < this.F.length; e++) { var f = this.F[e], g = this.R[e]; d = this.tag.get(g); - let k = B(); + let h = B(); if ("function" === typeof f) { - if (f = f(b), !f) { + if (f = f(c), !f) { continue; } } else { - const h = f.I; - if (h && !h(b)) { + const k = f.I; + if (k && !k(c)) { continue; } f.constructor === String && (f = "" + f); - f = ba(b, f); + f = ba(c, f); } if (d && f) { E(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 = []), !c || !n.includes(a))) { - if (n.length === 2 ** 31 - 1) { - g = new S(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 S(m); if (this.fastupdate) { - for (let m of this.reg.values()) { - m.includes(n) && (m[m.indexOf(n)] = g); + for (let n of this.reg.values()) { + n.includes(m) && (n[n.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 { @@ -704,138 +725,147 @@ function Aa(a) { } } } - if (this.store && (!c || !this.store.has(a))) { - let k; + if (this.store && (!b || !this.store.has(a))) { + let h; if (this.C) { - k = B(); - for (let h = 0, l; h < this.C.length; h++) { - l = this.C[h]; - if ((c = l.I) && !c(b)) { + h = B(); + for (let k = 0, l; k < this.C.length; k++) { + l = this.C[k]; + if ((b = l.I) && !b(c)) { continue; } - let n; + let m; if ("function" === typeof l) { - n = l(b); - if (!n) { + m = l(c); + if (!m) { continue; } l = [l.V]; } else if (E(l) || l.constructor === String) { - k[l] = b[l]; + h[l] = c[l]; continue; } - Da(b, k, l, 0, l[0], n); + Ea(c, h, l, 0, l[0], m); } } - this.store.set(a, k || b); + this.store.set(a, h || c); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Da(a, b, c, e, d, f) { +function Ea(a, c, b, e, d, f) { a = a[d]; - if (e === c.length - 1) { - b[d] = f || a; + if (e === b.length - 1) { + c[d] = f || a; } else if (a) { if (a.constructor === Array) { - for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { - Da(a, b, c, e, d); + for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { + Ea(a, c, b, e, d); } } else { - b = b[d] || (b[d] = B()), d = c[++e], Da(a, b, c, e, d); + c = c[d] || (c[d] = B()), d = b[++e], Ea(a, c, b, e, d); } } } -function Ca(a, b, c, e, d, f, g, k) { +function Da(a, c, b, e, d, f, g, h) { if (a = a[g]) { - if (e === b.length - 1) { + if (e === c.length - 1) { if (a.constructor === Array) { - if (c[e]) { - for (b = 0; b < a.length; b++) { - d.add(f, a[b], !0, !0); + if (b[e]) { + for (c = 0; c < a.length; c++) { + d.add(f, a[c], !0, !0); } return; } a = a.join(" "); } - d.add(f, a, k, !0); + d.add(f, a, h, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Ca(a, b, c, e, d, f, g, k); + Da(a, c, b, e, d, f, g, h); } } else { - g = b[++e], Ca(a, b, c, e, d, f, g, k); + g = c[++e], Da(a, c, b, e, d, f, g, h); } } } else { d.db && d.remove(f); } } -;function Ea(a, b, c, e, d, f, g) { - const k = a.length; - let h = [], l; - var n; +;function Fa(a, c, b, e, d, f, g) { + const h = a.length; + let k = [], l, m; l = B(); - for (let m = 0, q, p, t, r; m < b; m++) { - for (let v = 0; v < k; v++) { - if (t = a[v], m < t.length && (q = t[m])) { + for (let n = 0, q, r, p, v; n < c; n++) { + for (let u = 0; u < h; u++) { + if (p = a[u], n < p.length && (q = p[n])) { for (let x = 0; x < q.length; x++) { - p = q[x], (n = l[p]) ? l[p]++ : (n = 0, l[p] = 1), r = h[n] || (h[n] = []), g || (n = m + (v || !d ? 0 : f || 0), r = r[n] || (r[n] = [])), r.push(p); + r = q[x]; + (m = l[r]) ? l[r]++ : (m = 0, l[r] = 1); + v = k[m] || (k[m] = []); + if (!g) { + let y = n + (u || !d ? 0 : f || 0); + v = v[y] || (v[y] = []); + } + v.push(r); + if (g && b && m === h - 1 && v.length - e === b) { + return v; + } } } } } - if (a = h.length) { + if (a = k.length) { if (d) { - h = 1 < h.length ? Fa(h, c, e, g, f) : (h = h[0]).length > c || e ? h.slice(e, c + e) : h; + k = 1 < k.length ? Ga(k, b, e, g, f) : (k = k[0]).length > b || e ? k.slice(e, b + e) : k; } else { - if (a < k) { + if (a < h) { return []; } - h = h[a - 1]; - if (c || e) { + k = k[a - 1]; + if (b || e) { if (g) { - if (h.length > c || e) { - h = h.slice(e, c + e); + if (k.length > b || e) { + k = k.slice(e, b + e); } } else { d = []; - for (let m = 0, q; m < h.length; m++) { - if (q = h[m], q.length > e) { + for (let n = 0, q; n < k.length; n++) { + if (q = k[n], q.length > e) { e -= q.length; } else { - if (q.length > c || e) { - q = q.slice(e, c + e), c -= q.length, e && (e -= q.length); + if (q.length > b || e) { + q = q.slice(e, b + e), b -= q.length, e && (e -= q.length); } d.push(q); - if (!c) { + if (!b) { break; } } } - h = 1 < d.length ? [].concat.apply([], d) : d[0]; + k = 1 < d.length ? [].concat.apply([], d) : d[0]; } } } } - return h; + return k; } -function Fa(a, b, c, e, d) { +function Ga(a, c, b, e, d) { const f = [], g = B(); - let k; - var h = a.length; + let h; + var k = a.length; let l; if (e) { - for (d = h - 1; 0 <= d; d--) { + for (d = k - 1; 0 <= d; d--) { if (l = (e = a[d]) && e.length) { - for (h = 0; h < l; h++) { - if (k = e[h], !g[k]) { - if (g[k] = 1, c) { - c--; + 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 === b) { + if (f.push(h), f.length === c) { return f; } } @@ -844,18 +874,18 @@ function Fa(a, b, c, e, d) { } } } else { - for (let n = h - 1, m, q = 0; 0 <= n; n--) { - m = a[n]; - for (let p = 0; p < m.length; p++) { - if (l = (e = m[p]) && e.length) { - for (let t = 0; t < l; t++) { - if (k = e[t], !g[k]) { - if (g[k] = 1, c) { - c--; + for (let m = k - 1, n, q = 0; 0 <= m; m--) { + n = a[m]; + for (let r = 0; r < n.length; r++) { + if (l = (e = n[r]) && e.length) { + for (let p = 0; p < l; p++) { + if (h = e[p], !g[h]) { + if (g[h] = 1, b) { + b--; } else { - let r = (p + (n < h - 1 ? d || 0 : 0)) / (n + 1) | 0; - (f[r] || (f[r] = [])).push(k); - if (++q === b) { + let v = (r + (m < k - 1 ? d || 0 : 0)) / (m + 1) | 0; + (f[v] || (f[v] = [])).push(h); + if (++q === c) { return f; } } @@ -867,51 +897,51 @@ function Fa(a, b, c, e, d) { } return f; } -function Ga(a, b, c) { +function Ha(a, c, b) { const e = B(), d = []; - for (let f = 0, g; f < b.length; f++) { - g = b[f]; - for (let k = 0; k < g.length; k++) { - e[g[k]] = 1; + for (let f = 0, g; f < c.length; f++) { + g = c[f]; + for (let h = 0; h < g.length; h++) { + e[g[h]] = 1; } } - if (c) { + if (b) { for (let f = 0, g; f < a.length; f++) { g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { - for (let f = 0, g, k; f < a.result.length; f++) { - for (g = a.result[f], b = 0; b < g.length; b++) { - k = g[b], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); + for (let f = 0, g, h; f < a.result.length; f++) { + for (g = a.result[f], c = 0; c < g.length; c++) { + h = g[c], e[h] && ((d[f] || (d[f] = [])).push(h), e[h] = 0); } } } return d; } -;function Ha(a, b, c, e) { +;function Ia(a, c, b, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, e ? W.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; } let d = []; - for (let f = 0, g, k; f < a.length; f++) { - if ((g = a[f]) && (k = g.length)) { - if (c) { - if (c >= k) { - c -= k; + for (let f = 0, g, h; f < a.length; f++) { + if ((g = a[f]) && (h = g.length)) { + if (b) { + if (b >= h) { + b -= h; continue; } - c < k && (g = b ? g.slice(c, c + b) : g.slice(c), k = g.length, c = 0); + b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); } - k > b && (g = g.slice(0, b), k = b); - if (!d.length && k >= b) { + h > c && (g = g.slice(0, c), h = c); + if (!d.length && h >= c) { return e ? W.call(this, g) : g; } d.push(g); - b -= k; - if (!b) { + c -= h; + if (!c) { break; } } @@ -919,36 +949,36 @@ function Ga(a, b, c) { d = 1 < d.length ? [].concat.apply([], d) : d[0]; return e ? W.call(this, d) : d; } -;function Ia(a, b, c) { - var e = c[0]; +;function Ja(a, c, b) { + var e = b[0]; if (e.then) { - return Promise.all(c).then(function(n) { - return a[b].apply(a, n); + return Promise.all(b).then(function(m) { + return a[c].apply(a, m); }); } if (e[0] && e[0].index) { - return a[b].apply(a, e); + return a[c].apply(a, e); } e = []; - let d = [], f = 0, g = 0, k, h, l; - for (let n = 0, m; n < c.length; n++) { - if (m = c[n]) { + let d = [], f = 0, g = 0, h, k, l; + for (let m = 0, n; m < b.length; m++) { + if (n = b[m]) { let q; - if (m.constructor === X) { - q = m.result; - } else if (m.constructor === Array) { - q = m; + if (n.constructor === X) { + q = n.result; + } else if (n.constructor === Array) { + q = n; } else { - if (f = m.limit || 0, g = m.offset || 0, l = m.suggest, h = m.resolve, k = m.enrich && h, m.index) { - m.resolve = !1, m.enrich = !1, q = m.index.search(m).result, m.resolve = h, m.enrich = k; - } else if (m.and) { - q = a.and(m.and); - } else if (m.or) { - q = a.or(m.or); - } else if (m.xor) { - q = a.xor(m.xor); - } else if (m.not) { - q = a.not(m.not); + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { + n.resolve = !1, n.enrich = !1, q = n.index.search(n).result, n.resolve = k, n.enrich = h; + } else if (n.and) { + q = a.and(n.and); + } else if (n.or) { + q = a.or(n.or); + } else if (n.xor) { + q = a.xor(n.xor); + } else if (n.not) { + q = a.not(n.not); } else { continue; } @@ -956,129 +986,129 @@ function Ga(a, b, c) { if (q.then) { d.push(q); } else if (q.length) { - e[n] = q; - } else if (!l && ("and" === b || "xor" === b)) { + e[m] = q; + } else if (!l && ("and" === c || "xor" === c)) { e = []; break; } } } - return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; } ;X.prototype.or = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f} = Ia(this, "or", arguments); - return Ja.call(this, a, b, c, e, d, f); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ja(this, "or", arguments); + return Ka.call(this, a, c, b, e, d, f); }; -function Ja(a, b, c, e, d, f) { - if (b.length) { +function Ka(a, c, b, e, d, f) { + if (c.length) { const g = this; - return Promise.all(b).then(function(k) { + return Promise.all(c).then(function(h) { a = []; - for (let h = 0, l; h < k.length; h++) { - (l = k[h]).length && (a[h] = l); + for (let k = 0, l; k < h.length; k++) { + (l = h[k]).length && (a[k] = l); } - return Ja.call(g, a, [], c, e, d, f); + return Ka.call(g, a, [], b, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Fa(a, c, e, !1, this.h), e = 0)); - return f ? this.resolve(c, e, d) : this; + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ga(a, b, e, !1, this.h), e = 0)); + return f ? this.resolve(b, e, d) : this; } ;X.prototype.and = function() { - let a = this.result.length, b, c, e, d; + let a = this.result.length, c, b, e, d; if (!a) { const f = arguments[0]; - f && (a = !!f.suggest, d = f.resolve, b = f.limit, c = f.offset, e = f.enrich && d); + f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:n, suggest:m} = Ia(this, "and", arguments); - return Ka.call(this, f, g, k, h, l, n, m); + const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ja(this, "and", arguments); + return La.call(this, f, g, h, k, l, m, n); } - return d ? this.resolve(b, c, e) : this; + return d ? this.resolve(c, b, e) : this; }; -function Ka(a, b, c, e, d, f, g) { - if (b.length) { - const k = this; - return Promise.all(b).then(function(h) { +function La(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, n; l < h.length; l++) { - (n = h[l]).length && (a[l] = n); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return Ka.call(k, a, [], c, e, d, f, g); + return La.call(h, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - if (b = ca(a)) { - return this.result = Ea(a, b, c, e, g, this.h, f), f ? d ? W.call(this.index, this.result) : this.result : this; + if (c = ca(a)) { + return this.result = Fa(a, c, b, e, g, this.h, f), f ? d ? W.call(this.index, this.result) : this.result : this; } this.result = []; } } else { g || (this.result = a); } - return f ? this.resolve(c, e, d) : this; + return f ? this.resolve(b, e, d) : this; } ;X.prototype.xor = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ia(this, "xor", arguments); - return La.call(this, a, b, c, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "xor", arguments); + return Ma.call(this, a, c, b, e, d, f, g); }; -function La(a, b, c, e, d, f, g) { - if (b.length) { - const k = this; - return Promise.all(b).then(function(h) { +function Ma(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, n; l < h.length; l++) { - (n = h[l]).length && (a[l] = n); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return La.call(k, a, [], c, e, d, f, g); + return Ma.call(h, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = Ma.call(this, a, c, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Na.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } - return f ? this.resolve(c, e, d) : this; + return f ? this.resolve(b, e, d) : this; } -function Ma(a, b, c, e, d) { +function Na(a, c, b, e, d) { const f = [], g = B(); - let k = 0; - for (let h = 0, l; h < a.length; h++) { - if (l = a[h]) { - k < l.length && (k = l.length); - for (let n = 0, m; n < l.length; n++) { - if (m = l[n]) { - for (let q = 0, p; q < m.length; q++) { - p = m[q], g[p] = g[p] ? 2 : 1; + let h = 0; + for (let k = 0, l; k < a.length; k++) { + if (l = a[k]) { + h < l.length && (h = l.length); + for (let m = 0, n; m < l.length; m++) { + if (n = l[m]) { + for (let q = 0, r; q < n.length; q++) { + r = n[q], g[r] = g[r] ? 2 : 1; } } } } } - for (let h = 0, l, n = 0; h < k; h++) { - for (let m = 0, q; m < a.length; m++) { - if (q = a[m]) { - if (l = q[h]) { - for (let p = 0, t; p < l.length; p++) { - if (t = l[p], 1 === g[t]) { - if (c) { - c--; + for (let k = 0, l, m = 0; k < h; k++) { + for (let n = 0, q; n < a.length; n++) { + if (q = a[n]) { + if (l = q[k]) { + for (let r = 0, p; r < l.length; r++) { + if (p = l[r], 1 === g[p]) { + if (b) { + b--; } else { if (e) { - if (f.push(t), f.length === b) { + if (f.push(p), f.length === c) { return f; } } else { - const r = h + (m ? d : 0); - f[r] || (f[r] = []); - f[r].push(t); - if (++n === b) { + const v = k + (n ? d : 0); + f[v] || (f[v] = []); + f[v].push(p); + if (++m === c) { return f; } } @@ -1092,43 +1122,43 @@ function Ma(a, b, c, e, d) { return f; } ;X.prototype.not = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ia(this, "not", arguments); - return Na.call(this, a, b, c, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "not", arguments); + return Oa.call(this, a, c, b, e, d, f, g); }; -function Na(a, b, c, e, d, f, g) { - if (b.length) { - const k = this; - return Promise.all(b).then(function(h) { +function Oa(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, n; l < h.length; l++) { - (n = h[l]).length && (a[l] = n); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return Na.call(k, a, [], c, e, d, f, g); + return Oa.call(h, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Oa.call(this, a, c, e, f); + this.result = Pa.call(this, a, b, e, f); } else if (f) { - return this.resolve(c, e, d); + return this.resolve(b, e, d); } return f ? d ? W.call(this.index, this.result) : this.result : this; } -function Oa(a, b, c, e) { +function Pa(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, k = 0; f < this.result.length; f++) { + for (let f = 0, g, h = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let h = 0, l; h < g.length; h++) { - if (l = g[h], !a.has(l)) { - if (c) { - c--; + for (let k = 0, l; k < g.length; k++) { + if (l = g[k], !a.has(l)) { + if (b) { + b--; } else { if (e) { - if (d.push(l), d.length === b) { + if (d.push(l), d.length === c) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++k === b) { + if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { return d; } } @@ -1152,32 +1182,32 @@ function Oa(a, b, c, e) { } X.prototype.limit = function(a) { if (this.result.length) { - const b = []; - for (let c = 0, e; c < this.result.length; c++) { - if (e = this.result[c]) { + const c = []; + for (let b = 0, e; b < this.result.length; b++) { + if (e = this.result[b]) { if (e.length <= a) { - if (b[c] = e, a -= e.length, !a) { + if (c[b] = e, a -= e.length, !a) { break; } } else { - b[c] = e.slice(0, a); + c[b] = e.slice(0, a); break; } } } - this.result = b; + this.result = c; } return this; }; X.prototype.offset = function(a) { if (this.result.length) { - const b = []; - for (let c = 0, e; c < this.result.length; c++) { - if (e = this.result[c]) { - e.length <= a ? a -= e.length : (b[c] = e.slice(a), a = 0); + const c = []; + for (let b = 0, e; b < this.result.length; b++) { + if (e = this.result[b]) { + e.length <= a ? a -= e.length : (c[b] = e.slice(a), a = 0); } } - this.result = b; + this.result = c; } return this; }; @@ -1185,46 +1215,46 @@ X.prototype.boost = function(a) { this.h += a; return this; }; -X.prototype.resolve = function(a, b, c) { +X.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Ha.call(d, e, a || 100, b, c)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Ia.call(d, e, a || 100, c, b)) : e; }; B(); -V.prototype.search = function(a, b, c, e) { - c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); +V.prototype.search = function(a, c, b, e) { + b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); let d = [], f = [], g; + var h; let k; - let h; - let l, n = 0; - var m = !0; - let q; - if (c) { - c.constructor === Array && (c = {index:c}); - a = c.query || a; - g = c.pluck; - k = c.merge; - h = g || c.field || (h = c.index) && (h.index ? null : h); - var p = this.tag && c.tag; - var t = c.suggest; - m = !1 !== c.resolve; - if (!m && !g) { - if (h = h || this.field) { - E(h) ? g = h : (h.constructor === Array && 1 === h.length && (h = h[0]), g = h.field || h.index); + let l; + let m, n = 0; + var q = !0; + let r; + if (b) { + b.constructor === Array && (b = {index:b}); + a = b.query || a; + g = b.pluck; + k = b.merge; + l = g || b.field || (l = b.index) && (l.index ? null : l); + var p = this.tag && b.tag; + var v = b.suggest; + q = !1 !== b.resolve; + if (!q && !g) { + if (l = l || this.field) { + E(l) ? g = l : (l.constructor === Array && 1 === l.length && (l = l[0]), g = l.field || l.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."); } } - this.store && c.enrich && !m && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - var r = this.store && c.enrich && m; - q = c.highlight && r; - b = c.limit || b; - l = c.offset || 0; - b || (b = 100); + this.store && b.enrich && !q && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + r = (h = this.store && b.enrich && q) && b.highlight; + c = b.limit || c; + m = b.offset || 0; + c || (c = 100); if (p && (!this.db || !e)) { p.constructor !== Array && (p = [p]); - var v = []; + var u = []; for (let z = 0, w; z < p.length; z++) { w = p[z]; if (E(w)) { @@ -1234,46 +1264,46 @@ V.prototype.search = function(a, b, c, e) { var x = w.tag; if (x.constructor === Array) { for (var y = 0; y < x.length; y++) { - v.push(w.field, x[y]); + u.push(w.field, x[y]); } } else { - v.push(w.field, x); + u.push(w.field, x); } } else { x = Object.keys(w); for (let D = 0, H, C; D < x.length; D++) { if (H = x[D], C = w[H], C.constructor === Array) { for (y = 0; y < C.length; y++) { - v.push(H, C[y]); + u.push(H, C[y]); } } else { - v.push(H, C); + u.push(H, C); } } } } - if (!v.length) { + if (!u.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - p = v; + p = u; if (!a) { - t = []; - if (v.length) { - for (p = 0; p < v.length; p += 2) { + v = []; + if (u.length) { + for (p = 0; p < u.length; p += 2) { if (this.db) { - m = this.index.get(v[p]); - if (!m) { - console.warn("Tag '" + v[p] + ":" + v[p + 1] + "' will be skipped because there is no field '" + v[p] + "'."); + q = this.index.get(u[p]); + if (!q) { + console.warn("Tag '" + u[p] + ":" + u[p + 1] + "' will be skipped because there is no field '" + u[p] + "'."); continue; } - t.push(m = m.db.tag(v[p + 1], b, l, r)); + v.push(q = q.db.tag(u[p + 1], c, m, h)); } else { - m = Pa.call(this, v[p], v[p + 1], b, l, r); + q = Qa.call(this, u[p], u[p + 1], c, m, h); } - d.push({field:v[p], tag:v[p + 1], result:m}); + d.push({field:u[p], tag:u[p + 1], result:q}); } } - return t.length ? Promise.all(t).then(function(z) { + return v.length ? Promise.all(v).then(function(z) { for (let w = 0; w < z.length; w++) { d[w].result = z[w]; } @@ -1281,142 +1311,143 @@ V.prototype.search = function(a, b, c, e) { }) : d; } } - h && h.constructor !== Array && (h = [h]); + l && l.constructor !== Array && (l = [l]); } - h || (h = this.field); - v = !e && (this.worker || this.db) && []; + l || (l = this.field); + u = !e && (this.worker || this.db) && []; let F; - for (let z = 0, w, D, H; z < h.length; z++) { - D = h[z]; + for (let z = 0, w, D, H; z < l.length; z++) { + D = l[z]; if (this.db && this.tag && !this.D[z]) { continue; } let C; - E(D) || (C = D, D = C.field, a = C.query || a, b = C.limit || b, l = C.offset || l, t = C.suggest || t, r = this.store && (C.enrich || r)); + E(D) || (C = D, D = C.field, a = C.query || a, c = C.limit || c, m = C.offset || m, v = C.suggest || v, h = this.store && (C.enrich || h)); if (e) { w = e[z]; } else { - if (x = C || c, y = this.index.get(D), p && (this.db && (x.tag = p, F = y.db.support_tag_search, x.field = h), F || (x.enrich = !1)), v) { - v[z] = y.search(a, b, x); - x && r && (x.enrich = r); + if (x = C || b, y = this.index.get(D), p && (this.db && (x.tag = p, F = y.db.support_tag_search, x.field = l), F || (x.enrich = !1)), u) { + u[z] = y.search(a, c, x); + x && h && (x.enrich = h); continue; } else { - w = y.search(a, b, x), x && r && (x.enrich = r); + w = y.search(a, c, x), x && h && (x.enrich = h); } } - H = w && (m ? w.length : w.result.length); + H = w && (q ? w.length : w.result.length); if (p && H) { x = []; y = 0; if (this.db && e) { if (!F) { - for (let G = h.length; G < e.length; G++) { - let K = e[G]; - if (K && K.length) { - y++, x.push(K); - } else if (!t) { - return m ? d : new X(d); + for (let G = l.length; G < e.length; G++) { + let L = e[G]; + if (L && L.length) { + y++, x.push(L); + } else if (!v) { + return q ? d : new X(d); } } } } else { - for (let G = 0, K, nb; G < p.length; G += 2) { - K = this.tag.get(p[G]); - if (!K) { - if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), t) { + for (let G = 0, L, ob; G < p.length; G += 2) { + L = this.tag.get(p[G]); + if (!L) { + if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), v) { continue; } else { - return m ? d : new X(d); + return q ? d : new X(d); } } - if (nb = (K = K && K.get(p[G + 1])) && K.length) { - y++, x.push(K); - } else if (!t) { - return m ? d : new X(d); + if (ob = (L = L && L.get(p[G + 1])) && L.length) { + y++, x.push(L); + } else if (!v) { + return q ? d : new X(d); } } } if (y) { - w = Ga(w, x, m); + w = Ha(w, x, q); H = w.length; - if (!H && !t) { - return m ? w : new X(w); + if (!H && !v) { + return q ? w : new X(w); } y--; } } if (H) { f[n] = D, d.push(w), n++; - } else if (1 === h.length) { - return m ? d : new X(d); + } else if (1 === l.length) { + return q ? d : new X(d); } } - if (v) { + if (u) { if (this.db && p && p.length && !F) { - for (r = 0; r < p.length; r += 2) { - e = this.index.get(p[r]); + for (h = 0; h < p.length; h += 2) { + e = this.index.get(p[h]); if (!e) { - if (console.warn("Tag '" + p[r] + ":" + p[r + 1] + "' was not found because there is no field '" + p[r] + "'."), t) { + if (console.warn("Tag '" + p[h] + ":" + p[h + 1] + "' was not found because there is no field '" + p[h] + "'."), v) { continue; } else { - return m ? d : new X(d); + return q ? d : new X(d); } } - v.push(e.db.tag(p[r + 1], b, l, !1)); + u.push(e.db.tag(p[h + 1], c, m, !1)); } } const z = this; - return Promise.all(v).then(function(w) { - return w.length ? z.search(a, b, c, w) : w; + return Promise.all(u).then(function(w) { + return w.length ? z.search(a, c, b, w) : w; }); } if (!n) { - return m ? d : new X(d); + return q ? d : new X(d); } - if (g && (!r || !this.store)) { + if (g && (!h || !this.store)) { return d[0]; } - v = []; + u = []; for (let z = 0, w; z < f.length; z++) { w = d[z]; - r && w.length && !w[0].doc && (this.db ? v.push(w = this.index.get(this.field[0]).db.enrich(w)) : w = W.call(this, w)); + h && w.length && !w[0].doc && (this.db ? u.push(w = this.index.get(this.field[0]).db.enrich(w)) : w = W.call(this, w)); if (g) { - return m ? w : new X(w); + return q ? w : new X(w); } d[z] = {field:f[z], result:w}; } - if (r && this.db && v.length) { + if (h && this.db && u.length) { const z = this; - return Promise.all(v).then(function(w) { + return Promise.all(u).then(function(w) { for (let D = 0; D < w.length; D++) { d[D].result = w[D]; } - return k ? Qa(d, b) : q ? Ra(d, a, z.index, z.field, z.D, q) : d; + return k ? Ra(d, c) : r ? Sa(d, a, z.index, z.field, z.D, r) : d; }); } - return k ? Qa(d, b) : q ? Ra(d, a, this.index, this.field, this.D, q) : d; + return k ? Ra(d, c) : r ? Sa(d, a, this.index, this.field, this.D, r) : d; }; -function Ra(a, b, c, e, d, f) { - let g, k, h; - for (let n = 0, m, q, p, t, r; n < a.length; n++) { - m = a[n].result; - q = a[n].field; - t = c.get(q); - p = t.encoder; - h = t.tokenize; - r = d[e.indexOf(q)]; - p !== g && (g = p, k = g.encode(b)); - for (let v = 0; v < m.length; v++) { +function Sa(a, c, b, e, d, f) { + console.log("template", f); + let g, h, k; + for (let m = 0, n, q, r, p, v; m < a.length; m++) { + n = a[m].result; + q = a[m].field; + p = b.get(q); + r = p.encoder; + k = p.tokenize; + v = d[e.indexOf(q)]; + r !== g && (g = r, h = g.encode(c)); + for (let u = 0; u < n.length; u++) { let x = ""; - var l = ba(m[v].doc, r); + var l = ba(n[u].doc, v); let y = g.encode(l); l = l.split(g.split); for (let F = 0, z, w; F < y.length; F++) { z = y[F]; w = l[F]; let D; - for (let H = 0, C; H < k.length; H++) { - if (C = k[H], "strict" === h) { + for (let H = 0, C; H < h.length; H++) { + if (C = h[H], "strict" === k) { if (z === C) { x += (x ? " " : "") + f.replace("$1", w); D = !0; @@ -1433,38 +1464,38 @@ function Ra(a, b, c, e, d, f) { } D || (x += (x ? " " : "") + l[F]); } - m[v].highlight = x; + n[u].highlight = x; } } return a; } -function Qa(a, b) { - const c = [], e = B(); +function Ra(a, c) { + const b = [], e = B(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; - for (let k = 0, h, l, n; k < g.length; k++) { - if (l = g[k], "object" !== typeof l && (l = {id:l}), h = l.id, n = e[h]) { - n.push(f.field); + for (let h = 0, k, l, m; h < g.length; h++) { + if (l = g[h], "object" !== typeof l && (l = {id:l}), k = l.id, m = e[k]) { + m.push(f.field); } else { - if (c.length === b) { - return c; + if (b.length === c) { + return b; } - l.field = e[h] = [f.field]; - c.push(l); + l.field = e[k] = [f.field]; + b.push(l); } } } - return c; + return b; } -function Pa(a, b, c, e, d) { +function Qa(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(b)) && f.length - e) && 0 < a) { - if (a > c || e) { - f = f.slice(e, e + c); + if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { + if (a > b || e) { + f = f.slice(e, e + b); } d && (f = W.call(this, f)); return f; @@ -1474,45 +1505,45 @@ function W(a) { if (!this || !this.store) { return a; } - const b = Array(a.length); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b[c] = {id:e, doc:this.store.get(e)}; + const c = Array(a.length); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c[b] = {id:e, doc:this.store.get(e)}; } - return b; + return c; } ;function V(a) { if (!this || this.constructor !== V) { return new V(a); } - const b = a.document || a.doc || a; - let c, e; + const c = a.document || a.doc || a; + let b, e; this.D = []; this.field = []; this.J = []; - this.key = (c = b.key || b.id) && Sa(c, this.J) || "id"; + this.key = (b = c.key || c.id) && Ta(b, this.J) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; this.reg = !this.fastupdate || a.worker || a.db ? e ? new U(e) : new Set() : e ? new T(e) : new Map(); - this.C = (c = b.store || null) && c && !0 !== c && []; - this.store = c && (e ? new T(e) : new Map()); - this.cache = (c = a.cache || null) && new Y(c); + this.C = (b = c.store || null) && b && !0 !== b && []; + this.store = b && (e ? new T(e) : new Map()); + this.cache = (b = a.cache || null) && new Y(b); a.cache = !1; this.worker = a.worker; this.priority = a.priority || 4; - this.index = Ta.call(this, a, b); + this.index = Ua.call(this, a, c); this.tag = null; - if (c = b.tag) { - if ("string" === typeof c && (c = [c]), c.length) { + if (b = c.tag) { + if ("string" === typeof b && (b = [b]), b.length) { this.tag = new Map(); this.F = []; this.R = []; - for (let d = 0, f, g; d < c.length; d++) { - f = c[d]; + for (let d = 0, f, g; d < b.length; d++) { + f = b[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.F[d] = f.custom : (this.F[d] = Sa(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); + f.custom ? this.F[d] = f.custom : (this.F[d] = Ta(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); this.R[d] = g; this.tag.set(g, new Map()); } @@ -1528,9 +1559,9 @@ function W(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]; - k[1].then && d.index.set(h, f[g++]); + for (const h of d.index.entries()) { + const k = h[0]; + h[1].then && d.index.set(k, f[g++]); } return d; }); @@ -1539,103 +1570,103 @@ function W(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -u = V.prototype; -u.mount = function(a) { +t = V.prototype; +t.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); } - let b = this.field; + let c = this.field; if (this.tag) { for (let d = 0, f; d < this.R.length; d++) { f = this.R[d]; - var c = void 0; - this.index.set(f, c = new O({}, this.reg)); - b === this.field && (b = b.slice(0)); - b.push(f); - c.tag = this.tag.get(f); + var b = void 0; + this.index.set(f, b = new O({}, this.reg)); + c === this.field && (c = c.slice(0)); + c.push(f); + b.tag = this.tag.get(f); } } - c = []; + b = []; const e = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let d = 0, f, g; d < b.length; d++) { - e.field = g = b[d]; + for (let d = 0, f, g; d < c.length; d++) { + e.field = g = c[d]; f = this.index.get(g); - const k = new a.constructor(a.id, e); - k.id = a.id; - c[d] = k.mount(f); + const h = new a.constructor(a.id, e); + h.id = a.id; + b[d] = h.mount(f); f.document = !0; d ? f.bypass = !0 : f.store = this.store; } this.db = !0; - return Promise.all(c); + return Promise.all(b); }; -u.commit = async function(a, b) { - const c = []; +t.commit = async function(a, c) { + const b = []; for (const e of this.index.values()) { - c.push(e.db.commit(e, a, b)); + b.push(e.commit(e, a, c)); } - await Promise.all(c); + await Promise.all(b); this.reg.clear(); }; -u.destroy = function() { +t.destroy = function() { const a = []; - for (const b of this.index.values()) { - a.push(b.destroy()); + for (const c of this.index.values()) { + a.push(c.destroy()); } return Promise.all(a); }; -function Ta(a, b) { - const c = new Map(); - let e = b.index || b.field || b; +function Ua(a, c) { + const b = new Map(); + let e = c.index || c.field || c; E(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { f = e[d]; E(f) || (g = f, f = f.field); g = I(g) ? Object.assign({}, a, g) : a; if (this.worker) { - const k = new Q(g); - c.set(f, k); + const h = new Q(g); + b.set(f, h); } - this.worker || c.set(f, new O(g, this.reg)); - g.custom ? this.D[d] = g.custom : (this.D[d] = Sa(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)); + this.worker || b.set(f, new O(g, this.reg)); + g.custom ? this.D[d] = g.custom : (this.D[d] = Ta(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)); this.field[d] = f; } if (this.C) { - a = b.store; + a = c.store; E(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Sa(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ta(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); } } - return c; + return b; } -function Sa(a, b) { - const c = a.split(":"); +function Ta(a, c) { + const b = a.split(":"); let e = 0; - for (let d = 0; d < c.length; d++) { - a = c[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[e] = !0), a && (c[e++] = a); + for (let d = 0; d < b.length; d++) { + a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); } - e < c.length && (c.length = e); - return 1 < e ? c : c[0]; + e < b.length && (b.length = e); + return 1 < e ? b : b[0]; } -u.append = function(a, b) { - return this.add(a, b, !0); +t.append = function(a, c) { + return this.add(a, c, !0); }; -u.update = function(a, b) { - return this.remove(a).add(a, b); +t.update = function(a, c) { + return this.remove(a).add(a, c); }; -u.remove = function(a) { +t.remove = function(a) { I(a) && (a = ba(a, this.key)); - for (var b of this.index.values()) { - b.remove(a, !0); + for (var c of this.index.values()) { + c.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]; + for (let b of this.tag.values()) { + for (let e of b) { + c = e[0]; const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : c.delete(b)); + -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); } } } @@ -1645,113 +1676,116 @@ u.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -u.clear = function() { - for (const a of this.index.values()) { - a.clear(); +t.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 a of this.tag.values()) { - a.clear(); + for (const c of this.tag.values()) { + c.clear(); } } this.store && this.store.clear(); - return this; + this.cache && this.cache.clear(); + return a.length ? Promise.all(a) : this; }; -u.contain = function(a) { +t.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; -u.cleanup = function() { +t.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -u.get = function(a) { - return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { - return b[0] && b[0].doc; +t.get = function(a) { + return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(c) { + return c[0] && c[0].doc; }) : this.store.get(a); }; -u.set = function(a, b) { - this.store.set(a, b); +t.set = function(a, c) { + this.store.set(a, c); return this; }; -u.searchCache = Ua; -u.export = function(a, b, c = 0, e = 0) { - if (c < this.field.length) { - const g = this.field[c]; - if ((b = this.index.get(g).export(a, g, c, e = 1)) && b.then) { - const k = this; - return b.then(function() { - return k.export(a, g, c + 1); +t.searchCache = Va; +t.export = function(a, c, b = 0, e = 0) { + if (b < this.field.length) { + const g = this.field[b]; + if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { + const h = this; + return c.then(function() { + return h.export(a, g, b + 1); }); } - return this.export(a, g, c + 1); + return this.export(a, g, b + 1); } let d, f; switch(e) { case 0: d = "reg"; f = wa(this.reg); - b = null; + c = null; break; case 1: d = "tag"; f = this.tag && ua(this.tag, this.reg.size); - b = null; + c = null; break; case 2: d = "doc"; f = this.store && sa(this.store); - b = null; + c = null; break; default: return; } - return ya.call(this, a, b, d, f, c, e); + return ya.call(this, a, c, d, f, b, e); }; -u.import = function(a, b) { - var c = a.split("."); - "json" === c[c.length - 1] && c.pop(); - const e = 2 < c.length ? c[0] : ""; - c = 2 < c.length ? c[2] : c[1]; +t.import = function(a, c) { + var b = a.split("."); + "json" === b[b.length - 1] && b.pop(); + const e = 2 < b.length ? b[0] : ""; + b = 2 < b.length ? b[2] : b[1]; if (this.worker && e) { return this.index.get(e).import(a); } - if (b) { - "string" === typeof b && (b = JSON.parse(b)); + if (c) { + "string" === typeof c && (c = JSON.parse(c)); if (e) { - return this.index.get(e).import(c, b); + return this.index.get(e).import(b, c); } - switch(c) { + switch(b) { case "reg": this.fastupdate = !1; - this.reg = xa(b, this.reg); + this.reg = xa(c, this.reg); for (let d = 0, f; d < this.field.length; d++) { f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg; } if (this.worker) { - b = []; + c = []; for (const d of this.index.values()) { - b.push(d.import(a)); + c.push(d.import(a)); } - return Promise.all(b); + return Promise.all(c); } break; case "tag": - this.tag = va(b, this.tag); + this.tag = va(c, this.tag); break; case "doc": - this.store = ta(b, this.store); + this.store = ta(c, this.store); } } }; la(V.prototype); -function Ua(a, b, c) { +function Va(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); let e = this.cache.get(a); if (!e) { - e = this.search(a, b, c); + e = this.search(a, c, b); if (e.then) { const d = this; e.then(function(f) { @@ -1768,99 +1802,99 @@ function Y(a) { this.cache = new Map(); this.h = ""; } -Y.prototype.set = function(a, b) { - this.cache.set(this.h = a, b); +Y.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); }; Y.prototype.get = function(a) { - const b = this.cache.get(a); - b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); - return b; + const c = this.cache.get(a); + c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); + return c; }; Y.prototype.remove = function(a) { - for (const b of this.cache) { - const c = b[0]; - b[1].includes(a) && this.cache.delete(c); + for (const c of this.cache) { + const b = c[0]; + c[1].includes(a) && this.cache.delete(b); } }; Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Va = {normalize:function(a) { +const Wa = {normalize:function(a) { return a.toLowerCase(); }}; -const Wa = 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 Xa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ya = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const Za = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const $a = /[\x00-\x7F]+/g; +const Xa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const Ya = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Za = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const $a = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; const ab = /[\x00-\x7F]+/g; const bb = /[\x00-\x7F]+/g; -var cb = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Va, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Wa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Wa, matcher:Xa, replacer:Ya}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Wa, replacer:Ya.concat([/(?!^)[aeo]/g, ""]), matcher:Xa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { - for (let c = 0; c < a.length; c++) { - var b = a[c]; - let e = b.charAt(0), d = Za[e]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Za[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { +const cb = /[\x00-\x7F]+/g; +var db = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Wa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Xa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Xa, matcher:Ya, replacer:Za}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Xa, replacer:Za.concat([/(?!^)[aeo]/g, ""]), matcher:Ya}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { + for (let b = 0; b < a.length; b++) { + var c = a[b]; + let e = c.charAt(0), d = $a[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = $a[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[c] = e; + a[b] = e; } }}, ArabicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace($a, " "); + return ("" + a).replace(ab, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(ab, ""); + return ("" + a).replace(bb, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(bb, " "); + return ("" + a).replace(cb, " "); }}}; -const db = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -O.prototype.add = function(a, b, c, e) { - if (b && (a || 0 === a)) { - if (!e && !c && this.reg.has(a)) { - return this.update(a, b); +const eb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +O.prototype.add = function(a, c, b, e) { + if (c && (a || 0 === a)) { + if (!e && !b && this.reg.has(a)) { + return this.update(a, c); } - b = this.encoder.encode(b); - if (e = b.length) { - const l = B(), n = B(), m = this.depth, q = this.resolution; - for (let p = 0; p < e; p++) { - let t = b[this.rtl ? e - 1 - p : p]; - var d = t.length; - if (d && (m || !n[t])) { - var f = this.score ? this.score(b, t, p, null, 0) : eb(q, e, p), g = ""; + c = this.encoder.encode(c); + if (e = c.length) { + const l = B(), m = B(), n = this.depth, q = this.resolution; + for (let r = 0; r < e; r++) { + let p = c[this.rtl ? e - 1 - r : r]; + var d = p.length; + if (d && (n || !m[p])) { + var f = this.score ? this.score(c, p, r, null, 0) : fb(q, e, r), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let r = 0, v; r < d; r++) { - for (f = d; f > r; f--) { - g = t.substring(r, f); - v = this.rtl ? d - 1 - r : r; - var k = this.score ? this.score(b, t, p, g, v) : eb(q, e, p, d, v); - fb(this, n, g, k, a, c); + for (let v = 0, u; v < d; v++) { + for (f = d; f > v; f--) { + g = p.substring(v, f); + u = this.rtl ? d - 1 - v : v; + var h = this.score ? this.score(c, p, r, g, u) : fb(q, e, r, d, u); + gb(this, m, g, h, a, b); } } break; } case "reverse": if (1 < d) { - for (k = d - 1; 0 < k; k--) { - g = t[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(b, t, p, g, k) : eb(q, e, p, d, k); - fb(this, n, g, h, a, c); + for (h = d - 1; 0 < h; h--) { + g = p[this.rtl ? d - 1 - h : h] + g; + var k = this.score ? this.score(c, p, r, g, h) : fb(q, e, r, d, h); + gb(this, m, g, k, a, b); } g = ""; } case "forward": if (1 < d) { - for (k = 0; k < d; k++) { - g += t[this.rtl ? d - 1 - k : k], fb(this, n, g, f, a, c); + for (h = 0; h < d; h++) { + g += p[this.rtl ? d - 1 - h : h], gb(this, m, g, f, a, b); } break; } default: - if (fb(this, n, t, f, a, c), m && 1 < e && p < e - 1) { - for (d = B(), g = this.U, f = t, k = Math.min(m + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { - if ((t = b[this.rtl ? e - 1 - p - h : p + h]) && !d[t]) { - d[t] = 1; - const r = this.score ? this.score(b, f, p, t, h - 1) : eb(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && t > f; - fb(this, l, v ? f : t, r, a, c, v ? t : f); + if (gb(this, m, p, f, a, b), n && 1 < e && r < e - 1) { + for (d = B(), g = this.U, f = p, h = Math.min(n + 1, this.rtl ? r + 1 : e - r), d[f] = 1, k = 1; k < h; k++) { + if ((p = c[this.rtl ? e - 1 - r - k : r + k]) && !d[p]) { + d[p] = 1; + const v = this.score ? this.score(c, f, r, p, k - 1) : fb(g + (e / 2 > g ? 0 : 1), e, r, h - 1, k - 1), u = this.bidirectional && p > f; + gb(this, l, u ? f : p, v, a, b, u ? p : f); } } } @@ -1869,105 +1903,105 @@ O.prototype.add = function(a, b, c, e) { } this.fastupdate || this.reg.add(a); } else { - b = ""; + c = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && gb(this)); + this.db && (c || this.commit_task.push({del:a}), this.T && hb(this)); return this; }; -function fb(a, b, c, e, d, f, g) { - let k = g ? a.ctx : a.map, h; - if (!b[c] || g && !(h = b[c])[g]) { - if (g ? (b = h || (b[c] = B()), b[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : b[c] = 1, (h = k.get(c)) ? k = h : k.set(c, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { - if (k.length === 2 ** 31 - 1) { - b = new S(k); +function gb(a, c, b, e, d, f, g) { + let h = g ? a.ctx : a.map, k; + if (!c[b] || g && !(k = c[b])[g]) { + if (g ? (c = k || (c[b] = B()), 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 = k = []), h = h[e] || (h[e] = []), !f || !h.includes(d)) { + if (h.length === 2 ** 31 - 1) { + c = new S(h); if (a.fastupdate) { for (let l of a.reg.values()) { - l.includes(k) && (l[l.indexOf(k)] = b); + l.includes(h) && (l[l.indexOf(h)] = c); } } - h[e] = k = b; + k[e] = h = c; } - k.push(d); - a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); + h.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(h) : a.reg.set(d, [h])); } } } -function eb(a, b, c, e, d) { - return c && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; +function fb(a, c, b, e, d) { + return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;O.prototype.search = function(a, b, c) { - c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); - let e = [], d, f, g, k = 0, h, l, n, m, q; - c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, q = (h = !1 !== c.resolve) && c.enrich, n = c.boost, m = c.resolution, l = this.db && c.tag) : h = this.resolve; - let p = this.encoder.encode(a); - d = p.length; - b = b || (h ? 100 : 0); +;O.prototype.search = function(a, c, b) { + b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); + let e = [], d, f, g, h = 0, k, l, m, n, q; + b ? (a = b.query || a, c = b.limit || c, h = b.offset || 0, f = b.context, g = b.suggest, q = (k = !1 !== b.resolve) && b.enrich, m = b.boost, n = b.resolution, l = this.db && b.tag) : k = this.resolve; + let r = this.encoder.encode(a); + d = r.length; + c = c || (k ? 100 : 0); if (1 === d) { - return hb.call(this, p[0], "", b, k, h, q, l); + return ib.call(this, r[0], "", c, h, k, q, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return hb.call(this, p[0], p[1], b, k, h, q, l); + return ib.call(this, r[0], r[1], c, h, k, q, l); } - let t = B(), r = 0, v; - 1 < d && f && (v = p[0], r = 1); - m || 0 === m || (m = v ? this.U : this.resolution); + let p = B(), v = 0, u; + 1 < d && f && (u = r[0], v = 1); + n || 0 === n || (n = u ? this.U : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, p, b, k, g, h, q, l), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, r, c, h, g, k, q, l), !1 !== a)) { return a; } const x = this; return async function() { - for (let y, F; r < d; r++) { - if ((F = p[r]) && !t[F]) { - t[F] = 1; - y = await ib(x, F, v, 0, 0, !1, !1); - if (y = jb(y, e, g, m)) { + for (let y, F; v < d; v++) { + if ((F = r[v]) && !p[F]) { + p[F] = 1; + y = await jb(x, F, u, 0, 0, !1, !1); + if (y = kb(y, e, g, n)) { e = y; break; } - v && (g && y && e.length || (v = F)); + u && (g && y && e.length || (u = F)); } - g && v && r === d - 1 && !e.length && (m = x.resolution, v = "", r = -1, t = B()); + g && u && v === d - 1 && !e.length && (n = x.resolution, u = "", v = -1, p = B()); } - return kb(e, m, b, k, g, n, h); + return lb(e, n, c, h, g, m, k); }(); } - for (let x, y; r < d; r++) { - if ((y = p[r]) && !t[y]) { - t[y] = 1; - x = ib(this, y, v, 0, 0, !1, !1); - if (x = jb(x, e, g, m)) { + for (let x, y; v < d; v++) { + if ((y = r[v]) && !p[y]) { + p[y] = 1; + x = jb(this, y, u, 0, 0, !1, !1); + if (x = kb(x, e, g, n)) { e = x; break; } - v && (g && x && e.length || (v = y)); + u && (g && x && e.length || (u = y)); } - g && v && r === d - 1 && !e.length && (m = this.resolution, v = "", r = -1, t = B()); + g && u && v === d - 1 && !e.length && (n = this.resolution, u = "", v = -1, p = B()); } - return kb(e, m, b, k, g, n, h); + return lb(e, n, c, h, g, m, k); }; -function kb(a, b, c, e, d, f, g) { - let k = a.length, h = a; - if (1 < k) { - h = Ea(a, b, c, e, d, f, g); - } else if (1 === k) { - return g ? Ha.call(null, a[0], c, e) : new X(a[0]); +function lb(a, c, b, e, d, f, g) { + let h = a.length, k = a; + if (1 < h) { + k = Fa(a, c, b, e, d, f, g); + } else if (1 === h) { + return g ? Ia.call(null, a[0], b, e) : new X(a[0]); } - return g ? h : new X(h); + return g ? k : new X(k); } -function hb(a, b, c, e, d, f, g) { - a = ib(this, a, b, c, e, d, f, g); - return this.db ? a.then(function(k) { - return d ? k || [] : new X(k); - }) : a && a.length ? d ? Ha.call(this, a, c, e) : new X(a) : d ? [] : new X(); +function ib(a, c, b, e, d, f, g) { + a = jb(this, a, c, b, e, d, f, g); + return this.db ? a.then(function(h) { + return d ? h || [] : new X(h); + }) : a && a.length ? d ? Ia.call(this, a, b, e) : new X(a) : d ? [] : new X(); } -function jb(a, b, c, e) { +function kb(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { - b.push(a); + c.push(a); return; } for (let f = 0, g; f < e; f++) { @@ -1976,122 +2010,123 @@ function jb(a, b, c, e) { } } if (d.length) { - b.push(d); + c.push(d); return; } } - if (!c) { + if (!b) { return d; } } -function ib(a, b, c, e, d, f, g, k) { - let h; - c && (h = a.bidirectional && b > c) && (h = c, c = b, b = h); +function jb(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(b, c, e, d, f, g, k); + return a.db.get(c, b, e, d, f, g, h); } - a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); + a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;O.prototype.remove = function(a, b) { - const c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); - if (c) { +;O.prototype.remove = function(a, c) { + const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (b) { if (this.fastupdate) { - for (let e = 0, d; e < c.length; e++) { - if (d = c[e]) { + for (let e = 0, d; e < b.length; e++) { + if (d = b[e]) { if (2 > d.length) { d.pop(); } else { const f = d.indexOf(a); - f === c.length - 1 ? d.pop() : d.splice(f, 1); + f === b.length - 1 ? d.pop() : d.splice(f, 1); } } } } else { - lb(this.map, a), this.depth && lb(this.ctx, a); + mb(this.map, a), this.depth && mb(this.ctx, a); } - b || this.reg.delete(a); + c || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && gb(this)); + this.db && (this.commit_task.push({del:a}), this.T && hb(this)); this.cache && this.cache.remove(a); return this; }; -function lb(a, b) { - let c = 0; +function mb(a, c) { + let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { if ((d = a[e]) && d.length) { - if (f = d.indexOf(b), 0 <= f) { - 1 < d.length ? (d.splice(f, 1), c++) : delete a[e]; + if (f = d.indexOf(c), 0 <= f) { + 1 < d.length ? (d.splice(f, 1), b++) : delete a[e]; break; } else { - c++; + b++; } } } } else { for (let e of a.entries()) { - const d = e[0], f = lb(e[1], b); - f ? c += f : a.delete(d); + const d = e[0], f = mb(e[1], c); + f ? b += f : a.delete(d); } } - return c; + return b; } -;function O(a, b) { +;function O(a, c) { if (!this || this.constructor !== O) { return new O(a); } if (a) { - var c = E(a) ? a : a.preset; - c && (db[c] || console.warn("Preset not found: " + c), a = Object.assign({}, db[c], a)); + var b = E(a) ? a : a.preset; + b && (eb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, eb[b], a)); } else { a = {}; } - c = a.context; - const e = !0 === c ? {depth:1} : c || {}, d = E(a.encoder) ? cb[a.encoder] : a.encode || a.encoder || Va; + b = a.context; + const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? db[a.encoder] : a.encode || a.encoder || Wa; this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = (c = a.tokenize) && "default" !== c && c || "strict"; - this.depth = "strict" === c && e.depth || 0; + this.tokenize = b = (b = a.tokenize) && "default" !== b && b || "strict"; + this.depth = "strict" === b && e.depth || 0; this.bidirectional = !1 !== e.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; - (c = a.keystore || 0) && (this.keystore = c); - this.map = c ? new T(c) : new Map(); - this.ctx = c ? new T(c) : new Map(); - this.reg = b || (this.fastupdate ? c ? new T(c) : new Map() : c ? new U(c) : new Set()); + e && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); + (b = a.keystore || 0) && (this.keystore = b); + this.map = b ? new T(b) : new Map(); + this.ctx = b ? new T(b) : new Map(); + this.reg = c || (this.fastupdate ? b ? new T(b) : new Map() : b ? new U(b) : new Set()); this.U = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new Y(c); + this.cache = (b = a.cache || null) && new Y(b); this.resolve = !1 !== a.resolve; - if (c = a.db) { - this.db = this.mount(c); + if (b = a.db) { + this.db = this.mount(b); } this.T = !1 !== a.commit; this.commit_task = []; this.commit_timer = null; this.priority = a.priority || 4; } -u = O.prototype; -u.mount = function(a) { +t = O.prototype; +t.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -u.commit = function(a, b) { +t.commit = function(a, c) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); - return this.db.commit(this, a, b); + return this.db.commit(this, a, c); }; -u.destroy = function() { +t.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function gb(a) { +function hb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); }, 1)); } -u.clear = function() { +t.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); @@ -2099,40 +2134,40 @@ u.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -u.append = function(a, b) { - return this.add(a, b, !0); +t.append = function(a, c) { + return this.add(a, c, !0); }; -u.contain = function(a) { +t.contain = function(a) { return this.db ? this.db.has(a) : this.reg.has(a); }; -u.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); +t.update = function(a, c) { + const b = this, e = this.remove(a); + return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function mb(a) { - let b = 0; +function nb(a) { + let c = 0; if (a.constructor === Array) { - for (let c = 0, e; c < a.length; c++) { - (e = a[c]) && (b += e.length); + for (let b = 0, e; b < a.length; b++) { + (e = a[b]) && (c += e.length); } } else { - for (const c of a) { - const e = c[0], d = mb(c[1]); - d ? b += d : a.delete(e); + for (const b of a.entries()) { + const e = b[0], d = nb(b[1]); + d ? c += d : a.delete(e); } } - return b; + return c; } -u.cleanup = function() { +t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - mb(this.map); - this.depth && mb(this.ctx); + nb(this.map); + this.depth && nb(this.ctx); return this; }; -u.searchCache = Ua; -u.export = function(a, b, c = 0, e = 0) { +t.searchCache = Va; +t.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: @@ -2154,230 +2189,203 @@ u.export = function(a, b, c = 0, e = 0) { default: return; } - return ya.call(this, a, b, d, f, c, e); + return ya.call(this, a, c, d, f, b, e); }; -u.import = function(a, b) { - if (b) { - switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { +t.import = function(a, c) { + if (c) { + switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = xa(b, this.reg); + this.reg = xa(c, this.reg); break; case "map": - this.map = ta(b, this.map); + this.map = ta(c, this.map); break; case "ctx": - this.ctx = va(b, this.ctx); + this.ctx = va(c, this.ctx); } } }; -u.serialize = function(a = !0) { - if (!this.reg.size) { - return ""; - } - let b = "", c = ""; - for (var e of this.reg.keys()) { - c || (c = typeof e), b += (b ? "," : "") + ("string" === c ? '"' + e + '"' : e); - } - b = "index.reg=new Set([" + b + "]);"; - e = ""; - for (var d of this.map.entries()) { - var f = d[0], g = d[1], k = ""; - for (let n = 0, m; n < g.length; n++) { - m = g[n] || [""]; - var h = ""; - for (var l = 0; l < m.length; l++) { - h += (h ? "," : "") + ("string" === c ? '"' + m[l] + '"' : m[l]); - } - h = "[" + h + "]"; - k += (k ? "," : "") + h; +t.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 ? "," : "") + ("string" === f ? '"' + d + '"' : d); } - k = '["' + f + '",[' + k + "]]"; - e += (e ? "," : "") + k; - } - e = "index.map=new Map([" + e + "]);"; - d = ""; - for (const n of this.ctx.entries()) { - f = n[0]; - g = n[1]; - for (const m of g.entries()) { - g = m[0]; - k = m[1]; - h = ""; - for (let q = 0, p; q < k.length; q++) { - p = k[q] || [""]; - l = ""; - for (let t = 0; t < p.length; t++) { - l += (l ? "," : "") + ("string" === c ? '"' + p[t] + '"' : p[t]); - } - l = "[" + l + "]"; - h += (h ? "," : "") + l; - } - h = 'new Map([["' + g + '",[' + h + "]]])"; - h = '["' + f + '",' + h + "]"; - d += (d ? "," : "") + h; + c = "index.reg=new Set([" + c + "]);"; + b = za(this.map, f); + b = "index.map=new Map([" + b + "]);"; + for (const g of this.ctx.entries()) { + d = g[0]; + let h = za(g[1], f); + h = "new Map([" + h + "])"; + h = '["' + d + '",' + h + "]"; + e += (e ? "," : "") + h; } + e = "index.ctx=new Map([" + e + "]);"; } - d = "index.ctx=new Map([" + d + "]);"; - return a ? "function inject(index){" + b + e + d + "}" : b + e + d; + return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; la(O.prototype); -const ob = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), pb = ["map", "ctx", "tag", "reg", "cfg"]; -function qb(a, b = {}) { +const pb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), qb = ["map", "ctx", "tag", "reg", "cfg"]; +function rb(a, c = {}) { if (!this) { - return new qb(a, b); + return new rb(a, c); } - "object" === typeof a && (b = a, a = a.name); + "object" === typeof a && (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 = b.field ? b.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; - this.type = b.type; + 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 = {}; } -u = qb.prototype; -u.mount = function(a) { +t = rb.prototype; +t.mount = function(a) { if (!a.encoder) { return a.mount(this); } a.db = this; return this.open(); }; -u.open = function() { +t.open = function() { let a = this; navigator.storage && navigator.storage.persist(); - return this.db || new Promise(function(b, c) { - const e = ob.open(a.id + (a.field ? ":" + a.field : ""), 1); + return this.db || new Promise(function(c, b) { + const e = pb.open(a.id + (a.field ? ":" + a.field : ""), 1); e.onupgradeneeded = function() { const d = a.db = this.result; - pb.forEach(f => { + qb.forEach(f => { d.objectStoreNames.contains(f) || d.createObjectStore(f); }); }; e.onblocked = function(d) { console.error("blocked", d); - c(); + b(); }; e.onerror = function(d) { console.error(this.error, d); - c(); + b(); }; e.onsuccess = function() { a.db = this.result; a.db.onversionchange = function() { a.close(); }; - b(a); + c(a); }; }); }; -u.close = function() { - this.db.close(); +t.close = function() { + this.db && this.db.close(); this.db = null; }; -u.destroy = function() { - const a = ob.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); +t.destroy = function() { + const a = pb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); return Z(a); }; -u.clear = function() { - const a = this.db.transaction(pb, "readwrite"); - for (let b = 0; b < pb.length; b++) { - a.objectStore(pb[b]).clear(); +t.clear = function() { + const a = this.db.transaction(qb, "readwrite"); + for (let c = 0; c < qb.length; c++) { + a.objectStore(qb[c]).clear(); } return Z(a); }; -u.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { - a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); +t.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { + a = this.db.transaction(c ? "ctx" : "map", "readonly").objectStore(c ? "ctx" : "map").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 (!c && !e && 1 === k.length) { - return k[0]; + if (!b && !e && 1 === h.length) { + 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 m = c ? e + Math.min(n.length - e, c) : n.length; - for (let q = e; q < m; q++) { - h.push(n[q]); + const n = b ? e + Math.min(m.length - e, b) : m.length; + for (let q = e; q < n; q++) { + k.push(m[q]); } e = 0; - if (h.length === c) { + if (k.length === b) { break; } } } - return f ? g.enrich(h) : h; + return f ? g.enrich(k) : k; } - return k; + return h; }); }; -u.tag = function(a, b = 0, c = 0, e = !1) { +t.tag = function(a, c = 0, b = 0, e = !1) { a = this.db.transaction("tag", "readonly").objectStore("tag").get(a); const d = this; return Z(a).then(function(f) { - if (!f || !f.length || c >= f.length) { + if (!f || !f.length || b >= f.length) { return []; } - if (!b && !c) { + if (!c && !b) { return f; } - f = f.slice(c, c + b); + f = f.slice(b, b + c); return e ? d.enrich(f) : f; }); }; -u.enrich = function(a) { +t.enrich = function(a) { "object" !== typeof a && (a = [a]); - const b = this.db.transaction("reg", "readonly").objectStore("reg"), c = []; + const c = this.db.transaction("reg", "readonly").objectStore("reg"), b = []; for (let e = 0; e < a.length; e++) { - c[e] = Z(b.get(a[e])); + b[e] = Z(c.get(a[e])); } - return Promise.all(c).then(function(e) { + return Promise.all(b).then(function(e) { for (let d = 0; d < e.length; d++) { e[d] = {id:a[d], doc:e[d] ? JSON.parse(e[d]) : null}; } return e; }); }; -u.has = function(a) { +t.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Z(a); -}; -u.search = null; -u.info = function() { -}; -u.transaction = function(a, b, c) { - let e = this.h[a + ":" + b]; - if (e) { - return c.call(this, e); - } - let d = this.db.transaction(a, b); - this.h[a + ":" + b] = e = d.objectStore(a); - return new Promise((f, g) => { - d.onerror = h => { - d.abort(); - d = e = null; - g(h); - }; - d.oncomplete = h => { - d = e = null; - f(h || !0); - }; - const k = c.call(this, e); - this.h[a + ":" + b] = null; - return k; + return Z(a).then(function(c) { + return !!c; }); }; -u.commit = async function(a, b, c) { - if (b) { +t.search = null; +t.info = function() { +}; +t.transaction = function(a, c, b) { + let e = this.h[a + ":" + c]; + if (e) { + return b.call(this, e); + } + let d = this.db.transaction(a, c); + this.h[a + ":" + c] = e = d.objectStore(a); + return new Promise((f, g) => { + d.onerror = k => { + d.abort(); + d = e = null; + g(k); + }; + d.oncomplete = k => { + d = e = null; + f(k || !0); + }; + const h = b.call(this, e); + this.h[a + ":" + c] = null; + return h; + }); +}; +t.commit = async function(a, c, b) { + if (c) { await this.clear(), a.commit_task = []; } else { let e = a.commit_task; @@ -2385,66 +2393,66 @@ u.commit = async function(a, b, c) { for (let d = 0, f; d < e.length; d++) { if (f = e[d], f.clear) { await this.clear(); - b = !0; + c = !0; break; } else { e[d] = f.W; } } - b || (c || (e = e.concat(aa(a.reg))), e.length && await this.remove(e)); + c || (b || (e = e.concat(aa(a.reg))), e.length && await this.remove(e)); } 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 && (b ? 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, m, q; n < l; n++) { - if ((q = g[n]) && q.length) { - if ((m = k[n]) && m.length) { - for (h = 0; h < q.length; h++) { - m.push(q[h]); + g.length && (c ? e.put(g, f) : 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, n, q; m < l; m++) { + if ((q = g[m]) && q.length) { + if ((n = h[m]) && n.length) { + for (k = 0; k < q.length; k++) { + n.push(q[k]); } } else { - k[n] = q; + h[m] = q; } - 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 && (b ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { - let n = this.result; - var m; - if (n && n.length) { - const q = Math.max(n.length, l.length); - for (let p = 0, t, r; p < q; p++) { - if ((r = l[p]) && r.length) { - if ((t = n[p]) && t.length) { - for (m = 0; m < r.length; m++) { - t.push(r[m]); + for (const h of g) { + const k = h[0], l = h[1]; + l.length && (c ? e.put(l, f + ":" + k) : e.get(f + ":" + k).onsuccess = function() { + let m = this.result; + var n; + if (m && m.length) { + const q = Math.max(m.length, l.length); + for (let r = 0, p, v; r < q; r++) { + if ((v = l[r]) && v.length) { + if ((p = m[r]) && p.length) { + for (n = 0; n < v.length; n++) { + p.push(v[n]); } } else { - n[p] = r; + m[r] = v; } - m = 1; + n = 1; } } } else { - n = l, m = 1; + m = l, n = 1; } - m && e.put(n, f + ":" + h); + n && e.put(m, f + ":" + k); }); } } @@ -2461,72 +2469,72 @@ u.commit = async function(a, b, c) { 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 rb(a, b, c) { +function sb(a, c, b) { const e = a.value; let d, f, g = 0; - for (let k = 0, h; k < e.length; k++) { - if (h = c ? e : e[k]) { - for (let l = 0, n, m; l < b.length; l++) { - if (m = b[l], n = h.indexOf(f ? parseInt(m, 10) : m), 0 > n && !f && "string" === typeof m && !isNaN(m) && (n = h.indexOf(parseInt(m, 10))) && (f = 1), 0 <= n) { - if (d = 1, 1 < h.length) { - h.splice(n, 1); + for (let h = 0, k; h < e.length; h++) { + if (k = b ? e : e[h]) { + for (let l = 0, m, n; l < c.length; l++) { + if (n = c[l], m = k.indexOf(f ? parseInt(n, 10) : n), 0 > m && !f && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (f = 1), 0 <= m) { + if (d = 1, 1 < k.length) { + k.splice(m, 1); } else { - e[k] = []; + e[h] = []; break; } } } - g += h.length; + g += k.length; } - if (c) { + if (b) { break; } } g ? d && a.update(e) : a.delete(); a.continue(); } -u.remove = function(a) { +t.remove = function(a) { "object" !== typeof a && (a = [a]); - return Promise.all([this.transaction("map", "readwrite", function(b) { - b.openCursor().onsuccess = function() { - const c = this.result; - c && rb(c, a); + return Promise.all([this.transaction("map", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && sb(b, a); }; - }), this.transaction("ctx", "readwrite", function(b) { - b.openCursor().onsuccess = function() { - const c = this.result; - c && rb(c, a); + }), this.transaction("ctx", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && sb(b, a); }; - }), this.transaction("tag", "readwrite", function(b) { - b.openCursor().onsuccess = function() { - const c = this.result; - c && rb(c, a, !0); + }), this.transaction("tag", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && sb(b, a, !0); }; - }), this.transaction("reg", "readwrite", function(b) { - for (let c = 0; c < a.length; c++) { - b.delete(a[c]); + }), this.transaction("reg", "readwrite", function(c) { + for (let b = 0; b < a.length; b++) { + c.delete(a[b]); } })]); }; function Z(a) { - return new Promise((b, c) => { + return new Promise((c, b) => { a.onsuccess = function() { - b(this.result); + c(this.result); }; a.oncomplete = function() { - b(this.result); + c(this.result); }; - a.onerror = c; + a.onerror = b; a = null; }); } -;export default {Index:O, Charset:cb, Encoder:J, Document:V, Worker:Q, Resolver:X, IndexedDB:qb, Language:{}}; +;export default {Index:O, Charset:db, Encoder:J, Document:V, Worker:Q, Resolver:X, IndexedDB:rb, Language:{}}; -export const Index=O;export const Charset=cb;export const Encoder=J;export const Document=V;export const Worker=Q;export const Resolver=X;export const IndexedDB=qb;export const Language={}; \ No newline at end of file +export const Index=O;export const Charset=db;export const Encoder=J;export const Document=V;export const Worker=Q;export const Resolver=X;export const IndexedDB=rb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index 495bc46..6058fab 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,103 +1,104 @@ /**! - * FlexSearch.js v0.8.123 (Bundle/Module) + * FlexSearch.js v0.8.132 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var u;function A(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(k){return a(c(k))};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"undefined"===d?b:a}function B(){return Object.create(null)}function E(a){return"string"===typeof a} +var t;function A(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&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"undefined"===d?b:a}function B(){return Object.create(null)}function E(a){return"string"===typeof a} function I(a){return"object"===typeof a}function aa(a){const b=[];for(const c of a.keys())b.push(c);return b}function ba(a,b){if(E(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; -this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,ea)}catch(d){this.split=/\s+/}this.numeric=A(a.numeric,A(this.numeric,!0))}this.prepare=A(a.prepare,null,this.prepare);this.finalize=A(a.finalize,null,this.finalize);ja||(this.mapper=new Map(da));this.rtl=A(a.rtl,!1,this.rtl);this.dedupe=A(a.dedupe,!1,this.dedupe);this.filter=A((c=a.filter)&&new Set(c),null,this.filter);this.matcher=A((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=A((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= -A((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=A(a.replacer,null,this.replacer);this.minlength=A(a.minlength,1,this.minlength);this.maxlength=A(a.maxlength,0,this.maxlength);if(this.cache=c=A(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= -(this.A?"|":"")+d;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&L(this);return this};u.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&L(this);return this};u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&L(this);return this};u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&L(this);return this}; -u.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(L,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d -this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(b=a.factory)?(Function("return "+b)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[b].apply(M,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} +["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]];const ea=/[^\p{L}\p{N}]+/u,fa=/(\d{3})/g,ha=/(\D)(\d{3})/g,ia=/(\d{3})(\D)/g,ja="".normalize&&/[\u0300-\u036f]/g;function J(a={}){if(!this||this.constructor!==J)return new J(...arguments);if(arguments.length)for(a=0;a"a1a".split(c).length; +this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,ea)}catch(d){this.split=/\s+/}this.numeric=A(a.numeric,A(this.numeric,!0))}this.prepare=A(a.prepare,null,this.prepare);this.finalize=A(a.finalize,null,this.finalize);ja||(this.mapper=new Map(da));c=a.filter;this.filter="function"===typeof c?c:A(c&&new Set(c),null,this.filter);this.dedupe=A(a.dedupe,!1,this.dedupe);this.matcher=A((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=A((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= +A((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=A(a.replacer,null,this.replacer);this.minlength=A(a.minlength,1,this.minlength);this.maxlength=A(a.maxlength,0,this.maxlength);this.rtl=A(a.rtl,!1,this.rtl);if(this.cache=c=A(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= +(this.A?"|":"")+d;return this};t.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&K(this);return this};t.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&K(this);return this}; +t.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&K(this);return this}; +t.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&K(this);return this}; +t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(K,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),d!==g&&this.filter&& +g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function K(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(b=a.factory)?(Function("return "+b)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[b].apply(M,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} function ma(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);na?pa||(pa=Date.now()-oa>=this.priority*this.priority*3):(na=setTimeout(qa,0),oa=Date.now());if(pa){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 P=0; -function Q(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,n=l&&d.h[l];n&&(n(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++P]=function(){h(d);1E9=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const k=b.length;if(k&&(d=d.length?d.concat(b):b,c-=k,e&&(a.length-=k),!c))break;b=0}return d} -function S(a){if(!this)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,k,h;gc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let m=0,q;me)e-= -q.length;else{if(q.length>c||e)q=q.slice(e,c+e),c-=q.length,e&&(e-=q.length);d.push(q);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?W.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Fa(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:n,suggest:m}=Ia(this,"and",arguments);return Ka.call(this,f,g,k,h,l,n,m)}return d?this.resolve(b,c,e):this}; -function Ka(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Ea(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ia(this,"xor",arguments);return La.call(this,a,b,c,e,d,f,g)}; -function La(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=Ma.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} -function Ma(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Va={normalize:function(a){return a.toLowerCase()}};const Wa=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 Xa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Ya=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Za={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const $a=/[\x00-\x7F]+/g;const ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;var cb={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Va,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Wa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Wa,matcher:Xa,replacer:Ya},LatinExtra:{normalize:!0,dedupe:!0,mapper:Wa,replacer:Ya.concat([/(?!^)[aeo]/g,""]),matcher:Xa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;ct;f--){g=r.substring(t,f);v=this.rtl?d-1-t:t;var k=this.score?this.score(b,r,p,g,v):eb(q,e,p,d,v); -fb(this,n,g,k,a,c)}break}case "reverse":if(1g?0:1),e,p,k-1,h-1),v=this.bidirectional&& -r>f;fb(this,l,v?f:r,t,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&gb(this));return this}; -function fb(a,b,c,e,d,f,g){let k=g?a.ctx:a.map,h;if(!b[c]||g&&!(h=b[c])[g])if(g?(b=h||(b[c]=B()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new S(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} -function eb(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else lb(this.map,a),this.depth&&lb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&gb(this));this.cache&&this.cache.remove(a);return this}; -function lb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; -function nb(a){let b=0;if(a.constructor===Array)for(let c=0,e;c{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; -u.close=function(){this.db.close();this.db=null};u.destroy=function(){const a=ob.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};u.clear=function(){const a=this.db.transaction(pb,"readwrite");for(let b=0;b=n.length){e-=n.length;continue}const m=c?e+Math.min(n.length-e,c):n.length;for(let q=e;q=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; -u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{d.onerror=h=>{d.abort();d=e=null;g(h)};d.oncomplete=h=>{d=e=null;f(h||!0)};const k=c.call(this,e);this.h[a+":"+b]=null;return k})}; -u.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dn&&!f&&"string"===typeof m&&!isNaN(m)&&(n=h.indexOf(parseInt(m,10)))&&(f=1),0<=n)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:O,Charset:cb,Encoder:J,Document:V,Worker:Q,Resolver:X,IndexedDB:qb,Language:{}}; -export const Index=O;export const Charset=cb;export const Encoder=J;export const Document=V;export const Worker=Q;export const Resolver=X;export const IndexedDB=qb;export const Language={}; \ No newline at end of file +function ya(a,b,c,e,d,f,g=0){const h=e&&e.constructor===Array;var k=h?e.shift():e;if(!k)return this.export(a,b,d,f+1);if((k=a((b?b+".":"")+(g+1)+"."+c,JSON.stringify(k)))&&k.then){const l=this;return k.then(function(){return ya.call(l,a,b,c,h?e:null,d,f,g+1)})}return ya.call(this,a,b,c,h?e:null,d,f,g+1)} +function za(a,b){let c="";for(const e of a.entries()){a=e[0];const d=e[1];let f="";for(let g=0,h;g=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 S(a){if(!this||this.constructor!==S)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;gc||e?k.slice(e,c+e):k;else{if(ac||e)k=k.slice(e,c+e)}else{d=[];for(let n= +0,p;ne)e-=p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=b);if(!d.length&&h>=b)return e?W.call(this,g):g;d.push(g);b-=h;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,m,n)}return d?this.resolve(b,c,e):this}; +function La(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; +function Ma(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function Na(a,b,c,e,d){const f=[],g=B();let h=0;for(let k=0,l;kc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:function(a){return a.toLowerCase()}};const Xa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Ya=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const $a={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;var db={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Wa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Xa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{normalize:!0,dedupe:!0,mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cu;f--){g=q.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(b,q,r,g,v):fb(p,e,r,d,v); +gb(this,m,g,h,a,c)}break}case "reverse":if(1g?0:1),e,r,h-1,k-1),v=this.bidirectional&& +q>f;gb(this,l,v?f:q,u,a,c,v?q:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&hb(this));return this}; +function gb(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){b=new S(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 fb(a,b,c,e,d){return c&&1c)&&(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};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&hb(this));this.cache&&this.cache.remove(a);return this}; +function mb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; +function ob(a){let b=0;if(a.constructor===Array)for(let c=0,e;c{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; +t.close=function(){this.db&&this.db.close();this.db=null};t.destroy=function(){const a=pb.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(qb,"readwrite");for(let b=0;b=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let p=e;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; +t.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{d.onerror=k=>{d.abort();d=e=null;g(k)};d.oncomplete=k=>{d=e=null;f(k||!0)};const h=c.call(this,e);this.h[a+":"+b]=null;return h})}; +t.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dm&&!f&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:O,Charset:db,Encoder:J,Document:V,Worker:Q,Resolver:X,IndexedDB:rb,Language:{}}; +export const Index=O;export const Charset=db;export const Encoder=J;export const Document=V;export const Worker=Q;export const Resolver=X;export const IndexedDB=rb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 91ba9ff..e7d68ba 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.123 (Bundle/Debug) + * FlexSearch.js v0.8.132 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -13,8 +13,8 @@ function B(a, c, b) { if ("undefined" !== d) { if (b) { if ("function" === d && e === d) { - return function(k) { - return a(b(k)); + return function(h) { + return a(b(h)); }; } c = a.constructor; @@ -128,15 +128,16 @@ x.assign = function(a) { this.prepare = B(a.prepare, null, this.prepare); this.finalize = B(a.finalize, null, this.finalize); ha || (this.mapper = new Map(ba)); - this.rtl = B(a.rtl, !1, this.rtl); + b = a.filter; + this.filter = "function" === typeof b ? b : B(b && new Set(b), null, this.filter); this.dedupe = B(a.dedupe, !1, this.dedupe); - this.filter = B((b = a.filter) && new Set(b), null, this.filter); this.matcher = B((b = a.matcher) && new Map(b), null, this.matcher); this.mapper = B((b = a.mapper) && new Map(b), null, this.mapper); this.stemmer = B((b = a.stemmer) && new Map(b), null, this.stemmer); this.replacer = B(a.replacer, null, this.replacer); this.minlength = B(a.minlength, 1, this.minlength); this.maxlength = B(a.maxlength, 0, this.maxlength); + this.rtl = B(a.rtl, !1, this.rtl); if (this.cache = b = B(a.cache, !0, this.cache)) { this.H = null, this.R = "number" === typeof b ? b : 2e5, this.F = new Map(), this.G = new Map(), this.L = this.K = 128; } @@ -165,8 +166,7 @@ x.addStemmer = function(a, c) { return this; }; x.addFilter = function(a) { - this.filter || (this.filter = new Set()); - this.filter.add(a); + "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); this.cache && L(this); return this; }; @@ -220,12 +220,12 @@ x.encode = function(a) { this.numeric && 3 < a.length && (a = a.replace(ea, "$1 $2").replace(fa, "$1 $2").replace(da, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; - for (let f = 0, g, k; f < e.length; f++) { - if ((g = k = e[f]) && !(g.length < this.minlength)) { + for (let f = 0, g, h; f < e.length; f++) { + if ((g = h = e[f]) && !(g.length < this.minlength)) { if (c) { b.push(g); } else { - if (!this.filter || !this.filter.has(g)) { + if (!this.filter || ("function" === typeof this.filter ? this.filter(g) : !this.filter.has(g))) { if (this.cache && g.length <= this.L) { if (this.H) { var d = this.G.get(g); @@ -237,21 +237,21 @@ x.encode = function(a) { this.H = setTimeout(L, 50, this); } } - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), g = g.replace(this.N, h => this.stemmer.get(h)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), d = g, g = g.replace(this.N, k => this.stemmer.get(k)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let h = 0, l = "", m, n; h < g.length; h++) { - m = g.charAt(h), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + for (let k = 0, l = "", m, n; k < g.length; k++) { + m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); } g = d; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); if (g && this.replacer) { for (d = 0; g && d < this.replacer.length; d += 2) { g = g.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); g && b.push(g); } } @@ -332,19 +332,19 @@ function P(a) { ;let R = 0; function S(a = {}) { function c(g) { - function k(h) { - h = h.data || h; - const l = h.id, m = l && d.h[l]; - m && (m(h.msg), delete d.h[l]); + function h(k) { + k = k.data || k; + const l = k.id, m = l && d.h[l]; + m && (m(k.msg), delete d.h[l]); } this.worker = g; this.h = C(); if (this.worker) { - e ? this.worker.on("message", k) : this.worker.onmessage = k; + e ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { - return new Promise(function(h) { + return new Promise(function(k) { d.h[++R] = function() { - h(d); + k(d); 1e9 < R && (R = 0); }; d.worker.postMessage({id:R, task:"init", factory:b, options:a}); @@ -440,18 +440,38 @@ function ta(a, c) { return c; } function U(a, c, b, e, d, f, g = 0) { - const k = e && e.constructor === Array; - var h = k ? e.shift() : e; - if (!h) { + 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 U.call(l, a, c, b, k ? e : null, d, f, g + 1); + return k.then(function() { + return U.call(l, a, c, b, h ? e : null, d, f, g + 1); }); } - return U.call(this, a, c, b, k ? e : null, d, f, g + 1); + return U.call(this, a, c, b, h ? e : null, d, f, g + 1); +} +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, h; g < d.length; g++) { + h = d[g] || [""]; + let k = ""; + for (let l = 0; l < h.length; l++) { + k += (k ? "," : "") + ("string" === c ? '"' + h[l] + '"' : h[l]); + } + k = "[" + k + "]"; + f += (f ? "," : "") + k; + } + f = '["' + a + '",[' + f + "]]"; + b += (b ? "," : "") + f; + } + return b; } ;V.prototype.add = function(a, c, b) { I(a) && (c = a, a = J(c, this.key)); @@ -459,15 +479,15 @@ function U(a, c, b, e, d, f, g = 0) { if (!b && this.reg.has(a)) { return this.update(a, c); } - for (let k = 0, h; k < this.field.length; k++) { - h = this.C[k]; - var e = this.index.get(this.field[k]); - if ("function" === typeof h) { - var d = h(c); + for (let h = 0, k; h < this.field.length; h++) { + k = this.C[h]; + var e = this.index.get(this.field[h]); + if ("function" === typeof k) { + var d = k(c); d && e.add(a, d, !1, !0); } else { - if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), ua(c, h, this.J, 0, e, a, h[0], b); + if (d = k.I, !d || d(c)) { + k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), va(c, k, this.J, 0, e, a, k[0], b); } } } @@ -475,14 +495,14 @@ function U(a, c, b, e, d, f, g = 0) { for (e = 0; e < this.B.length; e++) { var f = this.B[e], g = this.T[e]; d = this.tag.get(g); - let k = C(); + let h = C(); if ("function" === typeof f) { if (f = f(c), !f) { continue; } } else { - const h = f.I; - if (h && !h(c)) { + const k = f.I; + if (k && !k(c)) { continue; } f.constructor === String && (f = "" + f); @@ -490,8 +510,8 @@ function U(a, c, b, e, d, f, g = 0) { } if (d && f) { D(f) && (f = [f]); - for (let h = 0, l, m; h < f.length; h++) { - l = f[h], k[l] || (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); + for (let k = 0, l, m; k < f.length; k++) { + l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -499,11 +519,11 @@ function U(a, c, b, e, d, f, g = 0) { } } if (this.store && (!b || !this.store.has(a))) { - let k; + let h; if (this.A) { - k = C(); - for (let h = 0, l; h < this.A.length; h++) { - l = this.A[h]; + h = C(); + for (let k = 0, l; k < this.A.length; k++) { + l = this.A[k]; if ((b = l.I) && !b(c)) { continue; } @@ -515,32 +535,32 @@ function U(a, c, b, e, d, f, g = 0) { } l = [l.U]; } else if (D(l) || l.constructor === String) { - k[l] = c[l]; + h[l] = c[l]; continue; } - va(c, k, l, 0, l[0], m); + wa(c, h, l, 0, l[0], m); } } - this.store.set(a, k || c); + this.store.set(a, h || c); } } return this; }; -function va(a, c, b, e, d, f) { +function wa(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++) { - va(a, c, b, e, d); + wa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = C()), d = b[++e], va(a, c, b, e, d); + c = c[d] || (c[d] = C()), d = b[++e], wa(a, c, b, e, d); } } } -function ua(a, c, b, e, d, f, g, k) { +function va(a, c, b, e, d, f, g, h) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -552,34 +572,36 @@ function ua(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++) { - ua(a, c, b, e, d, f, g, k); + va(a, c, b, e, d, f, g, h); } } else { - g = c[++e], ua(a, c, b, e, d, f, g, k); + g = c[++e], va(a, c, b, e, d, f, g, h); } } } } -;function wa(a, c, b, e, d) { +;function xa(a, c, b, e, d) { const f = a.length; - let g = [], k, h; - k = C(); + let g = [], h, k; + h = C(); for (let l = 0, m, n, t, p; l < c; l++) { for (let q = 0; q < f; q++) { if (t = a[q], l < t.length && (m = t[l])) { for (let v = 0; v < m.length; v++) { - n = m[v], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), p = g[h] || (g[h] = []), p.push(n); + if (n = m[v], (k = h[n]) ? h[n]++ : (k = 0, h[n] = 1), p = g[k] || (g[k] = []), p.push(n), b && k === f - 1 && p.length - e === b) { + return p; + } } } } } if (a = g.length) { if (d) { - g = 1 < g.length ? xa(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + g = 1 < g.length ? ya(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; } else { if (a < f) { return []; @@ -594,14 +616,14 @@ function ua(a, c, b, e, d, f, g, k) { } return g; } -function xa(a, c, b) { +function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; - let k; - for (let h = g - 1; 0 <= h; h--) { - if (k = (g = a[h]) && g.length) { - for (let l = 0; l < k; l++) { + let h; + for (let k = g - 1; 0 <= k; k--) { + if (h = (g = a[k]) && g.length) { + for (let l = 0; l < h; l++) { if (f = g[l], !d[f]) { if (d[f] = 1, b) { b--; @@ -616,7 +638,7 @@ function xa(a, c, b) { } return e; } -function ya(a, c) { +function za(a, c) { const b = C(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; @@ -629,7 +651,7 @@ function ya(a, c) { } return e; } -;function za(a, c, b, e) { +;function Aa(a, c, b, e) { if (!a.length) { return a; } @@ -637,21 +659,21 @@ function ya(a, c) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.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; } - b < k && (g = c ? g.slice(b, b + c) : g.slice(b), k = g.length, b = 0); + b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); } - k > c && (g = g.slice(0, c), k = c); - if (!d.length && k >= c) { + h > c && (g = g.slice(0, c), h = c); + if (!d.length && h >= c) { return e ? W.call(this, g) : g; } d.push(g); - c -= k; + c -= h; if (!c) { break; } @@ -660,7 +682,7 @@ function ya(a, c) { d = 1 < d.length ? [].concat.apply([], d) : d[0]; return e ? W.call(this, d) : d; } -;function Aa(a, c, b) { +;function Ba(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -671,7 +693,7 @@ function ya(a, c) { return a[c].apply(a, e); } e = []; - let d = [], f = 0, g = 0, k, h, l; + let d = [], f = 0, g = 0, h, k, l; for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { let t; @@ -680,8 +702,8 @@ function ya(a, c) { } else if (n.constructor === Array) { t = n; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { - n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = h, n.enrich = k; + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { + n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = k, n.enrich = h; } else if (n.and) { t = a.and(n.and); } else if (n.or) { @@ -704,24 +726,24 @@ function ya(a, c) { } } } - return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; } ;X.prototype.or = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Aa(this, "or", arguments); - return Ba.call(this, a, c, b, e, d, f); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); + return Ca.call(this, a, c, b, e, d, f); }; -function Ba(a, c, b, e, d, f) { +function Ca(a, c, b, e, d, f) { if (c.length) { const g = this; - return Promise.all(c).then(function(k) { + return Promise.all(c).then(function(h) { a = []; - for (let h = 0, l; h < k.length; h++) { - (l = k[h]).length && (a[h] = l); + for (let k = 0, l; k < h.length; k++) { + (l = h[k]).length && (a[k] = l); } - return Ba.call(g, a, [], b, e, d, f); + return Ca.call(g, a, [], b, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = xa(a, b, e), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ya(a, b, e), e = 0)); return f ? this.resolve(b, e, d) : this; } ;X.prototype.and = function() { @@ -731,20 +753,20 @@ function Ba(a, c, b, e, d, f) { f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Aa(this, "and", arguments); - return Ca.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); + return Da.call(this, f, g, h, k, l, m, n); } return d ? this.resolve(c, b, e) : this; }; -function Ca(a, c, b, e, d, f, g) { +function Da(a, c, b, e, d, f, g) { if (c.length) { - const k = this; - return Promise.all(c).then(function(h) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return Ca.call(k, a, [], b, e, d, f, g); + return Da.call(h, a, [], b, e, d, f, g); }); } if (a.length) { @@ -752,7 +774,7 @@ function Ca(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = aa(a)) { - return this.result = wa(a, c, b, e, g), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = xa(a, c, b, e, g), f ? d ? W.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -762,37 +784,37 @@ function Ca(a, c, b, e, d, f, g) { return f ? this.resolve(b, e, d) : this; } ;X.prototype.xor = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Aa(this, "xor", arguments); - return Da.call(this, a, c, b, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "xor", arguments); + return Ea.call(this, a, c, b, e, d, f, g); }; -function Da(a, c, b, e, d, f, g) { +function Ea(a, c, b, e, d, f, g) { if (c.length) { - const k = this; - return Promise.all(c).then(function(h) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return Da.call(k, a, [], b, e, d, f, g); + return Ea.call(h, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = Ea.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Fa.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function Ea(a, c, b, e, d) { +function Fa(a, c, b, e, d) { const f = [], g = C(); - let k = 0; - for (let h = 0, l; h < a.length; h++) { - if (l = a[h]) { - k < l.length && (k = l.length); + let h = 0; + for (let k = 0, l; k < a.length; k++) { + if (l = a[k]) { + h < l.length && (h = l.length); for (let m = 0, n; m < l.length; m++) { if (n = l[m]) { for (let t = 0, p; t < n.length; t++) { @@ -802,10 +824,10 @@ function Ea(a, c, b, e, d) { } } } - for (let h = 0, l, m = 0; h < k; h++) { + for (let k = 0, l, m = 0; k < h; k++) { for (let n = 0, t; n < a.length; n++) { if (t = a[n]) { - if (l = t[h]) { + if (l = t[k]) { for (let p = 0, q; p < l.length; p++) { if (q = l[p], 1 === g[q]) { if (b) { @@ -816,7 +838,7 @@ function Ea(a, c, b, e, d) { return f; } } else { - const v = h + (n ? d : 0); + const v = k + (n ? d : 0); f[v] || (f[v] = []); f[v].push(q); if (++m === c) { @@ -833,34 +855,34 @@ function Ea(a, c, b, e, d) { return f; } ;X.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Aa(this, "not", arguments); - return Fa.call(this, a, c, b, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "not", arguments); + return Ga.call(this, a, c, b, e, d, f, g); }; -function Fa(a, c, b, e, d, f, g) { +function Ga(a, c, b, e, d, f, g) { if (c.length) { - const k = this; - return Promise.all(c).then(function(h) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return Fa.call(k, a, [], b, e, d, f, g); + return Ga.call(h, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ga.call(this, a, b, e, f); + this.result = Ha.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } return f ? d ? W.call(this.index, this.result) : this.result : this; } -function Ga(a, c, b, e) { +function Ha(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, k = 0; f < this.result.length; f++) { + for (let f = 0, g, h = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let h = 0, l; h < g.length; h++) { - if (l = g[h], !a.has(l)) { + for (let k = 0, l; k < g.length; k++) { + if (l = g[k], !a.has(l)) { if (b) { b--; } else { @@ -869,7 +891,7 @@ function Ga(a, c, b, e) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { + if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { return d; } } @@ -929,26 +951,25 @@ X.prototype.boost = function(a) { X.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), za.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Aa.call(d, e, a || 100, c, b)) : e; }; C(); V.prototype.search = function(a, c, b, e) { b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); let d = []; var f = []; - let g, k, h, l, m, n, t = 0, p = !0, q; + let g, h, k, l, m, n, t = 0, p = !0, q; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; var v = b.pluck; - k = b.merge; + h = b.merge; l = v || b.field || (l = b.index) && (l.index ? null : l); m = this.tag && b.tag; - h = b.suggest; + k = b.suggest; p = !0; this.store && b.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - g = this.store && b.enrich && p; - q = b.highlight && g; + q = (g = this.store && b.enrich && p) && b.highlight; c = b.limit || c; n = b.offset || 0; c || (c = 100); @@ -990,7 +1011,7 @@ V.prototype.search = function(a, c, b, e) { e = []; if (u.length) { for (f = 0; f < u.length; f += 2) { - v = Ha.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:v}); + v = Ia.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:v}); } } return e.length ? Promise.all(e).then(function(y) { @@ -1008,7 +1029,7 @@ V.prototype.search = function(a, c, b, e) { for (let y = 0, r, E, F; y < l.length; y++) { E = l[y]; let A; - D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, h = A.suggest || h, g = this.store && (A.enrich || g)); + D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, k = A.suggest || k, g = this.store && (A.enrich || g)); if (e) { r = e[y]; } else { @@ -1024,25 +1045,25 @@ V.prototype.search = function(a, c, b, e) { if (m && F) { w = []; z = 0; - for (let G = 0, H, Ya; G < m.length; G += 2) { + for (let G = 0, H, Za; G < m.length; G += 2) { H = this.tag.get(m[G]); if (!H) { - if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), h) { + if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { continue; } else { return p ? d : new X(d); } } - if (Ya = (H = H && H.get(m[G + 1])) && H.length) { + if (Za = (H = H && H.get(m[G + 1])) && H.length) { z++, w.push(H); - } else if (!h) { + } else if (!k) { return p ? d : new X(d); } } if (z) { - r = ya(r, w); + r = za(r, w); F = r.length; - if (!F && !h) { + if (!F && !k) { return p ? r : new X(r); } z--; @@ -1075,18 +1096,19 @@ V.prototype.search = function(a, c, b, e) { } d[y] = {field:f[y], result:r}; } - return k ? Ia(d, c) : q ? Ja(d, a, this.index, this.field, this.C, q) : d; + return h ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; }; -function Ja(a, c, b, e, d, f) { - let g, k, h; +function Ka(a, c, b, e, d, f) { + console.log("template", f); + let g, h, k; for (let m = 0, n, t, p, q, v; m < a.length; m++) { n = a[m].result; t = a[m].field; q = b.get(t); p = q.encoder; - h = q.tokenize; + k = q.tokenize; v = d[e.indexOf(t)]; - p !== g && (g = p, k = g.encode(c)); + p !== g && (g = p, h = g.encode(c)); for (let u = 0; u < n.length; u++) { let w = ""; var l = J(n[u].doc, v); @@ -1096,8 +1118,8 @@ function Ja(a, c, b, e, d, f) { r = z[y]; E = l[y]; let F; - for (let A = 0, G; A < k.length; A++) { - if (G = k[A], "strict" === h) { + for (let A = 0, G; A < h.length; A++) { + if (G = h[A], "strict" === k) { if (r === G) { w += (w ? " " : "") + f.replace("$1", E); F = !0; @@ -1119,26 +1141,26 @@ function Ja(a, c, b, e, d, f) { } return a; } -function Ia(a, c) { +function Ja(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; - for (let k = 0, h, l, m; k < g.length; k++) { - if (l = g[k], "object" !== typeof l && (l = {id:l}), h = l.id, m = e[h]) { + for (let h = 0, k, l, m; h < g.length; h++) { + if (l = g[h], "object" !== typeof l && (l = {id:l}), k = l.id, m = e[k]) { m.push(f.field); } else { if (b.length === c) { return b; } - l.field = e[h] = [f.field]; + l.field = e[k] = [f.field]; b.push(l); } } } return b; } -function Ha(a, c, b, e, d) { +function Ia(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1170,7 +1192,7 @@ function W(a) { this.C = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && Ka(b, this.J) || "id"; + this.key = (b = c.key || c.id) && La(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); this.A = (b = c.store || null) && b && !0 !== b && []; this.store = b && new Map(); @@ -1181,13 +1203,13 @@ function W(a) { let e = c.index || c.field || c; D(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Ka(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; + f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = La(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { a = c.store; D(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = Ka(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = La(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } this.index = b; @@ -1203,14 +1225,14 @@ function W(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = Ka(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = La(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); this.T[d] = g; this.tag.set(g, new Map()); } } } } -function Ka(a, c) { +function La(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1248,16 +1270,19 @@ x.remove = function(a) { return this; }; x.clear = function() { - for (const a of this.index.values()) { - a.clear(); + const a = []; + for (const c of this.index.values()) { + const b = c.clear(); + b.then && a.push(b); } if (this.tag) { - for (const a of this.tag.values()) { - a.clear(); + for (const c of this.tag.values()) { + c.clear(); } } this.store && this.store.clear(); - return this; + this.cache && this.cache.clear(); + return a.length ? Promise.all(a) : this; }; x.contain = function(a) { return this.reg.has(a); @@ -1275,14 +1300,14 @@ x.set = function(a, c) { this.store.set(a, c); return this; }; -x.searchCache = La; +x.searchCache = Ma; x.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const 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); @@ -1336,7 +1361,7 @@ x.import = function(a, c) { } }; ja(V.prototype); -function La(a, c, b) { +function Ma(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); let e = this.cache.get(a); @@ -1377,31 +1402,31 @@ Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ma = {normalize:function(a) { +const Na = {normalize:function(a) { return a.toLowerCase(); }}; -const Na = 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 Oa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Pa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const Qa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const Ra = /[\x00-\x7F]+/g; +const Oa = 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 Pa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Qa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const Ra = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; const Sa = /[\x00-\x7F]+/g; const Ta = /[\x00-\x7F]+/g; -var Ua = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Ma, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Na}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Na, matcher:Oa, replacer:Pa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Na, replacer:Pa.concat([/(?!^)[aeo]/g, ""]), matcher:Oa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Ua = /[\x00-\x7F]+/g; +var Va = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Na, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Oa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Oa, matcher:Pa, replacer:Qa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Oa, replacer:Qa.concat([/(?!^)[aeo]/g, ""]), matcher:Pa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = Qa[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Qa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = Ra[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ra[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Ra, " "); + return ("" + a).replace(Sa, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Sa, ""); + return ("" + a).replace(Ta, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Ta, " "); + return ("" + a).replace(Ua, " "); }}}; -const Va = {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 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}}}; O.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { @@ -1414,7 +1439,7 @@ O.prototype.add = function(a, c, b, e) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Wa(t, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : Xa(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { @@ -1422,34 +1447,34 @@ O.prototype.add = function(a, c, b, e) { for (f = d; f > v; f--) { g = q.substring(v, f); u = this.rtl ? d - 1 - v : v; - var k = this.score ? this.score(c, q, p, g, u) : Wa(t, e, p, d, u); - Z(this, m, g, k, a, b); + var h = this.score ? this.score(c, q, p, g, u) : Xa(t, e, p, d, u); + Z(this, m, g, h, a, b); } } break; } case "reverse": if (1 < d) { - for (k = d - 1; 0 < k; k--) { - g = q[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(c, q, p, g, k) : Wa(t, e, p, d, k); - Z(this, m, g, h, a, b); + for (h = d - 1; 0 < h; h--) { + g = q[this.rtl ? d - 1 - h : h] + g; + var k = this.score ? this.score(c, q, p, g, h) : Xa(t, e, p, d, h); + Z(this, m, g, k, a, b); } g = ""; } case "forward": if (1 < d) { - for (k = 0; k < d; k++) { - g += q[this.rtl ? d - 1 - k : k], Z(this, m, g, f, a, b); + for (h = 0; h < d; h++) { + g += q[this.rtl ? d - 1 - h : h], Z(this, m, g, f, a, b); } break; } default: if (Z(this, m, q, f, a, b), n && 1 < e && p < e - 1) { - for (d = C(), g = this.S, f = q, k = Math.min(n + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { - if ((q = c[this.rtl ? e - 1 - p - h : p + h]) && !d[q]) { + for (d = C(), g = this.S, f = q, h = Math.min(n + 1, this.rtl ? p + 1 : e - p), d[f] = 1, k = 1; k < h; k++) { + if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { d[q] = 1; - const v = this.score ? this.score(c, f, p, q, h - 1) : Wa(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; + const v = this.score ? this.score(c, f, p, q, k - 1) : Xa(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; Z(this, l, u ? f : q, v, a, b, u ? q : f); } } @@ -1463,12 +1488,12 @@ O.prototype.add = function(a, c, b, e) { return this; }; function Z(a, c, b, e, d, f, g) { - let k = g ? a.ctx : a.map, h; - if (!c[b] || g && !(h = c[b])[g]) { - g ? (c = h || (c[b] = C()), 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 = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); + let h = g ? a.ctx : a.map, k; + if (!c[b] || g && !(k = c[b])[g]) { + g ? (c = k || (c[b] = C()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); } } -function Wa(a, c, b, e, d) { +function Xa(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } ;O.prototype.search = function(a, c, b) { @@ -1480,35 +1505,35 @@ function Wa(a, c, b, e, d) { d = b.offset || 0; var f = b.context; var g = b.suggest; - var k = !0; - var h = b.resolution; + var h = !0; + var k = b.resolution; } else { - k = !0; + h = !0; } a = this.encoder.encode(a); b = a.length; - c = c || (k ? 100 : 0); + c = c || (h ? 100 : 0); if (1 === b) { - return g = c, (c = Xa(this, a[0], "")) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Ya(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return g = c, (c = Xa(this, a[0], a[1])) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Ya(this, a[0], a[1])) && c.length ? Aa.call(this, c, g, d) : []; } - k = C(); + h = C(); let l = 0; if (1 < b && f) { var m = a[0]; l = 1; } - h || 0 === h || (h = m ? this.S : this.resolution); + k || 0 === k || (k = m ? this.S : this.resolution); for (let q, v; l < b; l++) { - if ((v = a[l]) && !k[v]) { - k[v] = 1; - q = Xa(this, v, m); + if ((v = a[l]) && !h[v]) { + h[v] = 1; + q = Ya(this, v, m); a: { f = q; - var n = e, t = g, p = h; + var n = e, t = g, p = k; let u = []; if (f && f.length) { if (f.length <= p) { @@ -1535,23 +1560,23 @@ function Wa(a, c, b, e, d) { } m && (g && q && e.length || (m = v)); } - g && m && l === b - 1 && !e.length && (h = this.resolution, m = "", l = -1, k = C()); + g && m && l === b - 1 && !e.length && (k = this.resolution, m = "", l = -1, h = C()); } a: { a = e; e = a.length; m = a; if (1 < e) { - m = wa(a, h, c, d, g); + m = xa(a, k, c, d, g); } else if (1 === e) { - g = za.call(null, a[0], c, d); + g = Aa.call(null, a[0], c, d); break a; } g = m; } return g; }; -function Xa(a, c, b) { +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); @@ -1572,14 +1597,14 @@ function Xa(a, c, b) { } } } else { - Za(this.map, a), this.depth && Za(this.ctx, a); + $a(this.map, a), this.depth && $a(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Za(a, c) { +function $a(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1594,7 +1619,7 @@ function Za(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = Za(e[1], c); + const d = e[0], f = $a(e[1], c); f ? b += f : a.delete(d); } } @@ -1606,19 +1631,20 @@ function Za(a, c) { } if (a) { var b = D(a) ? a : a.preset; - b && (Va[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Va[b], a)); + b && (Wa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Wa[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Ua[a.encoder] : a.encode || a.encoder || Ma; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Va[a.encoder] : a.encode || a.encoder || Na; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = (b = a.tokenize) && "default" !== b && b || "strict"; + this.tokenize = b = (b = a.tokenize) && "default" !== b && b || "strict"; this.depth = "strict" === b && e.depth || 0; this.bidirectional = !1 !== e.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; + e && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); b = !1; this.map = new Map(); this.ctx = new Map(); @@ -1646,15 +1672,15 @@ x.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function $a(a) { +function ab(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { (e = a[b]) && (c += e.length); } } else { - for (const b of a) { - const e = b[0], d = $a(b[1]); + for (const b of a.entries()) { + const e = b[0], d = ab(b[1]); d ? c += d : a.delete(e); } } @@ -1664,11 +1690,11 @@ x.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - $a(this.map); - this.depth && $a(this.ctx); + ab(this.map); + this.depth && ab(this.ctx); return this; }; -x.searchCache = La; +x.searchCache = Ma; x.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { @@ -1709,59 +1735,30 @@ x.import = function(a, c) { } }; x.serialize = function(a = !0) { - if (!this.reg.size) { - return ""; - } - let c = "", b = ""; - for (var e of this.reg.keys()) { - b || (b = typeof e), c += (c ? "," : "") + ("string" === b ? '"' + e + '"' : e); - } - c = "index.reg=new Set([" + c + "]);"; - e = ""; - for (var d of this.map.entries()) { - var f = d[0], g = d[1], k = ""; - for (let m = 0, n; m < g.length; m++) { - n = g[m] || [""]; - var h = ""; - for (var l = 0; l < n.length; l++) { - h += (h ? "," : "") + ("string" === b ? '"' + n[l] + '"' : n[l]); - } - h = "[" + h + "]"; - k += (k ? "," : "") + h; + let c = "", b = "", e = ""; + if (this.reg.size) { + let f; + for (var d of this.reg.keys()) { + f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } - k = '["' + f + '",[' + k + "]]"; - e += (e ? "," : "") + k; - } - e = "index.map=new Map([" + e + "]);"; - d = ""; - for (const m of this.ctx.entries()) { - f = m[0]; - g = m[1]; - for (const n of g.entries()) { - g = n[0]; - k = n[1]; - h = ""; - for (let t = 0, p; t < k.length; t++) { - p = k[t] || [""]; - l = ""; - for (let q = 0; q < p.length; q++) { - l += (l ? "," : "") + ("string" === b ? '"' + p[q] + '"' : p[q]); - } - l = "[" + l + "]"; - h += (h ? "," : "") + l; - } - h = 'new Map([["' + g + '",[' + h + "]]])"; - h = '["' + f + '",' + h + "]"; - d += (d ? "," : "") + h; + 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 + "]);"; } - d = "index.ctx=new Map([" + d + "]);"; - return a ? "function inject(index){" + c + e + d + "}" : c + e + d; + return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; ja(O.prototype); -const ab = {Index:O, Charset:Ua, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, bb = self; -let cb; -(cb = bb.define) && cb.amd ? cb([], function() { - return ab; -}) : "object" === typeof bb.exports ? bb.exports = ab : bb.FlexSearch = ab; +const bb = {Index:O, Charset:Va, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, cb = self; +let db; +(db = cb.define) && db.amd ? db([], function() { + return bb; +}) : "object" === typeof cb.exports ? cb.exports = bb : cb.FlexSearch = bb; }(this||self)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 465ee56..6376fe8 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,11 +1,11 @@ /**! - * FlexSearch.js v0.8.123 (Bundle) + * FlexSearch.js v0.8.132 (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 x;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(k){return a(b(k))};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"undefined"===d?c:a}function C(){return Object.create(null)}function D(a){return"string"===typeof a} +(function(self){'use strict';var x;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var 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"undefined"===d?c:a}function C(){return Object.create(null)}function D(a){return"string"===typeof a} function H(a){return"object"===typeof a}function I(a,c){if(D(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=B(a.numeric,e)}else{try{this.split=B(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=B(a.numeric,B(this.numeric,!0))}this.prepare=B(a.prepare,null,this.prepare);this.finalize=B(a.finalize,null,this.finalize);ha||(this.mapper=new Map(ba));this.rtl=B(a.rtl,!1,this.rtl);this.dedupe=B(a.dedupe,!1,this.dedupe);this.filter=B((b=a.filter)&&new Set(b),null,this.filter);this.matcher=B((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=B((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer= -B((b=a.stemmer)&&new Map(b),null,this.stemmer);this.replacer=B(a.replacer,null,this.replacer);this.minlength=B(a.minlength,1,this.minlength);this.maxlength=B(a.maxlength,0,this.maxlength);if(this.cache=b=B(a.cache,!0,this.cache))this.H=null,this.R="number"===typeof b?b:2E5,this.F=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.D="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.D+= -(this.D?"|":"")+d;return this};x.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.D+=(this.D?"|":"")+a;this.N=null;this.cache&&L(this);return this};x.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&L(this);return this};x.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(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.M=null;this.cache&&L(this);return this};x.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&L(this);return this}; +this.numeric=B(a.numeric,e)}else{try{this.split=B(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=B(a.numeric,B(this.numeric,!0))}this.prepare=B(a.prepare,null,this.prepare);this.finalize=B(a.finalize,null,this.finalize);ha||(this.mapper=new Map(ba));b=a.filter;this.filter="function"===typeof b?b:B(b&&new Set(b),null,this.filter);this.dedupe=B(a.dedupe,!1,this.dedupe);this.matcher=B((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=B((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer= +B((b=a.stemmer)&&new Map(b),null,this.stemmer);this.replacer=B(a.replacer,null,this.replacer);this.minlength=B(a.minlength,1,this.minlength);this.maxlength=B(a.maxlength,0,this.maxlength);this.rtl=B(a.rtl,!1,this.rtl);if(this.cache=b=B(a.cache,!0,this.cache))this.H=null,this.R="number"===typeof b?b:2E5,this.F=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.D="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.D+= +(this.D?"|":"")+d;return this};x.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.D+=(this.D?"|":"")+a;this.N=null;this.cache&&L(this);return this};x.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&L(this);return this}; +x.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(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.M=null;this.cache&&L(this);return this}; +x.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&L(this);return this}; x.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(L,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ha?a.normalize("NFKD").replace(ha,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d -this.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ka,la,Q;function ma(){ka=Q=0} +[],e=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;fthis.stemmer.get(k)),d!==g&&this.filter&& +g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ka,la,Q;function ma(){ka=Q=0} function P(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);ka?Q||(Q=Date.now()-la>=this.priority*this.priority*3):(ka=setTimeout(ma,0),la=Date.now());if(Q){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 R=0; -function S(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++R]=function(){h(d);1E9b||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function xa(a,c,b){const e=[],d=C();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?W.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=xa(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Aa(this,"and",arguments);return Ca.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; -function Ca(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=wa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Aa(this,"xor",arguments);return Da.call(this,a,c,b,e,d,f,g)}; -function Da(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Ea.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function Ea(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} +function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}bc&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?W.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,h,k,l,m,n)}return d?this.resolve(c,b,e):this}; +function Da(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; +function Ea(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Fa(a,c,b,e,d){const f=[],g=C();let h=0;for(let k=0,l;kb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.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};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Ma={normalize:function(a){return a.toLowerCase()}};const Na=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 Oa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Pa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Qa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Ra=/[\x00-\x7F]+/g;const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;var Ua={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Ma,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Na},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Na,matcher:Oa,replacer:Pa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Na,replacer:Pa.concat([/(?!^)[aeo]/g,""]),matcher:Oa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bv;f--){g=q.substring(v,f);u=this.rtl?d-1-v:v;var k=this.score?this.score(c,q,p,g,u):Wa(t,e,p,d,u); -Z(this,m,g,k,a,b)}break}case "reverse":if(1g?0:1),e,p,k-1,h-1),u=this.bidirectional&& -q>f;Z(this,l,u?f:q,v,a,b,u?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=C()),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=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function Wa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else Za(this.map,a),this.depth&&Za(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Za(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;ethis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.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};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:function(a){return a.toLowerCase()}};const Oa=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 Pa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Ra={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;const Ua=/[\x00-\x7F]+/g;var Va={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Na,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Oa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Oa,matcher:Pa,replacer:Qa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bv;f--){g=q.substring(v,f);u=this.rtl?d-1-v:v;var h=this.score?this.score(c,q,p,g,u):Xa(t,e,p,d,u); +Z(this,m,g,h,a,b)}break}case "reverse":if(1g?0:1),e,p,h-1,k-1),u=this.bidirectional&& +q>f;Z(this,l,u?f:q,v,a,b,u?q: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]=C()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function Xa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else $a(this.map,a),this.depth&&$a(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function $a(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function $a(a){let c=0;if(a.constructor===Array)for(let b=0,e;bb.add(a,c)):this.add(a,c)};function ab(a){let c=0;if(a.constructor===Array)for(let b=0,e;b this.stemmer.get(h)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), d = g, g = g.replace(this.N, k => this.stemmer.get(k)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let h = 0, l = "", m, n; h < g.length; h++) { - m = g.charAt(h), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + for (let k = 0, l = "", m, n; k < g.length; k++) { + m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); } g = d; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); if (g && this.replacer) { for (d = 0; g && d < this.replacer.length; d += 2) { g = g.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); g && b.push(g); } } @@ -331,19 +331,19 @@ function P(a) { ;let R = 0; function S(a = {}) { function c(g) { - function k(h) { - h = h.data || h; - const l = h.id, m = l && d.h[l]; - m && (m(h.msg), delete d.h[l]); + function h(k) { + k = k.data || k; + const l = k.id, m = l && d.h[l]; + m && (m(k.msg), delete d.h[l]); } this.worker = g; this.h = C(); if (this.worker) { - e ? this.worker.on("message", k) : this.worker.onmessage = k; + e ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { - return new Promise(function(h) { + return new Promise(function(k) { d.h[++R] = function() { - h(d); + k(d); 1e9 < R && (R = 0); }; d.worker.postMessage({id:R, task:"init", factory:b, options:a}); @@ -439,18 +439,38 @@ function ta(a, c) { return c; } function U(a, c, b, e, d, f, g = 0) { - const k = e && e.constructor === Array; - var h = k ? e.shift() : e; - if (!h) { + 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 U.call(l, a, c, b, k ? e : null, d, f, g + 1); + return k.then(function() { + return U.call(l, a, c, b, h ? e : null, d, f, g + 1); }); } - return U.call(this, a, c, b, k ? e : null, d, f, g + 1); + return U.call(this, a, c, b, h ? e : null, d, f, g + 1); +} +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, h; g < d.length; g++) { + h = d[g] || [""]; + let k = ""; + for (let l = 0; l < h.length; l++) { + k += (k ? "," : "") + ("string" === c ? '"' + h[l] + '"' : h[l]); + } + k = "[" + k + "]"; + f += (f ? "," : "") + k; + } + f = '["' + a + '",[' + f + "]]"; + b += (b ? "," : "") + f; + } + return b; } ;V.prototype.add = function(a, c, b) { I(a) && (c = a, a = J(c, this.key)); @@ -458,15 +478,15 @@ function U(a, c, b, e, d, f, g = 0) { if (!b && this.reg.has(a)) { return this.update(a, c); } - for (let k = 0, h; k < this.field.length; k++) { - h = this.C[k]; - var e = this.index.get(this.field[k]); - if ("function" === typeof h) { - var d = h(c); + for (let h = 0, k; h < this.field.length; h++) { + k = this.C[h]; + var e = this.index.get(this.field[h]); + if ("function" === typeof k) { + var d = k(c); d && e.add(a, d, !1, !0); } else { - if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), ua(c, h, this.J, 0, e, a, h[0], b); + if (d = k.I, !d || d(c)) { + k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), va(c, k, this.J, 0, e, a, k[0], b); } } } @@ -474,14 +494,14 @@ function U(a, c, b, e, d, f, g = 0) { for (e = 0; e < this.B.length; e++) { var f = this.B[e], g = this.T[e]; d = this.tag.get(g); - let k = C(); + let h = C(); if ("function" === typeof f) { if (f = f(c), !f) { continue; } } else { - const h = f.I; - if (h && !h(c)) { + const k = f.I; + if (k && !k(c)) { continue; } f.constructor === String && (f = "" + f); @@ -489,8 +509,8 @@ function U(a, c, b, e, d, f, g = 0) { } if (d && f) { D(f) && (f = [f]); - for (let h = 0, l, m; h < f.length; h++) { - l = f[h], k[l] || (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); + for (let k = 0, l, m; k < f.length; k++) { + l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -498,11 +518,11 @@ function U(a, c, b, e, d, f, g = 0) { } } if (this.store && (!b || !this.store.has(a))) { - let k; + let h; if (this.A) { - k = C(); - for (let h = 0, l; h < this.A.length; h++) { - l = this.A[h]; + h = C(); + for (let k = 0, l; k < this.A.length; k++) { + l = this.A[k]; if ((b = l.I) && !b(c)) { continue; } @@ -514,32 +534,32 @@ function U(a, c, b, e, d, f, g = 0) { } l = [l.U]; } else if (D(l) || l.constructor === String) { - k[l] = c[l]; + h[l] = c[l]; continue; } - va(c, k, l, 0, l[0], m); + wa(c, h, l, 0, l[0], m); } } - this.store.set(a, k || c); + this.store.set(a, h || c); } } return this; }; -function va(a, c, b, e, d, f) { +function wa(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++) { - va(a, c, b, e, d); + wa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = C()), d = b[++e], va(a, c, b, e, d); + c = c[d] || (c[d] = C()), d = b[++e], wa(a, c, b, e, d); } } } -function ua(a, c, b, e, d, f, g, k) { +function va(a, c, b, e, d, f, g, h) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -551,34 +571,36 @@ function ua(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++) { - ua(a, c, b, e, d, f, g, k); + va(a, c, b, e, d, f, g, h); } } else { - g = c[++e], ua(a, c, b, e, d, f, g, k); + g = c[++e], va(a, c, b, e, d, f, g, h); } } } } -;function wa(a, c, b, e, d) { +;function xa(a, c, b, e, d) { const f = a.length; - let g = [], k, h; - k = C(); + let g = [], h, k; + h = C(); for (let l = 0, m, n, t, p; l < c; l++) { for (let q = 0; q < f; q++) { if (t = a[q], l < t.length && (m = t[l])) { for (let v = 0; v < m.length; v++) { - n = m[v], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), p = g[h] || (g[h] = []), p.push(n); + if (n = m[v], (k = h[n]) ? h[n]++ : (k = 0, h[n] = 1), p = g[k] || (g[k] = []), p.push(n), b && k === f - 1 && p.length - e === b) { + return p; + } } } } } if (a = g.length) { if (d) { - g = 1 < g.length ? xa(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + g = 1 < g.length ? ya(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; } else { if (a < f) { return []; @@ -593,14 +615,14 @@ function ua(a, c, b, e, d, f, g, k) { } return g; } -function xa(a, c, b) { +function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; - let k; - for (let h = g - 1; 0 <= h; h--) { - if (k = (g = a[h]) && g.length) { - for (let l = 0; l < k; l++) { + let h; + for (let k = g - 1; 0 <= k; k--) { + if (h = (g = a[k]) && g.length) { + for (let l = 0; l < h; l++) { if (f = g[l], !d[f]) { if (d[f] = 1, b) { b--; @@ -615,7 +637,7 @@ function xa(a, c, b) { } return e; } -function ya(a, c) { +function za(a, c) { const b = C(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; @@ -628,7 +650,7 @@ function ya(a, c) { } return e; } -;function za(a, c, b, e) { +;function Aa(a, c, b, e) { if (!a.length) { return a; } @@ -636,21 +658,21 @@ function ya(a, c) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.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; } - b < k && (g = c ? g.slice(b, b + c) : g.slice(b), k = g.length, b = 0); + b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); } - k > c && (g = g.slice(0, c), k = c); - if (!d.length && k >= c) { + h > c && (g = g.slice(0, c), h = c); + if (!d.length && h >= c) { return e ? W.call(this, g) : g; } d.push(g); - c -= k; + c -= h; if (!c) { break; } @@ -659,7 +681,7 @@ function ya(a, c) { d = 1 < d.length ? [].concat.apply([], d) : d[0]; return e ? W.call(this, d) : d; } -;function Aa(a, c, b) { +;function Ba(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -670,7 +692,7 @@ function ya(a, c) { return a[c].apply(a, e); } e = []; - let d = [], f = 0, g = 0, k, h, l; + let d = [], f = 0, g = 0, h, k, l; for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { let t; @@ -679,8 +701,8 @@ function ya(a, c) { } else if (n.constructor === Array) { t = n; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { - n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = h, n.enrich = k; + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { + n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = k, n.enrich = h; } else if (n.and) { t = a.and(n.and); } else if (n.or) { @@ -703,24 +725,24 @@ function ya(a, c) { } } } - return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; } ;X.prototype.or = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Aa(this, "or", arguments); - return Ba.call(this, a, c, b, e, d, f); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); + return Ca.call(this, a, c, b, e, d, f); }; -function Ba(a, c, b, e, d, f) { +function Ca(a, c, b, e, d, f) { if (c.length) { const g = this; - return Promise.all(c).then(function(k) { + return Promise.all(c).then(function(h) { a = []; - for (let h = 0, l; h < k.length; h++) { - (l = k[h]).length && (a[h] = l); + for (let k = 0, l; k < h.length; k++) { + (l = h[k]).length && (a[k] = l); } - return Ba.call(g, a, [], b, e, d, f); + return Ca.call(g, a, [], b, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = xa(a, b, e), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ya(a, b, e), e = 0)); return f ? this.resolve(b, e, d) : this; } ;X.prototype.and = function() { @@ -730,20 +752,20 @@ function Ba(a, c, b, e, d, f) { f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Aa(this, "and", arguments); - return Ca.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); + return Da.call(this, f, g, h, k, l, m, n); } return d ? this.resolve(c, b, e) : this; }; -function Ca(a, c, b, e, d, f, g) { +function Da(a, c, b, e, d, f, g) { if (c.length) { - const k = this; - return Promise.all(c).then(function(h) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return Ca.call(k, a, [], b, e, d, f, g); + return Da.call(h, a, [], b, e, d, f, g); }); } if (a.length) { @@ -751,7 +773,7 @@ function Ca(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = aa(a)) { - return this.result = wa(a, c, b, e, g), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = xa(a, c, b, e, g), f ? d ? W.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -761,37 +783,37 @@ function Ca(a, c, b, e, d, f, g) { return f ? this.resolve(b, e, d) : this; } ;X.prototype.xor = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Aa(this, "xor", arguments); - return Da.call(this, a, c, b, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "xor", arguments); + return Ea.call(this, a, c, b, e, d, f, g); }; -function Da(a, c, b, e, d, f, g) { +function Ea(a, c, b, e, d, f, g) { if (c.length) { - const k = this; - return Promise.all(c).then(function(h) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return Da.call(k, a, [], b, e, d, f, g); + return Ea.call(h, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = Ea.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Fa.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function Ea(a, c, b, e, d) { +function Fa(a, c, b, e, d) { const f = [], g = C(); - let k = 0; - for (let h = 0, l; h < a.length; h++) { - if (l = a[h]) { - k < l.length && (k = l.length); + let h = 0; + for (let k = 0, l; k < a.length; k++) { + if (l = a[k]) { + h < l.length && (h = l.length); for (let m = 0, n; m < l.length; m++) { if (n = l[m]) { for (let t = 0, p; t < n.length; t++) { @@ -801,10 +823,10 @@ function Ea(a, c, b, e, d) { } } } - for (let h = 0, l, m = 0; h < k; h++) { + for (let k = 0, l, m = 0; k < h; k++) { for (let n = 0, t; n < a.length; n++) { if (t = a[n]) { - if (l = t[h]) { + if (l = t[k]) { for (let p = 0, q; p < l.length; p++) { if (q = l[p], 1 === g[q]) { if (b) { @@ -815,7 +837,7 @@ function Ea(a, c, b, e, d) { return f; } } else { - const v = h + (n ? d : 0); + const v = k + (n ? d : 0); f[v] || (f[v] = []); f[v].push(q); if (++m === c) { @@ -832,34 +854,34 @@ function Ea(a, c, b, e, d) { return f; } ;X.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Aa(this, "not", arguments); - return Fa.call(this, a, c, b, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "not", arguments); + return Ga.call(this, a, c, b, e, d, f, g); }; -function Fa(a, c, b, e, d, f, g) { +function Ga(a, c, b, e, d, f, g) { if (c.length) { - const k = this; - return Promise.all(c).then(function(h) { + const h = this; + return Promise.all(c).then(function(k) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return Fa.call(k, a, [], b, e, d, f, g); + return Ga.call(h, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ga.call(this, a, b, e, f); + this.result = Ha.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } return f ? d ? W.call(this.index, this.result) : this.result : this; } -function Ga(a, c, b, e) { +function Ha(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, k = 0; f < this.result.length; f++) { + for (let f = 0, g, h = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let h = 0, l; h < g.length; h++) { - if (l = g[h], !a.has(l)) { + for (let k = 0, l; k < g.length; k++) { + if (l = g[k], !a.has(l)) { if (b) { b--; } else { @@ -868,7 +890,7 @@ function Ga(a, c, b, e) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { + if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { return d; } } @@ -928,26 +950,25 @@ X.prototype.boost = function(a) { X.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), za.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Aa.call(d, e, a || 100, c, b)) : e; }; C(); V.prototype.search = function(a, c, b, e) { b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); let d = []; var f = []; - let g, k, h, l, m, n, t = 0, p = !0, q; + let g, h, k, l, m, n, t = 0, p = !0, q; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; var v = b.pluck; - k = b.merge; + h = b.merge; l = v || b.field || (l = b.index) && (l.index ? null : l); m = this.tag && b.tag; - h = b.suggest; + k = b.suggest; p = !0; this.store && b.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - g = this.store && b.enrich && p; - q = b.highlight && g; + q = (g = this.store && b.enrich && p) && b.highlight; c = b.limit || c; n = b.offset || 0; c || (c = 100); @@ -989,7 +1010,7 @@ V.prototype.search = function(a, c, b, e) { e = []; if (u.length) { for (f = 0; f < u.length; f += 2) { - v = Ha.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:v}); + v = Ia.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:v}); } } return e.length ? Promise.all(e).then(function(y) { @@ -1007,7 +1028,7 @@ V.prototype.search = function(a, c, b, e) { for (let y = 0, r, E, F; y < l.length; y++) { E = l[y]; let A; - D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, h = A.suggest || h, g = this.store && (A.enrich || g)); + D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, k = A.suggest || k, g = this.store && (A.enrich || g)); if (e) { r = e[y]; } else { @@ -1023,25 +1044,25 @@ V.prototype.search = function(a, c, b, e) { if (m && F) { w = []; z = 0; - for (let G = 0, H, Va; G < m.length; G += 2) { + for (let G = 0, H, Wa; G < m.length; G += 2) { H = this.tag.get(m[G]); if (!H) { - if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), h) { + if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { continue; } else { return p ? d : new X(d); } } - if (Va = (H = H && H.get(m[G + 1])) && H.length) { + if (Wa = (H = H && H.get(m[G + 1])) && H.length) { z++, w.push(H); - } else if (!h) { + } else if (!k) { return p ? d : new X(d); } } if (z) { - r = ya(r, w); + r = za(r, w); F = r.length; - if (!F && !h) { + if (!F && !k) { return p ? r : new X(r); } z--; @@ -1074,18 +1095,19 @@ V.prototype.search = function(a, c, b, e) { } d[y] = {field:f[y], result:r}; } - return k ? Ia(d, c) : q ? Ja(d, a, this.index, this.field, this.C, q) : d; + return h ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; }; -function Ja(a, c, b, e, d, f) { - let g, k, h; +function Ka(a, c, b, e, d, f) { + console.log("template", f); + let g, h, k; for (let m = 0, n, t, p, q, v; m < a.length; m++) { n = a[m].result; t = a[m].field; q = b.get(t); p = q.encoder; - h = q.tokenize; + k = q.tokenize; v = d[e.indexOf(t)]; - p !== g && (g = p, k = g.encode(c)); + p !== g && (g = p, h = g.encode(c)); for (let u = 0; u < n.length; u++) { let w = ""; var l = J(n[u].doc, v); @@ -1095,8 +1117,8 @@ function Ja(a, c, b, e, d, f) { r = z[y]; E = l[y]; let F; - for (let A = 0, G; A < k.length; A++) { - if (G = k[A], "strict" === h) { + for (let A = 0, G; A < h.length; A++) { + if (G = h[A], "strict" === k) { if (r === G) { w += (w ? " " : "") + f.replace("$1", E); F = !0; @@ -1118,26 +1140,26 @@ function Ja(a, c, b, e, d, f) { } return a; } -function Ia(a, c) { +function Ja(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; - for (let k = 0, h, l, m; k < g.length; k++) { - if (l = g[k], "object" !== typeof l && (l = {id:l}), h = l.id, m = e[h]) { + for (let h = 0, k, l, m; h < g.length; h++) { + if (l = g[h], "object" !== typeof l && (l = {id:l}), k = l.id, m = e[k]) { m.push(f.field); } else { if (b.length === c) { return b; } - l.field = e[h] = [f.field]; + l.field = e[k] = [f.field]; b.push(l); } } } return b; } -function Ha(a, c, b, e, d) { +function Ia(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1169,7 +1191,7 @@ function W(a) { this.C = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && Ka(b, this.J) || "id"; + this.key = (b = c.key || c.id) && La(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); this.A = (b = c.store || null) && b && !0 !== b && []; this.store = b && new Map(); @@ -1180,13 +1202,13 @@ function W(a) { let e = c.index || c.field || c; D(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Ka(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; + f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = La(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { a = c.store; D(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = Ka(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = La(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } this.index = b; @@ -1202,14 +1224,14 @@ function W(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = Ka(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = La(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); this.T[d] = g; this.tag.set(g, new Map()); } } } } -function Ka(a, c) { +function La(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1247,16 +1269,19 @@ x.remove = function(a) { return this; }; x.clear = function() { - for (const a of this.index.values()) { - a.clear(); + const a = []; + for (const c of this.index.values()) { + const b = c.clear(); + b.then && a.push(b); } if (this.tag) { - for (const a of this.tag.values()) { - a.clear(); + for (const c of this.tag.values()) { + c.clear(); } } this.store && this.store.clear(); - return this; + this.cache && this.cache.clear(); + return a.length ? Promise.all(a) : this; }; x.contain = function(a) { return this.reg.has(a); @@ -1274,14 +1299,14 @@ x.set = function(a, c) { this.store.set(a, c); return this; }; -x.searchCache = La; +x.searchCache = Ma; x.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const 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); @@ -1335,7 +1360,7 @@ x.import = function(a, c) { } }; ja(V.prototype); -function La(a, c, b) { +function Ma(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); let e = this.cache.get(a); @@ -1376,31 +1401,31 @@ Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ma = {normalize:function(a) { +const Na = {normalize:function(a) { return a.toLowerCase(); }}; -const Na = 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 Oa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Pa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const Qa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const Ra = /[\x00-\x7F]+/g; +const Oa = 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 Pa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Qa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const Ra = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; const Sa = /[\x00-\x7F]+/g; const Ta = /[\x00-\x7F]+/g; -var Ua = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Ma, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Na}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Na, matcher:Oa, replacer:Pa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Na, replacer:Pa.concat([/(?!^)[aeo]/g, ""]), matcher:Oa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Ua = /[\x00-\x7F]+/g; +var Va = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Na, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Oa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Oa, matcher:Pa, replacer:Qa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Oa, replacer:Qa.concat([/(?!^)[aeo]/g, ""]), matcher:Pa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = Qa[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Qa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = Ra[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ra[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Ra, " "); + return ("" + a).replace(Sa, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Sa, ""); + return ("" + a).replace(Ta, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Ta, " "); + return ("" + a).replace(Ua, " "); }}}; -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}}}; +const Xa = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; O.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { @@ -1413,7 +1438,7 @@ O.prototype.add = function(a, c, b, e) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Xa(t, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : Ya(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { @@ -1421,34 +1446,34 @@ O.prototype.add = function(a, c, b, e) { for (f = d; f > v; f--) { g = q.substring(v, f); u = this.rtl ? d - 1 - v : v; - var k = this.score ? this.score(c, q, p, g, u) : Xa(t, e, p, d, u); - Z(this, m, g, k, a, b); + var h = this.score ? this.score(c, q, p, g, u) : Ya(t, e, p, d, u); + Z(this, m, g, h, a, b); } } break; } case "reverse": if (1 < d) { - for (k = d - 1; 0 < k; k--) { - g = q[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(c, q, p, g, k) : Xa(t, e, p, d, k); - Z(this, m, g, h, a, b); + for (h = d - 1; 0 < h; h--) { + g = q[this.rtl ? d - 1 - h : h] + g; + var k = this.score ? this.score(c, q, p, g, h) : Ya(t, e, p, d, h); + Z(this, m, g, k, a, b); } g = ""; } case "forward": if (1 < d) { - for (k = 0; k < d; k++) { - g += q[this.rtl ? d - 1 - k : k], Z(this, m, g, f, a, b); + for (h = 0; h < d; h++) { + g += q[this.rtl ? d - 1 - h : h], Z(this, m, g, f, a, b); } break; } default: if (Z(this, m, q, f, a, b), n && 1 < e && p < e - 1) { - for (d = C(), g = this.S, f = q, k = Math.min(n + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { - if ((q = c[this.rtl ? e - 1 - p - h : p + h]) && !d[q]) { + for (d = C(), g = this.S, f = q, h = Math.min(n + 1, this.rtl ? p + 1 : e - p), d[f] = 1, k = 1; k < h; k++) { + if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { d[q] = 1; - const v = this.score ? this.score(c, f, p, q, h - 1) : Xa(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; + const v = this.score ? this.score(c, f, p, q, k - 1) : Ya(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; Z(this, l, u ? f : q, v, a, b, u ? q : f); } } @@ -1462,12 +1487,12 @@ O.prototype.add = function(a, c, b, e) { return this; }; function Z(a, c, b, e, d, f, g) { - let k = g ? a.ctx : a.map, h; - if (!c[b] || g && !(h = c[b])[g]) { - g ? (c = h || (c[b] = C()), 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 = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); + let h = g ? a.ctx : a.map, k; + if (!c[b] || g && !(k = c[b])[g]) { + g ? (c = k || (c[b] = C()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); } } -function Xa(a, c, b, e, d) { +function Ya(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } ;O.prototype.search = function(a, c, b) { @@ -1479,35 +1504,35 @@ function Xa(a, c, b, e, d) { d = b.offset || 0; var f = b.context; var g = b.suggest; - var k = !0; - var h = b.resolution; + var h = !0; + var k = b.resolution; } else { - k = !0; + h = !0; } a = this.encoder.encode(a); b = a.length; - c = c || (k ? 100 : 0); + c = c || (h ? 100 : 0); if (1 === b) { - return g = c, (c = Ya(this, a[0], "")) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Za(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return g = c, (c = Ya(this, a[0], a[1])) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Za(this, a[0], a[1])) && c.length ? Aa.call(this, c, g, d) : []; } - k = C(); + h = C(); let l = 0; if (1 < b && f) { var m = a[0]; l = 1; } - h || 0 === h || (h = m ? this.S : this.resolution); + k || 0 === k || (k = m ? this.S : this.resolution); for (let q, v; l < b; l++) { - if ((v = a[l]) && !k[v]) { - k[v] = 1; - q = Ya(this, v, m); + if ((v = a[l]) && !h[v]) { + h[v] = 1; + q = Za(this, v, m); a: { f = q; - var n = e, t = g, p = h; + var n = e, t = g, p = k; let u = []; if (f && f.length) { if (f.length <= p) { @@ -1534,23 +1559,23 @@ function Xa(a, c, b, e, d) { } m && (g && q && e.length || (m = v)); } - g && m && l === b - 1 && !e.length && (h = this.resolution, m = "", l = -1, k = C()); + g && m && l === b - 1 && !e.length && (k = this.resolution, m = "", l = -1, h = C()); } a: { a = e; e = a.length; m = a; if (1 < e) { - m = wa(a, h, c, d, g); + m = xa(a, k, c, d, g); } else if (1 === e) { - g = za.call(null, a[0], c, d); + g = Aa.call(null, a[0], c, d); break a; } g = m; } return g; }; -function Ya(a, c, b) { +function Za(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); @@ -1571,14 +1596,14 @@ function Ya(a, c, b) { } } } else { - Za(this.map, a), this.depth && Za(this.ctx, a); + $a(this.map, a), this.depth && $a(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Za(a, c) { +function $a(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1593,7 +1618,7 @@ function Za(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = Za(e[1], c); + const d = e[0], f = $a(e[1], c); f ? b += f : a.delete(d); } } @@ -1605,19 +1630,20 @@ function Za(a, c) { } if (a) { var b = D(a) ? a : a.preset; - b && (Wa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Wa[b], a)); + b && (Xa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Xa[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Ua[a.encoder] : a.encode || a.encoder || Ma; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Va[a.encoder] : a.encode || a.encoder || Na; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = (b = a.tokenize) && "default" !== b && b || "strict"; + this.tokenize = b = (b = a.tokenize) && "default" !== b && b || "strict"; this.depth = "strict" === b && e.depth || 0; this.bidirectional = !1 !== e.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; + e && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); b = !1; this.map = new Map(); this.ctx = new Map(); @@ -1645,15 +1671,15 @@ x.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function $a(a) { +function ab(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { (e = a[b]) && (c += e.length); } } else { - for (const b of a) { - const e = b[0], d = $a(b[1]); + for (const b of a.entries()) { + const e = b[0], d = ab(b[1]); d ? c += d : a.delete(e); } } @@ -1663,11 +1689,11 @@ x.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - $a(this.map); - this.depth && $a(this.ctx); + ab(this.map); + this.depth && ab(this.ctx); return this; }; -x.searchCache = La; +x.searchCache = Ma; x.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { @@ -1708,56 +1734,27 @@ x.import = function(a, c) { } }; x.serialize = function(a = !0) { - if (!this.reg.size) { - return ""; - } - let c = "", b = ""; - for (var e of this.reg.keys()) { - b || (b = typeof e), c += (c ? "," : "") + ("string" === b ? '"' + e + '"' : e); - } - c = "index.reg=new Set([" + c + "]);"; - e = ""; - for (var d of this.map.entries()) { - var f = d[0], g = d[1], k = ""; - for (let m = 0, n; m < g.length; m++) { - n = g[m] || [""]; - var h = ""; - for (var l = 0; l < n.length; l++) { - h += (h ? "," : "") + ("string" === b ? '"' + n[l] + '"' : n[l]); - } - h = "[" + h + "]"; - k += (k ? "," : "") + h; + let c = "", b = "", e = ""; + if (this.reg.size) { + let f; + for (var d of this.reg.keys()) { + f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } - k = '["' + f + '",[' + k + "]]"; - e += (e ? "," : "") + k; - } - e = "index.map=new Map([" + e + "]);"; - d = ""; - for (const m of this.ctx.entries()) { - f = m[0]; - g = m[1]; - for (const n of g.entries()) { - g = n[0]; - k = n[1]; - h = ""; - for (let t = 0, p; t < k.length; t++) { - p = k[t] || [""]; - l = ""; - for (let q = 0; q < p.length; q++) { - l += (l ? "," : "") + ("string" === b ? '"' + p[q] + '"' : p[q]); - } - l = "[" + l + "]"; - h += (h ? "," : "") + l; - } - h = 'new Map([["' + g + '",[' + h + "]]])"; - h = '["' + f + '",' + h + "]"; - d += (d ? "," : "") + h; + 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 + "]);"; } - d = "index.ctx=new Map([" + d + "]);"; - return a ? "function inject(index){" + c + e + d + "}" : c + e + d; + return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; ja(O.prototype); -export default {Index:O, Charset:Ua, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +export default {Index:O, Charset:Va, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=O;export const Charset=Ua;export const Encoder=K;export const Document=V;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=O;export const Charset=Va;export const Encoder=K;export const Document=V;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index b10d0c1..dde4ef3 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,11 +1,11 @@ /**! - * FlexSearch.js v0.8.123 (Bundle) + * FlexSearch.js v0.8.132 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var x;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(k){return a(b(k))};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"undefined"===d?c:a}function C(){return Object.create(null)}function D(a){return"string"===typeof a} +var x;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var 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"undefined"===d?c:a}function C(){return Object.create(null)}function D(a){return"string"===typeof a} function H(a){return"object"===typeof a}function I(a,c){if(D(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=B(a.numeric,e)}else{try{this.split=B(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=B(a.numeric,B(this.numeric,!0))}this.prepare=B(a.prepare,null,this.prepare);this.finalize=B(a.finalize,null,this.finalize);ha||(this.mapper=new Map(ba));this.rtl=B(a.rtl,!1,this.rtl);this.dedupe=B(a.dedupe,!1,this.dedupe);this.filter=B((b=a.filter)&&new Set(b),null,this.filter);this.matcher=B((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=B((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer= -B((b=a.stemmer)&&new Map(b),null,this.stemmer);this.replacer=B(a.replacer,null,this.replacer);this.minlength=B(a.minlength,1,this.minlength);this.maxlength=B(a.maxlength,0,this.maxlength);if(this.cache=b=B(a.cache,!0,this.cache))this.H=null,this.R="number"===typeof b?b:2E5,this.F=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.D="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.D+= -(this.D?"|":"")+d;return this};x.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.D+=(this.D?"|":"")+a;this.N=null;this.cache&&L(this);return this};x.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&L(this);return this};x.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(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.M=null;this.cache&&L(this);return this};x.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&L(this);return this}; +this.numeric=B(a.numeric,e)}else{try{this.split=B(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=B(a.numeric,B(this.numeric,!0))}this.prepare=B(a.prepare,null,this.prepare);this.finalize=B(a.finalize,null,this.finalize);ha||(this.mapper=new Map(ba));b=a.filter;this.filter="function"===typeof b?b:B(b&&new Set(b),null,this.filter);this.dedupe=B(a.dedupe,!1,this.dedupe);this.matcher=B((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=B((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer= +B((b=a.stemmer)&&new Map(b),null,this.stemmer);this.replacer=B(a.replacer,null,this.replacer);this.minlength=B(a.minlength,1,this.minlength);this.maxlength=B(a.maxlength,0,this.maxlength);this.rtl=B(a.rtl,!1,this.rtl);if(this.cache=b=B(a.cache,!0,this.cache))this.H=null,this.R="number"===typeof b?b:2E5,this.F=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.D="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.D+= +(this.D?"|":"")+d;return this};x.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.D+=(this.D?"|":"")+a;this.N=null;this.cache&&L(this);return this};x.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&L(this);return this}; +x.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(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.M=null;this.cache&&L(this);return this}; +x.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&L(this);return this}; x.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(L,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ha?a.normalize("NFKD").replace(ha,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d -this.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ka,la,Q;function ma(){ka=Q=0} +[],e=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;fthis.stemmer.get(k)),d!==g&&this.filter&& +g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ka,la,Q;function ma(){ka=Q=0} function P(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);ka?Q||(Q=Date.now()-la>=this.priority*this.priority*3):(ka=setTimeout(ma,0),la=Date.now());if(Q){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 R=0; -function S(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++R]=function(){h(d);1E9b||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function xa(a,c,b){const e=[],d=C();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?W.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=xa(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Aa(this,"and",arguments);return Ca.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; -function Ca(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=wa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Aa(this,"xor",arguments);return Da.call(this,a,c,b,e,d,f,g)}; -function Da(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Ea.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function Ea(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} +function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}bc&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?W.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,h,k,l,m,n)}return d?this.resolve(c,b,e):this}; +function Da(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; +function Ea(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Fa(a,c,b,e,d){const f=[],g=C();let h=0;for(let k=0,l;kb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.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};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Ma={normalize:function(a){return a.toLowerCase()}};const Na=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 Oa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Pa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Qa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Ra=/[\x00-\x7F]+/g;const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;var Va={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Ma,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Na},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Na,matcher:Oa,replacer:Pa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Na,replacer:Pa.concat([/(?!^)[aeo]/g,""]),matcher:Oa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bv;f--){g=q.substring(v,f);u=this.rtl?d-1-v:v;var k=this.score?this.score(c,q,p,g,u):Xa(t,e,p,d,u); -Z(this,m,g,k,a,b)}break}case "reverse":if(1g?0:1),e,p,k-1,h-1),u=this.bidirectional&& -q>f;Z(this,l,u?f:q,v,a,b,u?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=C()),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=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function Xa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else Za(this.map,a),this.depth&&Za(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Za(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;ethis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.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};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:function(a){return a.toLowerCase()}};const Oa=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 Pa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Ra={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;const Ua=/[\x00-\x7F]+/g;var Wa={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Na,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Oa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Oa,matcher:Pa,replacer:Qa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bv;f--){g=q.substring(v,f);u=this.rtl?d-1-v:v;var h=this.score?this.score(c,q,p,g,u):Ya(t,e,p,d,u); +Z(this,m,g,h,a,b)}break}case "reverse":if(1g?0:1),e,p,h-1,k-1),u=this.bidirectional&& +q>f;Z(this,l,u?f:q,v,a,b,u?q: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]=C()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function Ya(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else $a(this.map,a),this.depth&&$a(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function $a(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function $a(a){let c=0;if(a.constructor===Array)for(let b=0,e;bb.add(a,c)):this.add(a,c)};function ab(a){let c=0;if(a.constructor===Array)for(let b=0,e;b c && (c = Math.max(c + e, 0)); c < e; c++) { - var f = d[c]; - if (f === b || Object.is(f, b)) { + var g = d[c]; + if (g === b || Object.is(g, b)) { return !0; } } @@ -830,8 +830,8 @@ function I(a, b, c) { if ("undefined" !== e) { if (c) { if ("function" === e && d === e) { - return function(f) { - return a(c(f)); + return function(g) { + return a(c(g)); }; } b = a.constructor; @@ -841,7 +841,7 @@ function I(a, b, c) { } if (b === Map) { b = new Map(c); - d = w(a); + d = x(a); for (e = d.next(); !e.done; e = d.next()) { e = e.value, b.set(e[0], e[1]); } @@ -849,7 +849,7 @@ function I(a, b, c) { } if (b === Set) { b = new Set(c); - d = w(a.values()); + d = x(a.values()); for (e = d.next(); !e.done; e = d.next()) { b.add(e.value); } @@ -869,12 +869,12 @@ function J() { function K(a) { return "string" === typeof a; } -function M(a) { +function L(a) { return "object" === typeof a; } function xa(a) { var b = []; - a = w(a.keys()); + a = x(a.keys()); for (var c = a.next(); !c.done; c = a.next()) { b.push(c.value); } @@ -910,15 +910,15 @@ function Ga(a) { if (!this || this.constructor !== Ga) { var b = Function.prototype.bind, c = b.apply, d = [null], e = d.concat; if (arguments instanceof Array) { - var f = arguments; + var g = arguments; } else { - f = w(arguments); - for (var g, h = []; !(g = f.next()).done;) { - h.push(g.value); + g = x(arguments); + for (var f, h = []; !(f = g.next()).done;) { + h.push(f.value); } - f = h; + g = h; } - return new (c.call(b, Ga, e.call(d, f)))(); + return new (c.call(b, Ga, e.call(d, g)))(); } if (arguments.length) { for (b = 0; b < arguments.length; b++) { @@ -947,7 +947,7 @@ u.assign = function(a) { } try { this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); - } catch (f) { + } catch (g) { console.error("Your split configuration:", c, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { @@ -957,7 +957,7 @@ u.assign = function(a) { } else { try { this.split = I(this.split, Ba); - } catch (f) { + } catch (g) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } this.numeric = I(a.numeric, I(this.numeric, !0)); @@ -965,15 +965,16 @@ u.assign = function(a) { this.prepare = I(a.prepare, null, this.prepare); this.finalize = I(a.finalize, null, this.finalize); Fa || (this.mapper = new Map(Aa)); - this.rtl = I(a.rtl, !1, this.rtl); + c = a.filter; + this.filter = "function" === typeof c ? c : I(c && new Set(c), null, this.filter); this.dedupe = I(a.dedupe, !1, this.dedupe); - this.filter = I((c = a.filter) && new Set(c), null, this.filter); this.matcher = I((c = a.matcher) && new Map(c), null, this.matcher); this.mapper = I((c = a.mapper) && new Map(c), null, this.mapper); this.stemmer = I((c = a.stemmer) && new Map(c), null, this.stemmer); this.replacer = I(a.replacer, null, this.replacer); this.minlength = I(a.minlength, 1, this.minlength); this.maxlength = I(a.maxlength, 0, this.maxlength); + this.rtl = I(a.rtl, !1, this.rtl); if (this.cache = c = I(a.cache, !0, this.cache)) { this.D = null, this.T = "number" === typeof c ? c : 2e5, this.B = new Map(), this.C = new Map(), this.H = this.G = 128; } @@ -982,12 +983,12 @@ u.assign = function(a) { this.A = ""; this.N = null; if (this.matcher) { - for (a = w(this.matcher.keys()), b = a.next(); !b.done; b = a.next()) { + for (a = x(this.matcher.keys()), b = a.next(); !b.done; b = a.next()) { this.h += (this.h ? "|" : "") + b.value; } } if (this.stemmer) { - for (a = w(this.stemmer.keys()), b = a.next(); !b.done; b = a.next()) { + for (a = x(this.stemmer.keys()), b = a.next(); !b.done; b = a.next()) { this.A += (this.A ? "|" : "") + b.value; } } @@ -1002,8 +1003,7 @@ u.addStemmer = function(a, b) { return this; }; u.addFilter = function(a) { - this.filter || (this.filter = new Set()); - this.filter.add(a); + "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); this.cache && N(this); return this; }; @@ -1056,15 +1056,15 @@ u.encode = function(a) { this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = Fa ? a.normalize("NFKD").replace(Fa, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(Da, "$1 $2").replace(Ea, "$1 $2").replace(Ca, "$1 ")); - for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, f = 0, g = void 0, h = void 0; f < e.length; f++) { - if ((g = h = e[f]) && !(g.length < this.minlength)) { + for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, g = 0, f = void 0, h = void 0; g < e.length; g++) { + if ((f = h = e[g]) && !(f.length < this.minlength)) { if (c) { - d.push(g); + d.push(f); } else { - if (!this.filter || !this.filter.has(g)) { - if (this.cache && g.length <= this.H) { + if (!this.filter || ("function" === typeof this.filter ? this.filter(f) : !this.filter.has(f))) { + if (this.cache && f.length <= this.H) { if (this.D) { - var k = this.C.get(g); + var k = this.C.get(f); if (k || "" === k) { k && d.push(k); continue; @@ -1073,26 +1073,26 @@ u.encode = function(a) { this.D = setTimeout(N, 50, this); } } - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.N, function(q) { + this.stemmer && 2 < f.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), k = f, f = f.replace(this.N, function(q) { return b.stemmer.get(q); - }), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); - if (g && (this.mapper || this.dedupe && 1 < g.length)) { + }), k !== f && this.filter && f.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(f) : this.filter.has(f)) && (f = "")); + if (f && (this.mapper || this.dedupe && 1 < f.length)) { k = ""; - for (var l = 0, m = "", n = void 0, p = void 0; l < g.length; l++) { - n = g.charAt(l), n === m && this.dedupe || ((p = this.mapper && this.mapper.get(n)) || "" === p ? p === m && this.dedupe || !(m = p) || (k += p) : k += m = n); + for (var l = 0, m = "", n = void 0, p = void 0; l < f.length; l++) { + n = f.charAt(l), n === m && this.dedupe || ((p = this.mapper && this.mapper.get(n)) || "" === p ? p === m && this.dedupe || !(m = p) || (k += p) : k += m = n); } - g = k; + f = k; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, function(q) { + this.matcher && 1 < f.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), f = f.replace(this.M, function(q) { return b.matcher.get(q); })); - if (g && this.replacer) { - for (k = 0; g && k < this.replacer.length; k += 2) { - g = g.replace(this.replacer[k], this.replacer[k + 1]); + if (f && this.replacer) { + for (k = 0; f && k < this.replacer.length; k += 2) { + f = f.replace(this.replacer[k], this.replacer[k + 1]); } } - this.cache && h.length <= this.H && (this.C.set(h, g), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); - g && d.push(g); + this.cache && h.length <= this.H && (this.C.set(h, f), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); + f && d.push(f); } } } @@ -1106,9 +1106,9 @@ function N(a) { a.B.clear(); a.C.clear(); } -;var O, P; -function Ha(a) { - var b, c, d, e, f, g; +;var Ha, O; +function Ia(a) { + var b, c, d, e, g, f; return ta(function(h) { switch(h.h) { case 1: @@ -1118,8 +1118,8 @@ function Ha(a) { d = a.args; switch(b) { case "init": - P = a.options || {}; - (e = a.factory) ? (Function("return " + e)()(self), O = new self.FlexSearch.Index(P), delete self.FlexSearch) : O = new S(P); + O = a.options || {}; + (e = a.factory) ? (Function("return " + e)()(self), Ha = new self.FlexSearch.Index(O), delete self.FlexSearch) : Ha = new P(O); postMessage({id:c}); break; default: @@ -1129,92 +1129,92 @@ function Ha(a) { break; case 2: if ("export" === b) { - if (!P.export || "function" !== typeof P.export) { + if (!O.export || "function" !== typeof O.export) { 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] = P.export, d[2] = 0, d[3] = 1) : d = null; + d[1] ? (d[0] = O.export, d[2] = 0, d[3] = 1) : d = null; } if ("import" === b) { - if (!P.import || "function" !== typeof P.import) { + if (!O.import || "function" !== typeof O.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } if (!d[0]) { h.h = 5; break; } - return E(h, P.import.call(O, d[0]), 9); + return E(h, O.import.call(Ha, d[0]), 9); } - f = d && O[b].apply(O, d); - if (!f || !f.then) { + g = d && Ha[b].apply(Ha, d); + if (!g || !g.then) { h.h = 5; break; } - return E(h, f, 7); + return E(h, g, 7); case 7: - f = h.D; + g = h.D; h.h = 5; break; case 9: - g = h.D, O.import(d[0], g); + f = h.D, Ha.import(d[0], f); case 5: - postMessage("search" === b ? {id:c, msg:f} : {id:c}), h.h = 0; + postMessage("search" === b ? {id:c, msg:g} : {id:c}), h.h = 0; } }); } -;function Ia(a) { - La.call(a, "add"); - La.call(a, "append"); - La.call(a, "search"); - La.call(a, "update"); - La.call(a, "remove"); +;function La(a) { + Ma.call(a, "add"); + Ma.call(a, "append"); + Ma.call(a, "search"); + Ma.call(a, "update"); + Ma.call(a, "remove"); } -var Ma, Na, Oa; -function Pa() { - Ma = Oa = 0; +var Na, Oa, Pa; +function Qa() { + Na = Pa = 0; } -function La(a) { +function Ma(a) { this[a + "Async"] = function() { var b = arguments, c = b[b.length - 1]; if ("function" === typeof c) { var d = c; delete b[b.length - 1]; } - Ma ? Oa || (Oa = Date.now() - Na >= this.priority * this.priority * 3) : (Ma = setTimeout(Pa, 0), Na = Date.now()); - if (Oa) { + Na ? Pa || (Pa = Date.now() - Oa >= this.priority * this.priority * 3) : (Na = setTimeout(Qa, 0), Oa = Date.now()); + if (Pa) { var e = this; - return new Promise(function(g) { + return new Promise(function(f) { setTimeout(function() { - g(e[a + "Async"].apply(e, b)); + f(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); + var g = this[a].apply(this, b); + c = g.then ? g : new Promise(function(f) { + return f(g); }); d && c.then(d); return c; }; } -;var Qa = 0; -function Ra(a) { - function b(g) { +;var Ra = 0; +function Sa(a) { + function b(f) { function h(k) { k = k.data || k; var l = k.id, m = l && e.h[l]; m && (m(k.msg), delete e.h[l]); } - this.worker = g; + this.worker = f; this.h = J(); if (this.worker) { d ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { return new Promise(function(k) { - e.h[++Qa] = function() { + e.h[++Ra] = function() { k(e); - 1e9 < Qa && (Qa = 0); + 1e9 < Ra && (Ra = 0); }; - e.worker.postMessage({id:Qa, task:"init", factory:c, options:a}); + e.worker.postMessage({id:Ra, task:"init", factory:c, options:a}); }); } this.worker.postMessage({task:"init", factory:c, options:a}); @@ -1223,118 +1223,138 @@ function Ra(a) { } } a = void 0 === a ? {} : a; - if (!this || this.constructor !== Ra) { - return new Ra(a); + if (!this || this.constructor !== Sa) { + return new Sa(a); } var c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; c && (c = c.toString()); - var d = "undefined" === typeof window, e = this, f = Sa(c, d, a.worker); - return f.then ? f.then(function(g) { - return b.call(e, g); - }) : b.call(this, f); + var d = "undefined" === typeof window, e = this, g = Ta(c, d, a.worker); + return g.then ? g.then(function(f) { + return b.call(e, f); + }) : b.call(this, g); } -T("add"); -T("append"); -T("search"); -T("update"); -T("remove"); -T("clear"); -T("export"); -T("import"); -Ia(Ra.prototype); -function T(a) { - Ra.prototype[a] = function() { +S("add"); +S("append"); +S("search"); +S("update"); +S("remove"); +S("clear"); +S("export"); +S("import"); +La(Sa.prototype); +function S(a) { + Sa.prototype[a] = function() { var b = this, c = [].slice.call(arguments), d = c[c.length - 1]; if ("function" === typeof d) { var e = d; c.pop(); } - d = new Promise(function(f) { + d = new Promise(function(g) { "export" === a && "function" === typeof c[0] && (c[0] = null); - b.h[++Qa] = f; - b.worker.postMessage({task:a, id:Qa, args:c}); + b.h[++Ra] = g; + b.worker.postMessage({task:a, id:Ra, args:c}); }); return e ? (d.then(e), this) : d; }; } -function Sa(a, b, c) { - return b ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ha.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof c ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function Ta(a, b, c) { + return b ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ia.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof c ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;function Ta(a, b) { +;function Ua(a, b) { b = void 0 === b ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 5000 | 0); - a = w(a.entries()); + a = x(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 Ua(a, b) { +function Va(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 Va(a, b) { +function Wa(a, b) { b = void 0 === b ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 1000 | 0); - a = w(a.entries()); + a = x(a.entries()); for (var e = a.next(); !e.done; e = a.next()) { - e = e.value, d.push([e[0], Ta(e[1])[0]]), d.length === b && (c.push(d), d = []); + e = e.value, d.push([e[0], Ua(e[1])[0]]), d.length === b && (c.push(d), d = []); } d.length && c.push(d); return c; } -function Wa(a, b) { +function Xa(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], Ua(d[1], e)); + d = a[c], e = b.get(d[0]), b.set(d[0], Va(d[1], e)); } return b; } -function Xa(a) { +function Ya(a) { var b = [], c = []; - a = w(a.keys()); + a = x(a.keys()); for (var d = a.next(); !d.done; d = a.next()) { c.push(d.value), 250000 === c.length && (b.push(c), c = []); } c.length && b.push(c); return b; } -function Ya(a, b) { +function Za(a, b) { b || (b = new Set()); for (var c = 0; c < a.length; c++) { b.add(a[c]); } return b; } -function Za(a, b, c, d, e, f, g) { - g = void 0 === g ? 0 : g; +function $a(a, b, c, d, e, g, f) { + f = void 0 === f ? 0 : f; var h = d && d.constructor === Array, k = h ? d.shift() : d; if (!k) { - return this.export(a, b, e, f + 1); + return this.export(a, b, e, g + 1); } - if ((k = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { + if ((k = a((b ? b + "." : "") + (f + 1) + "." + c, JSON.stringify(k))) && k.then) { var l = this; return k.then(function() { - return Za.call(l, a, b, c, h ? d : null, e, f, g + 1); + return $a.call(l, a, b, c, h ? d : null, e, g, f + 1); }); } - return Za.call(this, a, b, c, h ? d : null, e, f, g + 1); + return $a.call(this, a, b, c, h ? d : null, e, g, f + 1); } -;function $a(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; +function ab(a, b) { + var c = ""; + a = x(a.entries()); + for (var d = a.next(); !d.done; d = a.next()) { + var e = d.value; + d = e[0]; + e = e[1]; + for (var g = "", f = 0, h; f < e.length; f++) { + h = e[f] || [""]; + for (var k = "", l = 0; l < h.length; l++) { + k += (k ? "," : "") + ("string" === b ? '"' + h[l] + '"' : h[l]); + } + k = "[" + k + "]"; + g += (g ? "," : "") + k; + } + g = '["' + d + '",[' + g + "]]"; + c += (c ? "," : "") + g; + } + return c; +} +;function bb(a, b, c, d) { + for (var e = [], g = 0, f; g < a.index.length; g++) { + if (f = a.index[g], b >= f.length) { + b -= f.length; } 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) { + b = f[d ? "splice" : "slice"](b, c); + if (f = b.length) { + if (e = e.length ? e.concat(b) : b, c -= f, d && (a.length -= f), !c) { break; } } @@ -1343,9 +1363,9 @@ function Za(a, b, c, d, e, f, g) { } return e; } -function ab(a) { - if (!this) { - return new ab(a); +function T(a) { + if (!this || this.constructor !== T) { + return new T(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; @@ -1369,21 +1389,21 @@ function ab(a) { } if ("indexOf" === d) { return function(e) { - for (var f = 0, g = 0, h, k; g < b.index.length; g++) { - h = b.index[g]; + for (var g = 0, f = 0, h, k; f < b.index.length; f++) { + h = b.index[f]; k = h.indexOf(e); if (0 <= k) { - return f + k; + return g + k; } - f += h.length; + g += h.length; } return -1; }; } if ("includes" === d) { return function(e) { - for (var f = 0; f < b.index.length; f++) { - if (b.index[f].includes(e)) { + for (var g = 0; g < b.index.length; g++) { + if (b.index[g].includes(e)) { return !0; } } @@ -1391,13 +1411,13 @@ function ab(a) { }; } if ("slice" === d) { - return function(e, f) { - return $a(b, e || 0, f || b.length, !1); + return function(e, g) { + return bb(b, e || 0, g || b.length, !1); }; } if ("splice" === d) { - return function(e, f) { - return $a(b, e || 0, f || b.length, !0); + return function(e, g) { + return bb(b, e || 0, g || b.length, !0); }; } if ("constructor" === d) { @@ -1413,52 +1433,53 @@ function ab(a) { return !0; }}); } -ab.prototype.clear = function() { +T.prototype.clear = function() { this.index.length = 0; }; -ab.prototype.destroy = function() { +T.prototype.destroy = function() { this.proxy = this.index = null; }; -ab.prototype.push = function() { +T.prototype.push = function() { }; function U(a) { a = void 0 === a ? 8 : a; - if (!this) { + if (!this || this.constructor !== U) { return new U(a); } this.index = J(); - this.B = []; + this.h = []; this.size = 0; - 32 < a ? (this.h = bb, this.A = BigInt(a)) : (this.h = cb, this.A = a); + 32 < a ? (this.A = cb, this.B = BigInt(a)) : (this.A = db, this.B = a); } U.prototype.get = function(a) { - var b = this.h(a); + var b = this.A(a); return (b = this.index[b]) && b.get(a); }; U.prototype.set = function(a, b) { - var c = this.h(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.B.push(d)); + 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 V(a) { a = void 0 === a ? 8 : a; - if (!this) { + if (!this || this.constructor !== V) { return new V(a); } this.index = J(); this.h = []; - 32 < a ? (this.B = bb, this.A = BigInt(a)) : (this.B = cb, this.A = a); + this.size = 0; + 32 < a ? (this.A = cb, this.B = BigInt(a)) : (this.A = db, this.B = a); } V.prototype.add = function(a) { - var b = this.B(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)); + 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++); }; u = U.prototype; u.has = V.prototype.has = function(a) { - var b = this.B(a); + var b = this.A(a); return (b = this.index[b]) && b.has(a); }; u.delete = V.prototype.delete = function(a) { - var b = this.B(a); + var b = this.A(a); (b = this.index[b]) && b.delete(a) && this.size--; }; u.clear = V.prototype.clear = function() { @@ -1466,149 +1487,149 @@ u.clear = V.prototype.clear = function() { this.h = []; this.size = 0; }; -u.values = V.prototype.values = function db() { - var b, c = this, d, e, f; - return ra(db, function(g) { - switch(g.h) { +u.values = V.prototype.values = function eb() { + var b, c = this, d, e, g; + return ra(eb, function(f) { + switch(f.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - g.h = 0; + f.h = 0; break; } - d = w(c.h[b].values()); + d = x(c.h[b].values()); e = d.next(); case 5: if (e.done) { b++; - g.h = 2; + f.h = 2; break; } - f = e.value; - return E(g, f, 6); + g = e.value; + return E(f, g, 6); case 6: - e = d.next(), g.h = 5; + e = d.next(), f.h = 5; } }); }; -u.keys = V.prototype.keys = function eb() { - var b, c = this, d, e, f; - return ra(eb, function(g) { - switch(g.h) { +u.keys = V.prototype.keys = function fb() { + var b, c = this, d, e, g; + return ra(fb, function(f) { + switch(f.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - g.h = 0; + f.h = 0; break; } - d = w(c.h[b].keys()); + d = x(c.h[b].keys()); e = d.next(); case 5: if (e.done) { b++; - g.h = 2; + f.h = 2; break; } - f = e.value; - return E(g, f, 6); + g = e.value; + return E(f, g, 6); case 6: - e = d.next(), g.h = 5; + e = d.next(), f.h = 5; } }); }; -u.entries = V.prototype.entries = function fb() { - var b, c = this, d, e, f; - return ra(fb, function(g) { - switch(g.h) { +u.entries = V.prototype.entries = function gb() { + var b, c = this, d, e, g; + return ra(gb, function(f) { + switch(f.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - g.h = 0; + f.h = 0; break; } - d = w(c.h[b].entries()); + d = x(c.h[b].entries()); e = d.next(); case 5: if (e.done) { b++; - g.h = 2; + f.h = 2; break; } - f = e.value; - return E(g, f, 6); + g = e.value; + return E(f, g, 6); case 6: - e = d.next(), g.h = 5; + e = d.next(), f.h = 5; } }); }; -function cb(a) { - var b = Math.pow(2, this.A) - 1; +function db(a) { + var b = Math.pow(2, this.B) - 1; if ("number" == typeof a) { return a & b; } - for (var c = 0, d = this.A + 1, e = 0; e < a.length; e++) { + for (var c = 0, d = this.B + 1, e = 0; e < a.length; e++) { c = (c * d ^ a.charCodeAt(e)) & b; } - return 32 === this.A ? c + Math.pow(2, 31) : c; + return 32 === this.B ? c + Math.pow(2, 31) : c; } -function bb() { +function cb() { throw Error("The keystore is limited to 32 for EcmaScript5"); } ;W.prototype.add = function(a, b, c) { - M(a) && (b = a, a = ya(b, this.key)); + L(a) && (b = a, a = ya(b, this.key)); if (b && (a || 0 === a)) { if (!c && this.reg.has(a)) { return this.update(a, b); } for (var d = 0, e; d < this.field.length; d++) { e = this.J[d]; - var f = this.index.get(this.field[d]); + var g = this.index.get(this.field[d]); if ("function" === typeof e) { - (e = e(b)) && f.add(a, e, !1, !0); + (e = e(b)) && g.add(a, e, !1, !0); } else { - var g = e.R; - if (!g || g(b)) { - e.constructor === String ? e = ["" + e] : K(e) && (e = [e]), gb(b, e, this.S, 0, f, a, e[0], c); + var f = e.R; + if (!f || f(b)) { + e.constructor === String ? e = ["" + e] : K(e) && (e = [e]), hb(b, e, this.S, 0, g, a, e[0], c); } } } if (this.tag) { for (d = 0; d < this.L.length; d++) { - g = this.L[d]; + f = this.L[d]; var h = this.aa[d]; - f = this.tag.get(h); + g = this.tag.get(h); e = J(); - if ("function" === typeof g) { - if (g = g(b), !g) { + if ("function" === typeof f) { + if (f = f(b), !f) { continue; } } else { - var k = g.R; + var k = f.R; if (k && !k(b)) { continue; } - g.constructor === String && (g = "" + g); - g = ya(b, g); + f.constructor === String && (f = "" + f); + f = ya(b, f); } - if (f && g) { - for (K(g) && (g = [g]), h = 0, k = void 0; h < g.length; h++) { - var l = g[h]; + if (g && f) { + for (K(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { + var l = f[h]; if (!e[l]) { e[l] = 1; var m; - (m = f.get(l)) ? k = m : f.set(l, k = []); + (m = g.get(l)) ? k = m : g.set(l, k = []); if (!c || !k.includes(a)) { if (k.length === Math.pow(2, 31) - 1) { - m = new ab(k); + m = new T(k); if (this.fastupdate) { - for (var n = w(this.reg.values()), p = n.next(); !p.done; p = n.next()) { + for (var n = x(this.reg.values()), p = n.next(); !p.done; p = n.next()) { p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); } } - f.set(l, k = m); + g.set(l, k = m); } k.push(a); this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); @@ -1616,7 +1637,7 @@ function bb() { } } } else { - f || console.warn("Tag '" + h + "' was not found"); + g || console.warn("Tag '" + h + "' was not found"); } } } @@ -1624,11 +1645,11 @@ function bb() { if (this.I) { var q = J(); for (c = 0; c < this.I.length; c++) { - if (d = this.I[c], f = d.R, !f || f(b)) { - f = void 0; + if (d = this.I[c], g = d.R, !g || g(b)) { + g = void 0; if ("function" === typeof d) { - f = d(b); - if (!f) { + g = d(b); + if (!g) { continue; } d = [d.ja]; @@ -1636,7 +1657,7 @@ function bb() { q[d] = b[d]; continue; } - hb(b, q, d, 0, d[0], f); + ib(b, q, d, 0, d[0], g); } } } @@ -1646,88 +1667,92 @@ function bb() { } return this; }; -function hb(a, b, c, d, e, f) { +function ib(a, b, c, d, e, g) { a = a[e]; if (d === c.length - 1) { - b[e] = f || a; + b[e] = g || a; } else if (a) { if (a.constructor === Array) { for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { - hb(a, b, c, d, e); + ib(a, b, c, d, e); } } else { - b = b[e] || (b[e] = J()), e = c[++d], hb(a, b, c, d, e); + b = b[e] || (b[e] = J()), e = c[++d], ib(a, b, c, d, e); } } } -function gb(a, b, c, d, e, f, g, h) { - if (a = a[g]) { +function hb(a, b, c, d, e, g, f, h) { + if (a = a[f]) { if (d === b.length - 1) { if (a.constructor === Array) { if (c[d]) { for (b = 0; b < a.length; b++) { - e.add(f, a[b], !0, !0); + e.add(g, a[b], !0, !0); } return; } a = a.join(" "); } - e.add(f, a, h, !0); + e.add(g, a, h, !0); } else { if (a.constructor === Array) { - for (g = 0; g < a.length; g++) { - gb(a, b, c, d, e, f, g, h); + for (f = 0; f < a.length; f++) { + hb(a, b, c, d, e, g, f, h); } } else { - g = b[++d], gb(a, b, c, d, e, f, g, h); + f = b[++d], hb(a, b, c, d, e, g, f, h); } } } else { - e.db && e.remove(f); + e.db && e.remove(g); } } -;function ib(a, b, c, d, e, f, g) { - var h = a.length, k = [], l; - var m = J(); - for (var n = 0, p = void 0, q; n < b; n++) { - for (var r = 0; r < h; r++) { - if (q = a[r], n < q.length && (p = q[n])) { - for (var x = 0; x < p.length; x++) { - q = p[x]; - (l = m[q]) ? m[q]++ : (l = 0, m[q] = 1); - l = k[l] || (k[l] = []); - if (!g) { - var t = n + (r || !e ? 0 : f || 0); - l = l[t] || (l[t] = []); +;function jb(a, b, c, d, e, g, f) { + var h = a.length, k = []; + var l = J(); + for (var m = 0, n = void 0, p, q; m < b; m++) { + for (var t = 0; t < h; t++) { + var w = a[t]; + if (m < w.length && (n = w[m])) { + for (var r = 0; r < n.length; r++) { + p = n[r]; + (w = l[p]) ? l[p]++ : (w = 0, l[p] = 1); + q = k[w] || (k[w] = []); + if (!f) { + var A = m + (t || !e ? 0 : g || 0); + q = q[A] || (q[A] = []); + } + q.push(p); + if (f && c && w === h - 1 && q.length - d === c) { + return q; } - l.push(q); } } } } if (a = k.length) { if (e) { - k = 1 < k.length ? jb(k, c, d, g, f) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + k = 1 < k.length ? kb(k, c, d, f, g) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; } else { if (a < h) { return []; } k = k[a - 1]; if (c || d) { - if (g) { + if (f) { if (k.length > c || d) { k = k.slice(d, c + d); } } else { e = []; - for (f = 0; f < k.length; f++) { - if (g = k[f], g.length > d) { - d -= g.length; + for (g = 0; g < k.length; g++) { + if (f = k[g], f.length > d) { + d -= f.length; } else { - if (g.length > c || d) { - g = g.slice(d, c + d), c -= g.length, d && (d -= g.length); + if (f.length > c || d) { + f = f.slice(d, c + d), c -= f.length, d && (d -= f.length); } - e.push(g); + e.push(f); if (!c) { break; } @@ -1740,19 +1765,19 @@ function gb(a, b, c, d, e, f, g, h) { } return k; } -function jb(a, b, c, d, e) { - var f = [], g = J(), h = a.length, k; +function kb(a, b, c, d, e) { + var g = [], f = J(), h = a.length, k; if (d) { for (e = h - 1; 0 <= e; e--) { if (k = (d = a[e]) && d.length) { for (h = 0; h < k; h++) { var l = d[h]; - if (!g[l]) { - if (g[l] = 1, c) { + if (!f[l]) { + if (f[l] = 1, c) { c--; } else { - if (f.push(l), f.length === b) { - return f; + if (g.push(l), g.length === b) { + return g; } } } @@ -1764,15 +1789,15 @@ function jb(a, b, c, d, e) { n = a[m]; for (var q = 0; q < n.length; q++) { if (k = (d = n[q]) && d.length) { - for (var r = 0; r < k; r++) { - if (l = d[r], !g[l]) { - if (g[l] = 1, c) { + for (var t = 0; t < k; t++) { + if (l = d[t], !f[l]) { + if (f[l] = 1, c) { c--; } else { - var x = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; - (f[x] || (f[x] = [])).push(l); + var w = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; + (g[w] || (g[w] = [])).push(l); if (++p === b) { - return f; + return g; } } } @@ -1781,13 +1806,13 @@ function jb(a, b, c, d, e) { } } } - return f; + return g; } -function kb(a, b, c) { - for (var d = J(), e = [], f = 0, g; f < b.length; f++) { - g = b[f]; - for (var h = 0; h < g.length; h++) { - d[g[h]] = 1; +function lb(a, b, c) { + for (var d = J(), e = [], g = 0, f; g < b.length; g++) { + f = b[g]; + for (var h = 0; h < f.length; h++) { + d[f[h]] = 1; } } if (c) { @@ -1796,34 +1821,34 @@ function kb(a, b, c) { } } else { for (b = 0; b < a.result.length; b++) { - 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); + for (c = a.result[b], f = 0; f < c.length; f++) { + g = c[f], d[g] && ((e[b] || (e[b] = [])).push(g), d[g] = 0); } } } return e; } -;function lb(a, b, c, d) { +;function mb(a, b, c, d) { if (!a.length) { return a; } if (1 === a.length) { return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? X.call(this, a) : a; } - for (var e = [], f = 0, g = void 0, h = void 0; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { + for (var e = [], g = 0, f = void 0, h = void 0; g < a.length; g++) { + if ((f = a[g]) && (h = f.length)) { if (c) { if (c >= h) { c -= h; continue; } - c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); + c < h && (f = b ? f.slice(c, c + b) : f.slice(c), h = f.length, c = 0); } - h > b && (g = g.slice(0, b), h = b); + h > b && (f = f.slice(0, b), h = b); if (!e.length && h >= b) { - return d ? X.call(this, g) : g; + return d ? X.call(this, f) : f; } - e.push(g); + e.push(f); b -= h; if (!b) { break; @@ -1833,7 +1858,7 @@ function kb(a, b, c) { e = 1 < e.length ? [].concat.apply([], e) : e[0]; return d ? X.call(this, e) : e; } -;function mb(a, b, c) { +;function nb(a, b, c) { var d = c[0]; if (d.then) { return Promise.all(c).then(function(q) { @@ -1844,7 +1869,7 @@ function kb(a, b, c) { return a[b].apply(a, d); } d = []; - for (var e = [], f = 0, g = 0, h, k, l, m = 0, n = void 0; m < c.length; m++) { + for (var e = [], g = 0, f = 0, h, k, l, m = 0, n = void 0; m < c.length; m++) { if (n = c[m]) { var p = void 0; if (n.constructor === Y) { @@ -1852,7 +1877,7 @@ function kb(a, b, c) { } else if (n.constructor === Array) { p = n; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { + if (g = n.limit || 0, f = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { n.resolve = !1, n.enrich = !1, p = n.index.search(n).result, n.resolve = k, n.enrich = h; } else if (n.and) { p = a.and(n.and); @@ -1876,25 +1901,25 @@ function kb(a, b, c) { } } } - return {W:d, $:e, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; + return {W:d, $:e, limit:g, offset:f, enrich:h, resolve:k, suggest:l}; } ;Y.prototype.or = function() { - var a = mb(this, "or", arguments); - return nb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve); + var a = nb(this, "or", arguments); + return ob.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve); }; -function nb(a, b, c, d, e, f) { +function ob(a, b, c, d, e, g) { if (b.length) { - var g = this; + var f = this; return Promise.all(b).then(function(h) { a = []; for (var k = 0, l = void 0; k < h.length; k++) { (l = h[k]).length && (a[k] = l); } - return nb.call(g, a, [], c, d, e, f); + return ob.call(f, a, [], c, d, e, g); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = jb(a, c, d, !1, this.h), d = 0)); - return f ? this.resolve(c, d, e) : this; + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = kb(a, c, d, !1, this.h), d = 0)); + return g ? this.resolve(c, d, e) : this; } ;Y.prototype.and = function() { var a = this.result.length; @@ -1905,12 +1930,12 @@ function nb(a, b, c, d, e, f) { var c = b.resolve; var d = b.limit; var e = b.offset; - var f = b.enrich && c; + var g = b.enrich && c; } } - return a ? (a = mb(this, "and", arguments), ob.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest)) : c ? this.resolve(d, e, f) : this; + return a ? (a = nb(this, "and", arguments), pb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest)) : c ? this.resolve(d, e, g) : this; }; -function ob(a, b, c, d, e, f, g) { +function pb(a, b, c, d, e, g, f) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -1918,7 +1943,7 @@ function ob(a, b, c, d, e, f, g) { for (var l = 0, m = void 0; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return ob.call(h, a, [], c, d, e, f, g); + return pb.call(h, a, [], c, d, e, g, f); }); } if (a.length) { @@ -1926,20 +1951,20 @@ function ob(a, b, c, d, e, f, g) { this.result = a[0]; } else { if (b = za(a)) { - return this.result = ib(a, b, c, d, g, this.h, f), f ? e ? X.call(this.index, this.result) : this.result : this; + return this.result = jb(a, b, c, d, f, this.h, g), g ? e ? X.call(this.index, this.result) : this.result : this; } this.result = []; } } else { - g || (this.result = a); + f || (this.result = a); } - return f ? this.resolve(c, d, e) : this; + return g ? this.resolve(c, d, e) : this; } ;Y.prototype.xor = function() { - var a = mb(this, "xor", arguments); - return pb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); + var a = nb(this, "xor", arguments); + return qb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); }; -function pb(a, b, c, d, e, f, g) { +function qb(a, b, c, d, e, g, f) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -1947,28 +1972,28 @@ function pb(a, b, c, d, e, f, g) { for (var l = 0, m = void 0; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return pb.call(h, a, [], c, d, e, f, g); + return qb.call(h, a, [], c, d, e, g, f); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = qb.call(this, a, c, d, f, this.h), f ? e ? X.call(this.index, this.result) : this.result : this; + return this.result = rb.call(this, a, c, d, g, this.h), g ? e ? X.call(this.index, this.result) : this.result : this; } } else { - g || (this.result = a); + f || (this.result = a); } - return f ? this.resolve(c, d, e) : this; + return g ? this.resolve(c, d, e) : this; } -function qb(a, b, c, d, e) { - for (var f = [], g = J(), h = 0, k = 0, l; k < a.length; k++) { +function rb(a, b, c, d, e) { + for (var g = [], f = J(), h = 0, k = 0, l; k < a.length; k++) { if (l = a[k]) { h < l.length && (h = l.length); for (var m = 0, n; m < l.length; m++) { if (n = l[m]) { for (var p = 0, q; p < n.length; p++) { - q = n[p], g[q] = g[q] ? 2 : 1; + q = n[p], f[q] = f[q] ? 2 : 1; } } } @@ -1979,20 +2004,20 @@ function qb(a, b, c, d, e) { if (n = a[m]) { if (n = n[k]) { for (p = 0; p < n.length; p++) { - if (q = n[p], 1 === g[q]) { + if (q = n[p], 1 === f[q]) { if (c) { c--; } else { if (d) { - if (f.push(q), f.length === b) { - return f; + if (g.push(q), g.length === b) { + return g; } } else { - var r = k + (m ? e : 0); - f[r] || (f[r] = []); - f[r].push(q); + var t = k + (m ? e : 0); + g[t] || (g[t] = []); + g[t].push(q); if (++l === b) { - return f; + return g; } } } @@ -2002,13 +2027,13 @@ function qb(a, b, c, d, e) { } } } - return f; + return g; } ;Y.prototype.not = function() { - var a = mb(this, "not", arguments); - return rb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); + var a = nb(this, "not", arguments); + return sb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); }; -function rb(a, b, c, d, e, f, g) { +function sb(a, b, c, d, e, g, f) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -2016,23 +2041,23 @@ function rb(a, b, c, d, e, f, g) { for (var l = 0, m = void 0; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return rb.call(h, a, [], c, d, e, f, g); + return sb.call(h, a, [], c, d, e, g, f); }); } if (a.length && this.result.length) { - this.result = sb.call(this, a, c, d, f); - } else if (f) { + this.result = tb.call(this, a, c, d, g); + } else if (g) { return this.resolve(c, d, e); } - return f ? e ? X.call(this.index, this.result) : this.result : this; + return g ? e ? X.call(this.index, this.result) : this.result : this; } -function sb(a, b, c, d) { +function tb(a, b, c, d) { var e = []; a = new Set(a.flat().flat()); - for (var f = 0, g, h = 0; f < this.result.length; f++) { - if (g = this.result[f]) { - for (var k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { + for (var g = 0, f, h = 0; g < this.result.length; g++) { + if (f = this.result[g]) { + for (var k = 0, l; k < f.length; k++) { + if (l = f[k], !a.has(l)) { if (c) { c--; } else { @@ -2041,7 +2066,7 @@ function sb(a, b, c, d) { return e; } } else { - if (e[f] || (e[f] = []), e[f].push(l), ++h === b) { + if (e[g] || (e[g] = []), e[g].push(l), ++h === b) { return e; } } @@ -2099,39 +2124,38 @@ Y.prototype.boost = function(a) { Y.prototype.resolve = function(a, b, c) { var d = this.result, e = this.index; this.result = this.index = null; - return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), lb.call(e, d, a || 100, b, c)) : d; + return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), mb.call(e, d, a || 100, b, c)) : d; }; J(); W.prototype.search = function(a, b, c, d) { - c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0)); - var e = [], f = [], g = 0, h = !0; + c || (!b && L(a) ? (c = a, a = "") : L(b) && (c = b, b = 0)); + var e = [], g = [], f, h = 0, k = !0; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; - var k = c.pluck; - var l = c.merge; - var m = k || c.field || (m = c.index) && (m.index ? null : m); - var n = this.tag && c.tag; - var p = c.suggest; - h = !1 !== c.resolve; - if (!h && !k) { - if (m = m || this.field) { - K(m) ? k = m : (m.constructor === Array && 1 === m.length && (m = m[0]), k = m.field || m.index); + var l = c.pluck; + var m = c.merge; + var n = l || c.field || (n = c.index) && (n.index ? null : n); + var p = this.tag && c.tag; + var q = c.suggest; + k = !1 !== c.resolve; + if (!k && !l) { + if (n = n || this.field) { + K(n) ? l = n : (n.constructor === Array && 1 === n.length && (n = n[0]), l = n.field || n.index); } - if (!k) { + if (!l) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - this.store && c.enrich && !h && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - var q = this.store && c.enrich && h; - var r = c.highlight && q; + this.store && c.enrich && !k && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var t = (f = this.store && c.enrich && k) && c.highlight; b = c.limit || b; - var x = c.offset || 0; + var w = c.offset || 0; b || (b = 100); - if (n && (!this.db || !d)) { - n.constructor !== Array && (n = [n]); - for (var t = [], A = 0, z = void 0; A < n.length; A++) { - z = n[A]; + if (p && (!this.db || !d)) { + p.constructor !== Array && (p = [p]); + for (var r = [], A = 0, z = void 0; A < p.length; A++) { + z = p[A]; if (K(z)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } @@ -2139,10 +2163,10 @@ W.prototype.search = function(a, b, c, d) { var v = z.tag; if (v.constructor === Array) { for (var y = 0; y < v.length; y++) { - t.push(z.field, v[y]); + r.push(z.field, v[y]); } } else { - t.push(z.field, v); + r.push(z.field, v); } } else { v = Object.keys(z); @@ -2150,37 +2174,37 @@ W.prototype.search = function(a, b, c, d) { for (var D = void 0, G = void 0; y < v.length; y++) { if (D = v[y], G = z[D], G.constructor === Array) { for (var H = 0; H < G.length; H++) { - t.push(D, G[H]); + r.push(D, G[H]); } } else { - t.push(D, G); + r.push(D, G); } } } } - if (!t.length) { + if (!r.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - n = t; + p = r; if (!a) { - h = []; - if (t.length) { - for (f = 0; f < t.length; f += 2) { - k = void 0; + k = []; + if (r.length) { + for (g = 0; g < r.length; g += 2) { + l = void 0; if (this.db) { - k = this.index.get(t[f]); - if (!k) { - console.warn("Tag '" + t[f] + ":" + t[f + 1] + "' will be skipped because there is no field '" + t[f] + "'."); + l = this.index.get(r[g]); + if (!l) { + console.warn("Tag '" + r[g] + ":" + r[g + 1] + "' will be skipped because there is no field '" + r[g] + "'."); continue; } - h.push(k = k.db.tag(t[f + 1], b, x, q)); + k.push(l = l.db.tag(r[g + 1], b, w, f)); } else { - k = tb.call(this, t[f], t[f + 1], b, x, q); + l = ub.call(this, r[g], r[g + 1], b, w, f); } - e.push({field:t[f], tag:t[f + 1], result:k}); + e.push({field:r[g], tag:r[g + 1], result:l}); } } - return h.length ? Promise.all(h).then(function(Q) { + return k.length ? Promise.all(k).then(function(Q) { for (var R = 0; R < Q.length; R++) { e[R].result = Q[R]; } @@ -2188,191 +2212,192 @@ W.prototype.search = function(a, b, c, d) { }) : e; } } - m && m.constructor !== Array && (m = [m]); + n && n.constructor !== Array && (n = [n]); } - m || (m = this.field); - t = !d && (this.worker || this.db) && []; + n || (n = this.field); + r = !d && (this.worker || this.db) && []; A = 0; - for (y = z = v = void 0; A < m.length; A++) { - if (z = m[A], !this.db || !this.tag || this.J[A]) { + for (y = z = v = void 0; A < n.length; A++) { + if (z = n[A], !this.db || !this.tag || this.J[A]) { v = void 0; - K(z) || (v = z, z = v.field, a = v.query || a, b = v.limit || b, x = v.offset || x, p = v.suggest || p, q = this.store && (v.enrich || q)); + K(z) || (v = z, z = v.field, a = v.query || a, b = v.limit || b, w = v.offset || w, q = v.suggest || q, f = this.store && (v.enrich || f)); if (d) { v = d[A]; } else { y = v || c; v = this.index.get(z); - if (n) { + if (p) { if (this.db) { - y.tag = n; + y.tag = p; var Ja = v.db.support_tag_search; - y.field = m; + y.field = n; } Ja || (y.enrich = !1); } - if (t) { - t[A] = v.search(a, b, y); - y && q && (y.enrich = q); + if (r) { + r[A] = v.search(a, b, y); + y && f && (y.enrich = f); continue; } else { - v = v.search(a, b, y), y && q && (y.enrich = q); + v = v.search(a, b, y), y && f && (y.enrich = f); } } - y = v && (h ? v.length : v.result.length); - if (n && y) { + y = v && (k ? v.length : v.result.length); + if (p && y) { D = []; G = 0; if (this.db && d) { if (!Ja) { - for (H = m.length; H < d.length; H++) { - var L = d[H]; - if (L && L.length) { - G++, D.push(L); - } else if (!p) { - return h ? e : new Y(e); + for (H = n.length; H < d.length; H++) { + var M = d[H]; + if (M && M.length) { + G++, D.push(M); + } else if (!q) { + return k ? e : new Y(e); } } } } else { H = 0; - for (var Wb = L = void 0; H < n.length; H += 2) { - L = this.tag.get(n[H]); - if (!L) { - if (console.warn("Tag '" + n[H] + ":" + n[H + 1] + "' will be skipped because there is no field '" + n[H] + "'."), p) { + for (var Xb = M = void 0; H < p.length; H += 2) { + M = this.tag.get(p[H]); + if (!M) { + if (console.warn("Tag '" + p[H] + ":" + p[H + 1] + "' will be skipped because there is no field '" + p[H] + "'."), q) { continue; } else { - return h ? e : new Y(e); + return k ? e : new Y(e); } } - if (Wb = (L = L && L.get(n[H + 1])) && L.length) { - G++, D.push(L); - } else if (!p) { - return h ? e : new Y(e); + if (Xb = (M = M && M.get(p[H + 1])) && M.length) { + G++, D.push(M); + } else if (!q) { + return k ? e : new Y(e); } } } if (G) { - v = kb(v, D, h); + v = lb(v, D, k); y = v.length; - if (!y && !p) { - return h ? v : new Y(v); + if (!y && !q) { + return k ? v : new Y(v); } G--; } } if (y) { - f[g] = z, e.push(v), g++; - } else if (1 === m.length) { - return h ? e : new Y(e); + g[h] = z, e.push(v), h++; + } else if (1 === n.length) { + return k ? e : new Y(e); } } } - if (t) { - if (this.db && n && n.length && !Ja) { - for (q = 0; q < n.length; q += 2) { - f = this.index.get(n[q]); - if (!f) { - if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), p) { + if (r) { + if (this.db && p && p.length && !Ja) { + for (f = 0; f < p.length; f += 2) { + g = this.index.get(p[f]); + if (!g) { + if (console.warn("Tag '" + p[f] + ":" + p[f + 1] + "' was not found because there is no field '" + p[f] + "'."), q) { continue; } else { - return h ? e : new Y(e); + return k ? e : new Y(e); } } - t.push(f.db.tag(n[q + 1], b, x, !1)); + r.push(g.db.tag(p[f + 1], b, w, !1)); } } - var Xb = this; - return Promise.all(t).then(function(Q) { - return Q.length ? Xb.search(a, b, c, Q) : Q; + var Yb = this; + return Promise.all(r).then(function(Q) { + return Q.length ? Yb.search(a, b, c, Q) : Q; }); } - if (!g) { - return h ? e : new Y(e); + if (!h) { + return k ? e : new Y(e); } - if (k && (!q || !this.store)) { + if (l && (!f || !this.store)) { return e[0]; } - t = []; - x = 0; - for (p = void 0; x < f.length; x++) { - p = e[x]; - q && p.length && !p[0].doc && (this.db ? t.push(p = this.index.get(this.field[0]).db.enrich(p)) : p = X.call(this, p)); - if (k) { - return h ? p : new Y(p); + r = []; + w = 0; + for (q = void 0; w < g.length; w++) { + q = e[w]; + f && q.length && !q[0].doc && (this.db ? r.push(q = this.index.get(this.field[0]).db.enrich(q)) : q = X.call(this, q)); + if (l) { + return k ? q : new Y(q); } - e[x] = {field:f[x], result:p}; + e[w] = {field:g[w], result:q}; } - if (q && this.db && t.length) { + if (f && this.db && r.length) { var Ka = this; - return Promise.all(t).then(function(Q) { + return Promise.all(r).then(function(Q) { for (var R = 0; R < Q.length; R++) { e[R].result = Q[R]; } - return l ? ub(e, b) : r ? vb(e, a, Ka.index, Ka.field, Ka.J, r) : e; + return m ? vb(e, b) : t ? wb(e, a, Ka.index, Ka.field, Ka.J, t) : e; }); } - return l ? ub(e, b) : r ? vb(e, a, this.index, this.field, this.J, r) : e; + return m ? vb(e, b) : t ? wb(e, a, this.index, this.field, this.J, t) : e; }; -function vb(a, b, c, d, e, f) { - for (var g, h, k, l = 0, m, n, p; l < a.length; l++) { - for (m = a[l].result, n = a[l].field, k = c.get(n), p = k.encoder, k = k.tokenize, n = e[d.indexOf(n)], p !== g && (g = p, h = g.encode(b)), p = 0; p < m.length; p++) { - var q = "", r = ya(m[p].doc, n), x = g.encode(r); - r = r.split(g.split); - for (var t = 0, A, z; t < x.length; t++) { - A = x[t]; - z = r[t]; +function wb(a, b, c, d, e, g) { + console.log("template", g); + for (var f, h, k, l = 0, m, n, p; l < a.length; l++) { + for (m = a[l].result, n = a[l].field, k = c.get(n), p = k.encoder, k = k.tokenize, n = e[d.indexOf(n)], p !== f && (f = p, h = f.encode(b)), p = 0; p < m.length; p++) { + var q = "", t = ya(m[p].doc, n), w = f.encode(t); + t = t.split(f.split); + for (var r = 0, A, z; r < w.length; r++) { + A = w[r]; + z = t[r]; for (var v = void 0, y = 0, D; y < h.length; y++) { if (D = h[y], "strict" === k) { if (A === D) { - q += (q ? " " : "") + f.replace("$1", z); + q += (q ? " " : "") + g.replace("$1", z); v = !0; break; } } else { var G = A.indexOf(D); if (-1 < G) { - q += (q ? " " : "") + z.substring(0, G) + f.replace("$1", z.substring(G, D.length)) + z.substring(G + D.length); + q += (q ? " " : "") + z.substring(0, G) + g.replace("$1", z.substring(G, D.length)) + z.substring(G + D.length); v = !0; break; } } } - v || (q += (q ? " " : "") + r[t]); + v || (q += (q ? " " : "") + t[r]); } m[p].highlight = q; } } return a; } -function ub(a, b) { - for (var c = [], d = J(), e = 0, f, g; e < a.length; e++) { - f = a[e]; - g = f.result; - for (var h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], "object" !== typeof l && (l = {id:l}), k = l.id, m = d[k]) { - m.push(f.field); +function vb(a, b) { + for (var c = [], d = J(), e = 0, g, f; e < a.length; e++) { + g = a[e]; + f = g.result; + for (var h = 0, k, l, m; h < f.length; h++) { + if (l = f[h], "object" !== typeof l && (l = {id:l}), k = l.id, m = d[k]) { + m.push(g.field); } else { if (c.length === b) { return c; } - l.field = d[k] = [f.field]; + l.field = d[k] = [g.field]; c.push(l); } } } return c; } -function tb(a, b, c, d, e) { - var f = this.tag.get(a); - if (!f) { +function ub(a, b, c, d, e) { + var g = this.tag.get(a); + if (!g) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { + if ((a = (g = g && g.get(b)) && g.length - d) && 0 < a) { if (a > c || d) { - f = f.slice(d, d + c); + g = g.slice(d, d + c); } - e && (f = X.call(this, f)); - return f; + e && (g = X.call(this, g)); + return g; } } function X(a) { @@ -2392,7 +2417,7 @@ function X(a) { this.J = []; this.field = []; this.S = []; - this.key = (c = b.key || b.id) && wb(c, this.S) || "id"; + this.key = (c = b.key || b.id) && xb(c, this.S) || "id"; (d = a.keystore || 0) && (this.keystore = d); this.fastupdate = !!a.fastupdate; this.reg = !this.fastupdate || a.worker || a.db ? d ? new V(d) : new Set() : d ? new U(d) : new Map(); @@ -2402,7 +2427,7 @@ function X(a) { a.cache = !1; this.worker = a.worker; this.priority = a.priority || 4; - this.index = xb.call(this, a, b); + this.index = yb.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { @@ -2416,7 +2441,7 @@ function X(a) { if (!e) { throw Error("The tag field from the document descriptor is undefined."); } - d.custom ? this.L[b] = d.custom : (this.L[b] = wb(e, this.S), d.filter && ("string" === typeof this.L[b] && (this.L[b] = new String(this.L[b])), this.L[b].R = d.filter)); + d.custom ? this.L[b] = d.custom : (this.L[b] = xb(e, this.S), d.filter && ("string" === typeof this.L[b] && (this.L[b] = new String(this.L[b])), this.L[b].R = d.filter)); this.aa[b] = e; this.tag.set(e, new Map()); } @@ -2425,19 +2450,19 @@ function X(a) { if (this.worker) { this.fastupdate = !1; a = []; - c = w(this.index.values()); + c = x(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(g) { - for (var h = 0, k = w(f.index.entries()), l = k.next(); !l.done; l = k.next()) { + var g = this; + return Promise.all(a).then(function(f) { + for (var h = 0, k = x(g.index.entries()), l = k.next(); !l.done; l = k.next()) { l = l.value; var m = l[0]; - l[1].then && f.index.set(m, g[h++]); + l[1].then && g.index.set(m, f[h++]); } - return f; + return g; }); } } else { @@ -2454,7 +2479,7 @@ u.mount = function(a) { for (var c = 0, d; c < this.aa.length; c++) { d = this.aa[c]; var e; - this.index.set(d, e = new S({}, this.reg)); + this.index.set(d, e = new P({}, this.reg)); b === this.field && (b = b.slice(0)); b.push(d); e.tag = this.tag.get(d); @@ -2463,26 +2488,26 @@ u.mount = function(a) { c = []; d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; e = 0; - for (var f; e < b.length; e++) { - d.field = f = b[e]; - f = this.index.get(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; + for (var g; e < b.length; e++) { + d.field = g = b[e]; + g = this.index.get(g); + var f = new a.constructor(a.id, d); + f.id = a.id; + c[e] = f.mount(g); + g.document = !0; + e ? g.bypass = !0 : g.store = this.store; } this.db = !0; return Promise.all(c); }; u.commit = function(a, b) { - var c = this, d, e, f, g; + var c = this, d, e, g, f; return ta(function(h) { if (1 == h.h) { d = []; - e = w(c.index.values()); - for (f = e.next(); !f.done; f = e.next()) { - g = f.value, d.push(g.db.commit(g, a, b)); + e = x(c.index.values()); + for (g = e.next(); !g.done; g = e.next()) { + f = g.value, d.push(f.commit(f, a, b)); } return E(h, Promise.all(d), 2); } @@ -2491,34 +2516,34 @@ u.commit = function(a, b) { }); }; u.destroy = function() { - for (var a = [], b = w(this.index.values()), c = b.next(); !c.done; c = b.next()) { + for (var a = [], b = x(this.index.values()), c = b.next(); !c.done; c = b.next()) { a.push(c.value.destroy()); } return Promise.all(a); }; -function xb(a, b) { +function yb(a, b) { var c = new Map(), d = b.index || b.field || b; K(d) && (d = [d]); - for (var e = 0, f, g = void 0; e < d.length; e++) { - f = d[e]; - K(f) || (g = f, f = f.field); - g = M(g) ? Object.assign({}, a, g) : a; + for (var e = 0, g, f = void 0; e < d.length; e++) { + g = d[e]; + K(g) || (f = g, g = g.field); + f = L(f) ? Object.assign({}, a, f) : a; if (this.worker) { - var h = new Ra(g); - c.set(f, h); + var h = new Sa(f); + c.set(g, h); } - this.worker || c.set(f, new S(g, this.reg)); - g.custom ? this.J[e] = g.custom : (this.J[e] = wb(f, this.S), g.filter && ("string" === typeof this.J[e] && (this.J[e] = new String(this.J[e])), this.J[e].R = g.filter)); - this.field[e] = f; + this.worker || c.set(g, new P(f, this.reg)); + f.custom ? this.J[e] = f.custom : (this.J[e] = xb(g, this.S), f.filter && ("string" === typeof this.J[e] && (this.J[e] = new String(this.J[e])), this.J[e].R = f.filter)); + this.field[e] = g; } if (this.I) { for (a = b.store, K(a) && (a = [a]), b = 0; b < a.length; b++) { - d = a[b], e = d.field || d, d.custom ? (this.I[b] = d.custom, d.custom.ja = e) : (this.I[b] = wb(e, this.S), d.filter && ("string" === typeof this.I[b] && (this.I[b] = new String(this.I[b])), this.I[b].R = d.filter)); + d = a[b], e = d.field || d, d.custom ? (this.I[b] = d.custom, d.custom.ja = e) : (this.I[b] = xb(e, this.S), d.filter && ("string" === typeof this.I[b] && (this.I[b] = new String(this.I[b])), this.I[b].R = d.filter)); } } return c; } -function wb(a, b) { +function xb(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); } @@ -2532,20 +2557,20 @@ u.update = function(a, b) { return this.remove(a).add(a, b); }; u.remove = function(a) { - M(a) && (a = ya(a, this.key)); - for (var b = w(this.index.values()), c = b.next(); !c.done; c = b.next()) { + L(a) && (a = ya(a, this.key)); + for (var b = x(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 = w(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + for (b = x(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c = c.value; - for (var d = w(c), e = d.next(); !e.done; e = d.next()) { - var f = e.value; - e = f[0]; - f = f[1]; - var g = f.indexOf(a); - -1 < g && (1 < f.length ? f.splice(g, 1) : c.delete(e)); + for (var d = x(c), e = d.next(); !e.done; e = d.next()) { + var g = e.value; + e = g[0]; + g = g[1]; + var f = g.indexOf(a); + -1 < f && (1 < g.length ? g.splice(f, 1) : c.delete(e)); } } } @@ -2556,22 +2581,23 @@ u.remove = function(a) { return this; }; u.clear = function() { - for (var a = w(this.index.values()), b = a.next(); !b.done; b = a.next()) { - b.value.clear(); + for (var a = [], b = x(this.index.values()), c = b.next(); !c.done; c = b.next()) { + c = c.value.clear(), c.then && a.push(c); } if (this.tag) { - for (a = w(this.tag.values()), b = a.next(); !b.done; b = a.next()) { - b.value.clear(); + for (b = x(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + c.value.clear(); } } this.store && this.store.clear(); - return this; + this.cache && this.cache.clear(); + return a.length ? Promise.all(a) : this; }; u.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; u.cleanup = function() { - for (var a = w(this.index.values()), b = a.next(); !b.done; b = a.next()) { + for (var a = x(this.index.values()), b = a.next(); !b.done; b = a.next()) { b.value.cleanup(); } return this; @@ -2585,40 +2611,40 @@ u.set = function(a, b) { this.store.set(a, b); return this; }; -u.searchCache = yb; +u.searchCache = zb; u.export = function(a, b, c, d) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; if (c < this.field.length) { var e = this.field[c]; if ((b = this.index.get(e).export(a, e, c, d = 1)) && b.then) { - var f = this; + var g = this; return b.then(function() { - return f.export(a, e, c + 1); + return g.export(a, e, c + 1); }); } return this.export(a, e, c + 1); } switch(d) { case 0: - var g = "reg"; - var h = Xa(this.reg); + var f = "reg"; + var h = Ya(this.reg); b = null; break; case 1: - g = "tag"; - h = this.tag && Va(this.tag, this.reg.size); + f = "tag"; + h = this.tag && Wa(this.tag, this.reg.size); b = null; break; case 2: - g = "doc"; - h = this.store && Ta(this.store); + f = "doc"; + h = this.store && Ua(this.store); b = null; break; default: return; } - return Za.call(this, a, b, g, h, c, d); + return $a.call(this, a, b, f, h, c, d); }; u.import = function(a, b) { var c = a.split("."); @@ -2636,13 +2662,13 @@ u.import = function(a, b) { switch(c) { case "reg": this.fastupdate = !1; - this.reg = Ya(b, this.reg); + this.reg = Za(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 = w(this.index.values()); + d = x(this.index.values()); for (c = d.next(); !c.done; c = d.next()) { b.push(c.value.import(a)); } @@ -2650,15 +2676,15 @@ u.import = function(a, b) { } break; case "tag": - this.tag = Wa(b, this.tag); + this.tag = Xa(b, this.tag); break; case "doc": - this.store = Ua(b, this.store); + this.store = Va(b, this.store); } } }; -Ia(W.prototype); -function yb(a, b, c) { +La(W.prototype); +function zb(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Z()); var d = this.cache.get(a); @@ -2666,9 +2692,9 @@ function yb(a, b, c) { d = this.search(a, b, c); if (d.then) { var e = this; - d.then(function(f) { - e.cache.set(a, f); - return f; + d.then(function(g) { + e.cache.set(a, g); + return g; }); } this.cache.set(a, d); @@ -2690,7 +2716,7 @@ Z.prototype.get = function(a) { return b; }; Z.prototype.remove = function(a) { - for (var b = w(this.cache), c = b.next(); !c.done; c = b.next()) { + for (var b = x(this.cache), c = b.next(); !c.done; c = b.next()) { c = c.value; var d = c[0]; c[1].includes(a) && this.cache.delete(d); @@ -2700,72 +2726,72 @@ Z.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -var zb = {normalize:function(a) { +var Ab = {normalize:function(a) { return a.toLowerCase(); }}; -var Ab = 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 Bb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Cb = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -var Db = {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 Eb = /[\x00-\x7F]+/g; +var Bb = 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 Cb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Db = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +var Eb = {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 Fb = /[\x00-\x7F]+/g; var Gb = /[\x00-\x7F]+/g; -var Hb = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:zb, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ab}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ab, matcher:Bb, replacer:Cb}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ab, replacer:Cb.concat([/(?!^)[aeo]/g, ""]), matcher:Bb}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +var Hb = /[\x00-\x7F]+/g; +var Ib = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Ab, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Bb}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Bb, matcher:Cb, replacer:Db}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Bb, replacer:Db.concat([/(?!^)[aeo]/g, ""]), matcher:Cb}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (var b = 0; b < a.length; b++) { - for (var c = a[b], d = c.charAt(0), e = Db[d], f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Db[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + for (var c = a[b], d = c.charAt(0), e = Eb[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = Eb[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) { } a[b] = d; } }}, ArabicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Eb, " "); + return ("" + a).replace(Fb, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Fb, ""); + return ("" + a).replace(Gb, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Gb, " "); + return ("" + a).replace(Hb, " "); }}}; -var Ib = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -S.prototype.add = function(a, b, c, d) { +var Jb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +P.prototype.add = function(a, b, c, d) { if (b && (a || 0 === a)) { if (!d && !c && this.reg.has(a)) { return this.update(a, b); } b = this.encoder.encode(b); if (d = b.length) { - for (var e = J(), f = J(), g = this.depth, h = this.resolution, k = 0; k < d; k++) { + for (var e = J(), g = J(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { var l = b[this.rtl ? d - 1 - k : k], m = l.length; - if (m && (g || !f[l])) { - var n = this.score ? this.score(b, l, k, null, 0) : Jb(h, d, k), p = ""; + if (m && (f || !g[l])) { + var n = this.score ? this.score(b, l, k, null, 0) : Kb(h, d, k), p = ""; switch(this.tokenize) { case "full": if (2 < m) { n = 0; for (var q; n < m; n++) { - for (var r = m; r > n; r--) { - p = l.substring(n, r), q = this.rtl ? m - 1 - n : n, q = this.score ? this.score(b, l, k, p, q) : Jb(h, d, k, m, q), Kb(this, f, p, q, a, c); + for (var t = m; t > n; t--) { + p = l.substring(n, t), q = this.rtl ? m - 1 - n : n, q = this.score ? this.score(b, l, k, p, q) : Kb(h, d, k, m, q), Lb(this, g, p, q, a, c); } } break; } case "reverse": if (1 < m) { - for (r = m - 1; 0 < r; r--) { - p = l[this.rtl ? m - 1 - r : r] + p, q = this.score ? this.score(b, l, k, p, r) : Jb(h, d, k, m, r), Kb(this, f, p, q, a, c); + for (t = m - 1; 0 < t; t--) { + p = l[this.rtl ? m - 1 - t : t] + p, q = this.score ? this.score(b, l, k, p, t) : Kb(h, d, k, m, t), Lb(this, g, p, q, a, c); } p = ""; } case "forward": if (1 < m) { - for (r = 0; r < m; r++) { - p += l[this.rtl ? m - 1 - r : r], Kb(this, f, p, n, a, c); + for (t = 0; t < m; t++) { + p += l[this.rtl ? m - 1 - t : t], Lb(this, g, p, n, a, c); } break; } default: - if (Kb(this, f, l, n, a, c), g && 1 < d && k < d - 1) { - for (m = J(), p = this.da, n = l, r = Math.min(g + 1, this.rtl ? k + 1 : d - k), q = m[n] = 1; q < r; q++) { + if (Lb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { + for (m = J(), p = this.da, n = l, t = Math.min(f + 1, this.rtl ? k + 1 : d - k), q = m[n] = 1; q < t; q++) { if ((l = b[this.rtl ? d - 1 - k - q : k + q]) && !m[l]) { m[l] = 1; - var x = this.score ? this.score(b, n, k, l, q - 1) : Jb(p + (d / 2 > p ? 0 : 1), d, k, r - 1, q - 1), t = this.bidirectional && l > n; - Kb(this, e, t ? n : l, x, a, c, t ? l : n); + var w = this.score ? this.score(b, n, k, l, q - 1) : Kb(p + (d / 2 > p ? 0 : 1), d, k, t - 1, q - 1), r = this.bidirectional && l > n; + Lb(this, e, r ? n : l, w, a, c, r ? l : n); } } } @@ -2777,18 +2803,18 @@ S.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.ca && Lb(this)); + this.db && (b || this.commit_task.push({del:a}), this.ca && Mb(this)); return this; }; -function Kb(a, b, c, d, e, f, g) { - var h = g ? a.ctx : a.map, k; - if (!b[c] || g && !(k = b[c])[g]) { - if (g ? (b = k || (b[c] = J()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { +function Lb(a, b, c, d, e, g, f) { + var h = f ? a.ctx : a.map, k; + if (!b[c] || f && !(k = b[c])[f]) { + if (f ? (b = k || (b[c] = J()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) { if (h.length === Math.pow(2, 31) - 1) { - b = new ab(h); + b = new T(h); if (a.fastupdate) { - for (c = w(a.reg.values()), f = c.next(); !f.done; f = c.next()) { - f = f.value, f.includes(h) && (f[f.indexOf(h)] = b); + for (c = x(a.reg.values()), g = c.next(); !g.done; g = c.next()) { + g = g.value, g.includes(h) && (g[g.indexOf(h)] = b); } } k[d] = h = b; @@ -2798,43 +2824,43 @@ function Kb(a, b, c, d, e, f, g) { } } } -function Jb(a, b, c, d, e) { +function Kb(a, b, c, d, e) { return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; } -;S.prototype.search = function(a, b, c) { - c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0)); - var d = [], e = 0, f; +;P.prototype.search = function(a, b, c) { + c || (!b && L(a) ? (c = a, a = "") : L(b) && (c = b, b = 0)); + var d = [], e = 0, g; if (c) { a = c.query || a; b = c.limit || b; e = c.offset || 0; - var g = c.context; + var f = c.context; var h = c.suggest; - var k = (f = !1 !== c.resolve) && c.enrich; + var k = (g = !1 !== c.resolve) && c.enrich; var l = c.boost; var m = c.resolution; var n = this.db && c.tag; } else { - f = this.resolve; + g = this.resolve; } var p = this.encoder.encode(a); var q = p.length; - b = b || (f ? 100 : 0); + b = b || (g ? 100 : 0); if (1 === q) { - return Mb.call(this, p[0], "", b, e, f, k, n); + return Nb.call(this, p[0], "", b, e, g, k, n); } - g = this.depth && !1 !== g; - if (2 === q && g && !h) { - return Mb.call(this, p[0], p[1], b, e, f, k, n); + f = this.depth && !1 !== f; + if (2 === q && f && !h) { + return Nb.call(this, p[0], p[1], b, e, g, k, n); } - var r = J(), x = 0; - if (1 < q && g) { - var t = p[0]; - x = 1; + var t = J(), w = 0; + if (1 < q && f) { + var r = p[0]; + w = 1; } - m || 0 === m || (m = t ? this.da : this.resolution); + m || 0 === m || (m = r ? this.da : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, p, b, e, h, f, k, n), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, p, b, e, h, g, k, n), !1 !== a)) { return a; } var A = this; @@ -2845,75 +2871,75 @@ function Jb(a, b, c, d, e) { case 1: v = z = void 0; case 2: - if (!(x < q)) { + if (!(w < q)) { y.h = 4; break; } - v = p[x]; - if (!v || r[v]) { + v = p[w]; + if (!v || t[v]) { y.h = 5; break; } - r[v] = 1; - return E(y, Nb(A, v, t, 0, 0, !1, !1), 6); + t[v] = 1; + return E(y, Ob(A, v, r, 0, 0, !1, !1), 6); case 6: z = y.D; - if (z = Ob(z, d, h, m)) { + if (z = Pb(z, d, h, m)) { d = z; y.h = 4; break; } - t && (h && z && d.length || (t = v)); + r && (h && z && d.length || (r = v)); case 5: - h && t && x === q - 1 && !d.length && (m = A.resolution, t = "", x = -1, r = J()); - x++; + h && r && w === q - 1 && !d.length && (m = A.resolution, r = "", w = -1, t = J()); + w++; y.h = 2; break; case 4: - return y.return(Pb(d, m, b, e, h, l, f)); + return y.return(Qb(d, m, b, e, h, l, g)); } }); }(); } - for (c = a = void 0; x < q; x++) { - if ((c = p[x]) && !r[c]) { - r[c] = 1; - a = Nb(this, c, t, 0, 0, !1, !1); - if (a = Ob(a, d, h, m)) { + for (c = a = void 0; w < q; w++) { + if ((c = p[w]) && !t[c]) { + t[c] = 1; + a = Ob(this, c, r, 0, 0, !1, !1); + if (a = Pb(a, d, h, m)) { d = a; break; } - t && (h && a && d.length || (t = c)); + r && (h && a && d.length || (r = c)); } - h && t && x === q - 1 && !d.length && (m = this.resolution, t = "", x = -1, r = J()); + h && r && w === q - 1 && !d.length && (m = this.resolution, r = "", w = -1, t = J()); } - return Pb(d, m, b, e, h, l, f); + return Qb(d, m, b, e, h, l, g); }; -function Pb(a, b, c, d, e, f, g) { +function Qb(a, b, c, d, e, g, f) { var h = a.length, k = a; if (1 < h) { - k = ib(a, b, c, d, e, f, g); + k = jb(a, b, c, d, e, g, f); } else if (1 === h) { - return g ? lb.call(null, a[0], c, d) : new Y(a[0]); + return f ? mb.call(null, a[0], c, d) : new Y(a[0]); } - return g ? k : new Y(k); + return f ? k : new Y(k); } -function Mb(a, b, c, d, e, f, g) { - a = Nb(this, a, b, c, d, e, f, g); +function Nb(a, b, c, d, e, g, f) { + a = Ob(this, a, b, c, d, e, g, f); return this.db ? a.then(function(h) { return e ? h || [] : new Y(h); - }) : a && a.length ? e ? lb.call(this, a, c, d) : new Y(a) : e ? [] : new Y(); + }) : a && a.length ? e ? mb.call(this, a, c, d) : new Y(a) : e ? [] : new Y(); } -function Ob(a, b, c, d) { +function Pb(a, b, c, d) { var e = []; if (a && a.length) { if (a.length <= d) { b.push(a); return; } - for (var f = 0, g; f < d; f++) { - if (g = a[f]) { - e[f] = g; + for (var g = 0, f; g < d; g++) { + if (f = a[g]) { + e[g] = f; } } if (e.length) { @@ -2925,16 +2951,16 @@ function Ob(a, b, c, d) { return e; } } -function Nb(a, b, c, d, e, f, g, h) { +function Ob(a, b, c, d, e, g, f, 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, g, h); + return a.db.get(b, c, d, e, g, f, h); } a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;S.prototype.remove = function(a, b) { +;P.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) { @@ -2943,27 +2969,27 @@ function Nb(a, b, c, d, e, f, g, h) { if (2 > e.length) { e.pop(); } else { - var f = e.indexOf(a); - f === c.length - 1 ? e.pop() : e.splice(f, 1); + var g = e.indexOf(a); + g === c.length - 1 ? e.pop() : e.splice(g, 1); } } } } else { - Qb(this.map, a), this.depth && Qb(this.ctx, a); + Rb(this.map, a), this.depth && Rb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.ca && Lb(this)); + this.db && (this.commit_task.push({del:a}), this.ca && Mb(this)); this.cache && this.cache.remove(a); return this; }; -function Qb(a, b) { +function Rb(a, b) { var c = 0; if (a.constructor === Array) { - for (var d = 0, e = void 0, f; d < a.length; d++) { + for (var d = 0, e = void 0, g; d < a.length; d++) { if ((e = a[d]) && e.length) { - if (f = e.indexOf(b), 0 <= f) { - 1 < e.length ? (e.splice(f, 1), c++) : delete a[d]; + if (g = e.indexOf(b), 0 <= g) { + 1 < e.length ? (e.splice(g, 1), c++) : delete a[d]; break; } else { c++; @@ -2971,31 +2997,32 @@ function Qb(a, b) { } } } else { - for (d = w(a.entries()), e = d.next(); !e.done; e = d.next()) { - f = e.value, e = f[0], (f = Qb(f[1], b)) ? c += f : a.delete(e); + for (d = x(a.entries()), e = d.next(); !e.done; e = d.next()) { + g = e.value, e = g[0], (g = Rb(g[1], b)) ? c += g : a.delete(e); } } return c; } -;function S(a, b) { - if (!this || this.constructor !== S) { - return new S(a); +;function P(a, b) { + if (!this || this.constructor !== P) { + return new P(a); } if (a) { var c = K(a) ? a : a.preset; - c && (Ib[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Ib[c], a)); + c && (Jb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Jb[c], a)); } else { a = {}; } c = a.context; - var d = !0 === c ? {depth:1} : c || {}, e = K(a.encoder) ? Hb[a.encoder] : a.encode || a.encoder || zb; + var d = !0 === c ? {depth:1} : c || {}, e = K(a.encoder) ? Ib[a.encoder] : a.encode || a.encoder || Ab; this.encoder = e.encode ? e : "object" === typeof e ? new Ga(e) : {encode:e}; this.resolution = a.resolution || 9; - this.tokenize = (c = a.tokenize) && "default" !== c && c || "strict"; + this.tokenize = c = (c = a.tokenize) && "default" !== c && c || "strict"; this.depth = "strict" === c && d.depth || 0; this.bidirectional = !1 !== d.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; + d && "strict" !== this.tokenize && 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 U(c) : new Map(); this.ctx = c ? new U(c) : new Map(); @@ -3012,7 +3039,7 @@ function Qb(a, b) { this.commit_timer = null; this.priority = a.priority || 4; } -u = S.prototype; +u = P.prototype; u.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); @@ -3025,7 +3052,7 @@ u.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Lb(a) { +function Mb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -3051,17 +3078,17 @@ u.update = function(a, b) { return c.add(a, b); }) : this.add(a, b); }; -function Rb(a) { +function Sb(a) { var b = 0; if (a.constructor === Array) { for (var c = 0, d = void 0; c < a.length; c++) { (d = a[c]) && (b += d.length); } } else { - for (c = w(a), d = c.next(); !d.done; d = c.next()) { + for (c = x(a.entries()), d = c.next(); !d.done; d = c.next()) { var e = d.value; d = e[0]; - (e = Rb(e[1])) ? b += e : a.delete(d); + (e = Sb(e[1])) ? b += e : a.delete(d); } } return b; @@ -3070,109 +3097,82 @@ u.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Rb(this.map); - this.depth && Rb(this.ctx); + Sb(this.map); + this.depth && Sb(this.ctx); return this; }; -u.searchCache = yb; +u.searchCache = zb; u.export = function(a, b, c, d) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; switch(d) { case 0: var e = "reg"; - var f = Xa(this.reg); + var g = Ya(this.reg); break; case 1: e = "cfg"; - f = null; + g = null; break; case 2: e = "map"; - f = Ta(this.map, this.reg.size); + g = Ua(this.map, this.reg.size); break; case 3: e = "ctx"; - f = Va(this.ctx, this.reg.size); + g = Wa(this.ctx, this.reg.size); break; default: return; } - return Za.call(this, a, b, e, f, c, d); + return $a.call(this, a, b, e, g, c, d); }; u.import = function(a, b) { if (b) { switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = Ya(b, this.reg); + this.reg = Za(b, this.reg); break; case "map": - this.map = Ua(b, this.map); + this.map = Va(b, this.map); break; case "ctx": - this.ctx = Wa(b, this.ctx); + this.ctx = Xa(b, this.ctx); } } }; u.serialize = function(a) { a = void 0 === a ? !0 : a; - if (!this.reg.size) { - return ""; - } - for (var b = "", c = "", d = w(this.reg.keys()), e = d.next(); !e.done; e = d.next()) { - e = e.value, c || (c = typeof e), b += (b ? "," : "") + ("string" === c ? '"' + e + '"' : e); - } - b = "index.reg=new Set([" + b + "]);"; - d = ""; - e = w(this.map.entries()); - for (var f = e.next(); !f.done; f = e.next()) { - var g = f.value; - f = g[0]; - g = g[1]; - for (var h = "", k = 0, l; k < g.length; k++) { - l = g[k] || [""]; - for (var m = "", n = 0; n < l.length; n++) { - m += (m ? "," : "") + ("string" === c ? '"' + l[n] + '"' : l[n]); - } - m = "[" + m + "]"; - h += (h ? "," : "") + m; + var b = "", c = "", d = ""; + if (this.reg.size) { + var e; + c = x(this.reg.keys()); + for (var g = c.next(); !g.done; g = c.next()) { + g = g.value, e || (e = typeof g), b += (b ? "," : "") + ("string" === e ? '"' + g + '"' : g); } - h = '["' + f + '",[' + h + "]]"; - d += (d ? "," : "") + h; - } - d = "index.map=new Map([" + d + "]);"; - e = ""; - f = w(this.ctx.entries()); - for (g = f.next(); !g.done; g = f.next()) { - for (h = g.value, g = h[0], h = w(h[1].entries()), k = h.next(); !k.done; k = h.next()) { - l = k.value; - k = l[0]; - l = l[1]; - m = ""; - n = 0; - for (var p; n < l.length; n++) { - p = l[n] || [""]; - for (var q = "", r = 0; r < p.length; r++) { - q += (q ? "," : "") + ("string" === c ? '"' + p[r] + '"' : p[r]); - } - q = "[" + q + "]"; - m += (m ? "," : "") + q; - } - m = 'new Map([["' + k + '",[' + m + "]]])"; - m = '["' + g + '",' + m + "]"; - e += (e ? "," : "") + m; + b = "index.reg=new Set([" + b + "]);"; + c = ab(this.map, e); + c = "index.map=new Map([" + c + "]);"; + g = x(this.ctx.entries()); + for (var f = g.next(); !f.done; f = g.next()) { + var h = f.value; + f = h[0]; + h = ab(h[1], e); + h = "new Map([" + h + "])"; + h = '["' + f + '",' + h + "]"; + d += (d ? "," : "") + h; } + d = "index.ctx=new Map([" + d + "]);"; } - e = "index.ctx=new Map([" + e + "]);"; - return a ? "function inject(index){" + b + d + e + "}" : b + d + e; + return a ? "function inject(index){" + b + c + d + "}" : b + c + d; }; -Ia(S.prototype); -var Sb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Tb = ["map", "ctx", "tag", "reg", "cfg"]; -function Ub(a, b) { +La(P.prototype); +var Tb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Ub = ["map", "ctx", "tag", "reg", "cfg"]; +function Vb(a, b) { b = void 0 === b ? {} : b; if (!this) { - return new Ub(a, b); + return new Vb(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -3183,7 +3183,7 @@ function Ub(a, b) { this.db = null; this.h = {}; } -u = Ub.prototype; +u = Vb.prototype; u.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -3195,11 +3195,11 @@ u.open = function() { var a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - var d = Sb.open(a.id + (a.field ? ":" + a.field : ""), 1); + var d = Tb.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { var e = a.db = this.result; - Tb.forEach(function(f) { - e.objectStoreNames.contains(f) || e.createObjectStore(f); + Ub.forEach(function(g) { + e.objectStoreNames.contains(g) || e.createObjectStore(g); }); }; d.onblocked = function(e) { @@ -3220,27 +3220,27 @@ u.open = function() { }); }; u.close = function() { - this.db.close(); + this.db && this.db.close(); this.db = null; }; u.destroy = function() { - var a = Sb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); - return Vb(a); + var a = Tb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return Wb(a); }; u.clear = function() { - for (var a = this.db.transaction(Tb, "readwrite"), b = 0; b < Tb.length; b++) { - a.objectStore(Tb[b]).clear(); + for (var a = this.db.transaction(Ub, "readwrite"), b = 0; b < Ub.length; b++) { + a.objectStore(Ub[b]).clear(); } - return Vb(a); + return Wb(a); }; -u.get = function(a, b, c, d, e, f) { +u.get = function(a, b, c, d, e, g) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; e = void 0 === e ? !0 : e; - f = void 0 === f ? !1 : f; + g = void 0 === g ? !1 : g; a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); - var g = this; - return Vb(a).then(function(h) { + var f = this; + return Wb(a).then(function(h) { var k = []; if (!h || !h.length) { return k; @@ -3264,7 +3264,7 @@ u.get = function(a, b, c, d, e, f) { } } } - return f ? g.enrich(k) : k; + return g ? f.enrich(k) : k; } return h; }); @@ -3275,32 +3275,34 @@ u.tag = function(a, b, c, d) { d = void 0 === d ? !1 : d; a = this.db.transaction("tag", "readonly").objectStore("tag").get(a); var e = this; - return Vb(a).then(function(f) { - if (!f || !f.length || c >= f.length) { + return Wb(a).then(function(g) { + if (!g || !g.length || c >= g.length) { return []; } if (!b && !c) { - return f; + return g; } - f = f.slice(c, c + b); - return d ? e.enrich(f) : f; + g = g.slice(c, c + b); + return d ? e.enrich(g) : g; }); }; u.enrich = function(a) { "object" !== typeof a && (a = [a]); for (var b = this.db.transaction("reg", "readonly").objectStore("reg"), c = [], d = 0; d < a.length; d++) { - c[d] = Vb(b.get(a[d])); + c[d] = Wb(b.get(a[d])); } return Promise.all(c).then(function(e) { - for (var f = 0; f < e.length; f++) { - e[f] = {id:a[f], doc:e[f] ? JSON.parse(e[f]) : null}; + for (var g = 0; g < e.length; g++) { + e[g] = {id:a[g], doc:e[g] ? JSON.parse(e[g]) : null}; } return e; }); }; u.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Vb(a); + return Wb(a).then(function(b) { + return !!b; + }); }; u.search = null; u.info = function() { @@ -3310,17 +3312,17 @@ u.transaction = function(a, b, c) { if (e) { return c.call(this, e); } - var f = this.db.transaction(a, b); - this.h[a + ":" + b] = e = f.objectStore(a); - return new Promise(function(g, h) { - f.onerror = function(l) { - f.abort(); - f = e = null; + var g = this.db.transaction(a, b); + this.h[a + ":" + b] = e = g.objectStore(a); + return new Promise(function(f, h) { + g.onerror = function(l) { + g.abort(); + g = e = null; h(l); }; - f.oncomplete = function(l) { - f = e = null; - g(l || !0); + g.oncomplete = function(l) { + g = e = null; + f(l || !0); }; var k = c.call(d, e); d.h[a + ":" + b] = null; @@ -3328,7 +3330,7 @@ u.transaction = function(a, b, c) { }); }; u.commit = function(a, b, c) { - var d = this, e, f, g; + var d = this, e, g, f; return ta(function(h) { switch(h.h) { case 1: @@ -3337,16 +3339,16 @@ u.commit = function(a, b, c) { } e = a.commit_task; a.commit_task = []; - f = 0; - g = void 0; + g = 0; + f = void 0; case 4: - if (!(f < e.length)) { + if (!(g < e.length)) { h.h = 6; break; } - g = e[f]; - if (!g.clear) { - e[f] = g.ma; + f = e[g]; + if (!f.clear) { + e[g] = f.ma; h.h = 5; break; } @@ -3356,7 +3358,7 @@ u.commit = function(a, b, c) { h.h = 6; break; case 5: - f++; + g++; h.h = 4; break; case 6: @@ -3378,58 +3380,58 @@ u.commit = function(a, b, c) { a.commit_task = []; case 3: return a.reg.size ? E(h, d.transaction("map", "readwrite", function(k) { - for (var l = w(a.map), m = l.next(), n = {}; !m.done; n = {O:void 0, Y:void 0}, m = l.next()) { + for (var l = x(a.map), m = l.next(), n = {}; !m.done; n = {O:void 0, Y:void 0}, m = l.next()) { m = m.value, n.Y = m[0], n.O = m[1], n.O.length && (b ? k.put(n.O, n.Y) : k.get(n.Y).onsuccess = function(p) { return function() { - var q = this.result, r; + var q = this.result, t; if (q && q.length) { - for (var x = Math.max(q.length, p.O.length), t = 0, A; t < x; t++) { - if ((A = p.O[t]) && A.length) { - if ((r = q[t]) && r.length) { + for (var w = Math.max(q.length, p.O.length), r = 0, A; r < w; r++) { + if ((A = p.O[r]) && A.length) { + if ((t = q[r]) && t.length) { for (var z = 0; z < A.length; z++) { - r.push(A[z]); + t.push(A[z]); } } else { - q[t] = A; + q[r] = A; } - r = 1; + t = 1; } } } else { - q = p.O, r = 1; + q = p.O, t = 1; } - r && k.put(q, p.Y); + t && k.put(q, p.Y); }; }(n)); } }), 13) : h.return(); case 13: return E(h, d.transaction("ctx", "readwrite", function(k) { - for (var l = w(a.ctx), m = l.next(), n = {}; !m.done; n = {V:void 0}, m = l.next()) { + for (var l = x(a.ctx), m = l.next(), n = {}; !m.done; n = {V:void 0}, m = l.next()) { m = m.value; n.V = m[0]; - m = w(m[1]); + m = x(m[1]); for (var p = m.next(), q = {}; !p.done; q = {P:void 0, Z:void 0}, p = m.next()) { - p = p.value, q.Z = p[0], q.P = p[1], q.P.length && (b ? k.put(q.P, n.V + ":" + q.Z) : k.get(n.V + ":" + q.Z).onsuccess = function(r, x) { + p = p.value, q.Z = p[0], q.P = p[1], q.P.length && (b ? k.put(q.P, n.V + ":" + q.Z) : k.get(n.V + ":" + q.Z).onsuccess = function(t, w) { return function() { - var t = this.result, A; - if (t && t.length) { - for (var z = Math.max(t.length, r.P.length), v = 0, y; v < z; v++) { - if ((y = r.P[v]) && y.length) { - if ((A = t[v]) && A.length) { + var r = this.result, A; + if (r && r.length) { + for (var z = Math.max(r.length, t.P.length), v = 0, y; v < z; v++) { + if ((y = t.P[v]) && y.length) { + if ((A = r[v]) && A.length) { for (var D = 0; D < y.length; D++) { A.push(y[D]); } } else { - t[v] = y; + r[v] = y; } A = 1; } } } else { - t = r.P, A = 1; + r = t.P, A = 1; } - A && k.put(t, x.V + ":" + r.Z); + A && k.put(r, w.V + ":" + t.Z); }; }(q, n)); } @@ -3438,7 +3440,7 @@ u.commit = function(a, b, c) { case 14: if (a.store) { return E(h, d.transaction("reg", "readwrite", function(k) { - for (var l = w(a.store), m = l.next(); !m.done; m = l.next()) { + for (var l = x(a.store), m = l.next(); !m.done; m = l.next()) { var n = m.value; m = n[0]; n = n[1]; @@ -3451,7 +3453,7 @@ u.commit = function(a, b, c) { break; } return E(h, d.transaction("reg", "readwrite", function(k) { - for (var l = w(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { + for (var l = x(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { k.put(1, m.value); } }), 16); @@ -3461,7 +3463,7 @@ u.commit = function(a, b, c) { break; } return E(h, d.transaction("tag", "readwrite", function(k) { - for (var l = w(a.tag), m = l.next(), n = {}; !m.done; n = {X:void 0, ba:void 0}, m = l.next()) { + for (var l = x(a.tag), m = l.next(), n = {}; !m.done; n = {X:void 0, ba:void 0}, m = l.next()) { m = m.value, n.ba = m[0], n.X = m[1], n.X.length && (k.get(n.ba).onsuccess = function(p) { return function() { var q = this.result; @@ -3476,11 +3478,11 @@ u.commit = function(a, b, c) { } }); }; -function Yb(a, b, c) { - for (var d = a.value, e, f, g = 0, h = 0, k; h < d.length; h++) { +function Zb(a, b, c) { + for (var d = a.value, e, g, f = 0, h = 0, k; h < d.length; h++) { if (k = c ? d : d[h]) { for (var l = 0, m, n; l < b.length; l++) { - if (n = b[l], m = k.indexOf(f ? parseInt(n, 10) : n), 0 > m && !f && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (f = 1), 0 <= m) { + if (n = b[l], m = k.indexOf(g ? parseInt(n, 10) : n), 0 > m && !g && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (g = 1), 0 <= m) { if (e = 1, 1 < k.length) { k.splice(m, 1); } else { @@ -3489,13 +3491,13 @@ function Yb(a, b, c) { } } } - g += k.length; + f += k.length; } if (c) { break; } } - g ? e && a.update(d) : a.delete(); + f ? e && a.update(d) : a.delete(); a.continue(); } u.remove = function(a) { @@ -3503,17 +3505,17 @@ u.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Yb(c, a); + c && Zb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Yb(c, a); + c && Zb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Yb(c, a, !0); + c && Zb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3521,7 +3523,7 @@ u.remove = function(a) { } })]); }; -function Vb(a) { +function Wb(a) { return new Promise(function(b, c) { a.onsuccess = function() { b(this.result); @@ -3533,8 +3535,8 @@ function Vb(a) { a = null; }); } -;var Zb = {Index:S, Charset:Hb, Encoder:Ga, Document:W, Worker:Ra, Resolver:Y, IndexedDB:Ub, Language:{}}, $b = self, ac; -(ac = $b.define) && ac.amd ? ac([], function() { - return Zb; -}) : "object" === typeof $b.exports ? $b.exports = Zb : $b.FlexSearch = Zb; +;var $b = {Index:P, Charset:Ib, Encoder:Ga, Document:W, Worker:Sa, Resolver:Y, IndexedDB:Vb, Language:{}}, ac = self, bc; +(bc = ac.define) && bc.amd ? bc([], function() { + return $b; +}) : "object" === typeof ac.exports ? ac.exports = $b : ac.FlexSearch = $b; }(this||self)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index 42a924d..9e0748c 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,11 +1,11 @@ /**! - * FlexSearch.js v0.8.123 (ES5) + * FlexSearch.js v0.8.132 (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 u;function aa(a){var b=0;return function(){return bc&&(c=Math.max(c+e,0));c"a1a".split(c).length; -this.numeric=H(a.numeric,e)}else{try{this.split=H(this.split,Ba)}catch(g){this.split=/\s+/}this.numeric=H(a.numeric,H(this.numeric,!0))}this.prepare=H(a.prepare,null,this.prepare);this.finalize=H(a.finalize,null,this.finalize);Fa||(this.mapper=new Map(Aa));this.rtl=H(a.rtl,!1,this.rtl);this.dedupe=H(a.dedupe,!1,this.dedupe);this.filter=H((c=a.filter)&&new Set(c),null,this.filter);this.matcher=H((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=H((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= -H((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=H(a.replacer,null,this.replacer);this.minlength=H(a.minlength,1,this.minlength);this.maxlength=H(a.maxlength,0,this.maxlength);if(this.cache=c=H(a.cache,!0,this.cache))this.D=null,this.T="number"===typeof c?c:2E5,this.B=new Map,this.C=new Map,this.H=this.G=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(a=w(this.matcher.keys()),b=a.next();!b.done;b=a.next())this.h+=(this.h?"|":"")+b.value;if(this.stemmer)for(a=w(this.stemmer.keys()), -b=a.next();!b.done;b=a.next())this.A+=(this.A?"|":"")+b.value;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&N(this);return this};u.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&N(this);return this}; +this.numeric=H(a.numeric,e)}else{try{this.split=H(this.split,Ba)}catch(g){this.split=/\s+/}this.numeric=H(a.numeric,H(this.numeric,!0))}this.prepare=H(a.prepare,null,this.prepare);this.finalize=H(a.finalize,null,this.finalize);Fa||(this.mapper=new Map(Aa));c=a.filter;this.filter="function"===typeof c?c:H(c&&new Set(c),null,this.filter);this.dedupe=H(a.dedupe,!1,this.dedupe);this.matcher=H((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=H((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= +H((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=H(a.replacer,null,this.replacer);this.minlength=H(a.minlength,1,this.minlength);this.maxlength=H(a.maxlength,0,this.maxlength);this.rtl=H(a.rtl,!1,this.rtl);if(this.cache=c=H(a.cache,!0,this.cache))this.D=null,this.T="number"===typeof c?c:2E5,this.B=new Map,this.C=new Map,this.H=this.G=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(a=x(this.matcher.keys()),b=a.next();!b.done;b=a.next())this.h+=(this.h?"|":"")+b.value; +if(this.stemmer)for(a=x(this.stemmer.keys()),b=a.next();!b.done;b=a.next())this.A+=(this.A?"|":"")+b.value;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&N(this);return this};u.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&N(this);return this}; u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&N(this);return this}; u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&N(this);return this}; u.encode=function(a){var b=this;if(this.cache&&a.length<=this.G)if(this.D){if(this.B.has(a))return this.B.get(a)}else this.D=setTimeout(N,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=Fa?a.normalize("NFKD").replace(Fa,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.T&&(this.C.clear(),this.H=this.H/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.G&&(this.B.set(a,d),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return d};function N(a){a.D=null;a.B.clear();a.C.clear()};var O,Ha; +d=[],e=this.split||""===this.split?a.split(this.split):a,g=0,f=void 0,h=void 0;g=this.minlength&&("function"===typeof this.filter?!this.filter(f):this.filter.has(f))&&(f=""));if(f&&(this.mapper||this.dedupe&&1this.T&&(this.C.clear(),this.H=this.H/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.G&&(this.B.set(a,d),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return d};function N(a){a.D=null;a.B.clear();a.C.clear()};var O,Ha; function Ia(a){var b,c,d,e,g,f;return ta(function(h){switch(h.h){case 1:a=a.data;b=a.task;c=a.id;d=a.args;switch(b){case "init":Ha=a.options||{};(e=a.factory)?(Function("return "+e)()(self),O=new self.FlexSearch.Index(Ha),delete self.FlexSearch):O=new R(Ha);postMessage({id:c});break;default:h.h=2;return}h.h=0;break;case 2:"export"===b&&(d[1]?(d[0]=Ha.export,d[2]=0,d[3]=1):d=null);if("import"===b){if(!d[0]){h.h=5;break}return E(h,Ha.import.call(O,d[0]),9)}g=d&&O[b].apply(O,d);if(!g||!g.then){h.h=5; break}return E(h,g,7);case 7:g=h.D;h.h=5;break;case 9:f=h.D,O.import(d[0],f);case 5:postMessage("search"===b?{id:c,msg:g}:{id:c}),h.h=0}})};function La(a){Ma.call(a,"add");Ma.call(a,"append");Ma.call(a,"search");Ma.call(a,"update");Ma.call(a,"remove")}var Na,Oa,Pa;function Qa(){Na=Pa=0} -function Ma(a){this[a+"Async"]=function(){var b=arguments,c=b[b.length-1];if("function"===typeof c){var d=c;delete b[b.length-1]}Na?Pa||(Pa=Date.now()-Oa>=this.priority*this.priority*3):(Na=setTimeout(Qa,0),Oa=Date.now());if(Pa){var e=this;return new Promise(function(f){setTimeout(function(){f(e[a+"Async"].apply(e,b))},0)})}var g=this[a].apply(this,b);c=g.then?g:new Promise(function(f){return f(g)});d&&c.then(d);return c}};var S=0; -function Ra(a){function b(f){function h(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=J();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++S]=function(){k(e);1E9=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} -function ab(a){if(!this)return new ab(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var g=0,f=0,h,k;fc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(g=0;gd)d-=f.length; -else{if(f.length>c||d)f=f.slice(d,c+d),c-=f.length,d&&(d-=f.length);e.push(f);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,d?X.call(this,a):a;for(var e=[],g=0,f=void 0,h=void 0;g=h){c-=h;continue}cb&&(f=f.slice(0,b),h=b);if(!e.length&&h>=b)return d?X.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=jb(a,c,d,!1,this.h),d=0));return g?this.resolve(c,d,e):this};Y.prototype.and=function(){var a=this.result.length;if(!a){var b=arguments[0];if(b){a=!!b.suggest;var c=b.resolve;var d=b.limit;var e=b.offset;var g=b.enrich&&c}}return a?(a=mb(this,"and",arguments),ob.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,g):this}; -function ob(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else{if(b=za(a))return this.result=ib(a,b,c,d,f,this.h,g),g?e?X.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(c,d,e):this};Y.prototype.xor=function(){var a=mb(this,"xor",arguments);return pb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)}; -function pb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else return this.result=qb.call(this,a,c,d,g,this.h),g?e?X.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(c,d,e):this} -function qb(a,b,c,d,e){for(var g=[],f=J(),h=0,k=0,l;kc||d)a=a.slice(d,d+c);e&&(a=X.call(this,a));return a}}function X(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;c=this.priority*this.priority*3):(Na=setTimeout(Qa,0),Oa=Date.now());if(Pa){var e=this;return new Promise(function(f){setTimeout(function(){f(e[a+"Async"].apply(e,b))},0)})}var g=this[a].apply(this,b);c=g.then?g:new Promise(function(f){return f(g)});d&&c.then(d);return c}};var Ra=0; +function Sa(a){function b(f){function h(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=J();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++Ra]=function(){k(e);1E9=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} +function T(a){if(!this||this.constructor!==T)return new T(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var g=0,f=0,h,k;fc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[]; +for(g=0;gd)d-=f.length;else{if(f.length>c||d)f=f.slice(d,c+d),c-=f.length,d&&(d-=f.length);e.push(f);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,d?X.call(this,a):a;for(var e=[],g=0,f=void 0,h=void 0;g=h){c-=h;continue}cb&&(f=f.slice(0,b),h=b);if(!e.length&&h>=b)return d?X.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=kb(a,c,d,!1,this.h),d=0));return g?this.resolve(c,d,e):this};Y.prototype.and=function(){var a=this.result.length;if(!a){var b=arguments[0];if(b){a=!!b.suggest;var c=b.resolve;var d=b.limit;var e=b.offset;var g=b.enrich&&c}}return a?(a=nb(this,"and",arguments),pb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,g):this}; +function pb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else{if(b=za(a))return this.result=jb(a,b,c,d,f,this.h,g),g?e?X.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(c,d,e):this};Y.prototype.xor=function(){var a=nb(this,"xor",arguments);return qb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)}; +function qb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else return this.result=rb.call(this,a,c,d,g,this.h),g?e?X.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(c,d,e):this} +function rb(a,b,c,d,e){for(var g=[],f=J(),h=0,k=0,l;kc||d)a=a.slice(d,d+c);e&&(a=X.call(this,a));return a}}function X(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Z.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};Z.prototype.remove=function(a){for(var b=w(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)}};Z.prototype.clear=function(){this.cache.clear();this.h=""};var zb={normalize:function(a){return a.toLowerCase()}};var Ab=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 Bb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Cb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Db={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 Eb=/[\x00-\x7F]+/g;var Fb=/[\x00-\x7F]+/g;var Gb=/[\x00-\x7F]+/g;var Hb={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:zb,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ab},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ab,matcher:Bb,replacer:Cb},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ab,replacer:Cb.concat([/(?!^)[aeo]/g,""]),matcher:Bb},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;r--)p=l.substring(n,r),q=this.rtl?m-1-n:n,q=this.score?this.score(b,l,k,p,q):Jb(h,d,k,m,q),Kb(this,g,p, -q,a,c);break}case "reverse":if(1p?0:1),d,k,r-1,q-1),t=this.bidirectional&&l>n;Kb(this, -e,t?n:l,x,a,c,t?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.ca&&Lb(this));return this}; -function Kb(a,b,c,d,e,g,f){var h=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=J()),b[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!g||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new ab(h);if(a.fastupdate)for(c=w(a.reg.values()),g=c.next();!g.done;g=c.next())g=g.value,g.includes(h)&&(g[g.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} -function Jb(a,b,c,d,e){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,g,f,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};R.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else Qb(this.map,a),this.depth&&Qb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Lb(this));this.cache&&this.cache.remove(a);return this}; -function Qb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;dthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Z.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};Z.prototype.remove=function(a){for(var b=x(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};Z.prototype.clear=function(){this.cache.clear();this.h=""};var Ab={normalize:function(a){return a.toLowerCase()}};var Bb=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 Cb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Db=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Eb={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 Fb=/[\x00-\x7F]+/g;var Gb=/[\x00-\x7F]+/g;var Hb=/[\x00-\x7F]+/g;var Ib={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Ab,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Bb},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Bb,matcher:Cb,replacer:Db},LatinExtra:{normalize:!0,dedupe:!0,mapper:Bb,replacer:Db.concat([/(?!^)[aeo]/g,""]),matcher:Cb},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;r--)p=l.substring(n,r),q=this.rtl?m-1-n:n,q=this.score?this.score(b,l,k,p,q):Kb(h,d,k,m,q),Lb(this,g,p, +q,a,c);break}case "reverse":if(1p?0:1),d,k,r-1,q-1),t=this.bidirectional&&l>n;Lb(this, +e,t?n:l,w,a,c,t?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.ca&&Mb(this));return this}; +function Lb(a,b,c,d,e,g,f){var h=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=J()),b[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!g||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new T(h);if(a.fastupdate)for(c=x(a.reg.values()),g=c.next();!g.done;g=c.next())g=g.value,g.includes(h)&&(g[g.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} +function Kb(a,b,c,d,e){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,g,f,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};R.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else Rb(this.map,a),this.depth&&Rb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Mb(this));this.cache&&this.cache.remove(a);return this}; +function Rb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;d=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p=g.length)return[];if(!b&&!c)return g;g=g.slice(c,c+b);return d?e.enrich(g):g})}; -u.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p=g.length)return[];if(!b&&!c)return g;g=g.slice(c,c+b);return d?e.enrich(g):g})}; +u.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;dm&&!g&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(g=1),0<=m)if(e=1,1m&&!g&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(g=1),0<=m)if(e=1,1 this.stemmer.get(k)), e.length < this.minlength || this.filter && this.filter.has(e)) && (e = ""); + this.stemmer && 2 < e.length && (this.u || (this.u = new RegExp("(?!^)(" + this.h + ")$")), d = e, e = e.replace(this.u, k => this.stemmer.get(k)), d !== e && this.filter && e.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(e) : this.filter.has(e)) && (e = "")); if (e && (this.mapper || this.dedupe && 1 < e.length)) { d = ""; for (let k = 0, n = "", m, v; k < e.length; k++) { @@ -300,12 +300,12 @@ L.prototype.add = function(a, c, b, f) { } c = this.encoder.encode(c); if (f = c.length) { - const n = w(), m = w(), v = this.depth, C = this.resolution; + const n = w(), m = w(), v = this.depth, D = this.resolution; for (let p = 0; p < f; p++) { let l = c[this.rtl ? f - 1 - p : p]; var d = l.length; if (d && (v || !m[l])) { - var g = this.score ? this.score(c, l, p, null, 0) : M(C, f, p), e = ""; + var g = this.score ? this.score(c, l, p, null, 0) : M(D, f, p), e = ""; switch(this.tokenize) { case "full": if (2 < d) { @@ -313,7 +313,7 @@ L.prototype.add = function(a, c, b, f) { for (g = d; g > q; g--) { e = l.substring(q, g); t = this.rtl ? d - 1 - q : q; - var h = this.score ? this.score(c, l, p, e, t) : M(C, f, p, d, t); + var h = this.score ? this.score(c, l, p, e, t) : M(D, f, p, d, t); N(this, m, e, h, a, b); } } @@ -323,7 +323,7 @@ L.prototype.add = function(a, c, b, f) { if (1 < d) { for (h = d - 1; 0 < h; h--) { e = l[this.rtl ? d - 1 - h : h] + e; - var k = this.score ? this.score(c, l, p, e, h) : M(C, f, p, d, h); + var k = this.score ? this.score(c, l, p, e, h) : M(D, f, p, d, h); N(this, m, e, k, a, b); } e = ""; @@ -399,7 +399,7 @@ function M(a, c, b, f, d) { l = O(this, q, m); a: { g = l; - var v = f, C = e, p = k; + var v = f, D = e, p = k; let t = []; if (g && g.length) { if (g.length <= p) { @@ -407,9 +407,9 @@ function M(a, c, b, f, d) { l = void 0; break a; } - for (let x = 0, E; x < p; x++) { - if (E = g[x]) { - t[x] = E; + for (let x = 0, A; x < p; x++) { + if (A = g[x]) { + t[x] = A; } } if (t.length) { @@ -418,7 +418,7 @@ function M(a, c, b, f, d) { break a; } } - l = C ? void 0 : t; + l = D ? void 0 : t; } if (l) { f = l; @@ -438,11 +438,14 @@ function M(a, c, b, f, d) { m = a.length; e = []; b = w(); - for (let l = 0, q, t, x, E; l < k; l++) { + for (let l = 0, q, t, x, A; l < k; l++) { for (n = 0; n < m; n++) { if (x = a[n], l < x.length && (q = x[l])) { for (g = 0; g < q.length; g++) { - t = q[g], (h = b[t]) ? b[t]++ : (h = 0, b[t] = 1), E = e[h] || (e[h] = []), E.push(t); + if (t = q[g], (h = b[t]) ? b[t]++ : (h = 0, b[t] = 1), A = e[h] || (e[h] = []), A.push(t), c && h === m - 1 && A.length - d === c) { + m = A; + break b; + } } } } @@ -557,11 +560,12 @@ function P(a, c) { const f = !0 === b ? {depth:1} : b || {}, d = a.encode || a.encoder || J; this.encoder = d.encode ? d : "object" === typeof d ? new F(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = (b = a.tokenize) && "default" !== b && b || "strict"; + this.tokenize = b = (b = a.tokenize) && "default" !== b && b || "strict"; this.depth = "strict" === b && f.depth || 0; this.bidirectional = !1 !== f.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; + f && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); b = !1; this.map = new Map(); this.ctx = new Map(); @@ -595,7 +599,7 @@ function Q(a) { (f = a[b]) && (c += f.length); } } else { - for (const b of a) { + for (const b of a.entries()) { const f = b[0], d = Q(b[1]); d ? c += d : a.delete(f); } diff --git a/dist/flexsearch.light.min.js b/dist/flexsearch.light.min.js index 7667e11..381122f 100644 --- a/dist/flexsearch.light.min.js +++ b/dist/flexsearch.light.min.js @@ -1,27 +1,28 @@ /**! - * FlexSearch.js v0.8.123 (Light) + * FlexSearch.js v0.8.132 (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 r;function u(a,c,b){const f=typeof b,d=typeof a;if("undefined"!==f){if("undefined"!==d){if(b){if("function"===d&&f===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var g=new Map(b);for(var 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"undefined"===d?c:a}function w(){return Object.create(null)};const y=/[^\p{L}\p{N}]+/u,z=/(\d{3})/g,A=/(\D)(\d{3})/g,B=/(\d{3})(\D)/g,D="".normalize&&/[\u0300-\u036f]/g;function F(a={}){if(!this||this.constructor!==F)return new F(...arguments);if(arguments.length)for(a=0;a"a1a".split(b).length; -this.numeric=u(a.numeric,f)}else{try{this.split=u(this.split,y)}catch(d){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);this.rtl=u(a.rtl,!1,this.rtl);this.dedupe=u(a.dedupe,!1,this.dedupe);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), -null,this.stemmer);this.replacer=u(a.replacer,null,this.replacer);this.minlength=u(a.minlength,1,this.minlength);this.maxlength=u(a.maxlength,0,this.maxlength);if(this.cache=b=u(a.cache,!0,this.cache))this.l=null,this.A="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.o=this.m=128;this.g="";this.s=null;this.h="";this.u=null;if(this.matcher)for(const d of this.matcher.keys())this.g+=(this.g?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.h+=(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){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&G(this);return this};r.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(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("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&G(this);return this}; -r.encode=function(a){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&&("function"===typeof this.normalize?a=this.normalize(a):a=D?a.normalize("NFKD").replace(D,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),e.lengththis.matcher.get(k)));if(e&&this.replacer)for(d=0;e&&dthis.A&& -(this.j.clear(),this.o=this.o/1.1|0));e&&b.push(e)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.m&&(this.i.set(a,b),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return b};function G(a){a.l=null;a.i.clear();a.j.clear()};function H(a,c,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>c?c?a.slice(b,b+c):a.slice(b):a;let f=[];for(let d=0,g,e;d=e){b-=e;continue}bc&&(g=g.slice(0,c),e=c);if(!f.length&&e>=c)return g;f.push(g);c-=e;if(!c)break}return f=1this.limit&&this.cache.delete(this.cache.keys().next().value)};I.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};I.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; -I.prototype.clear=function(){this.cache.clear();this.g=""};const J={normalize:function(a){return a.toLowerCase()}};const K={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};L.prototype.add=function(a,c,b,f){if(c&&(a||0===a)){if(!f&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(f=c.length){const n=w(),m=w(),v=this.depth,C=this.resolution;for(let p=0;pq;g--){e=l.substring(q,g);t=this.rtl?d-1-q:q;var h=this.score?this.score(c,l,p,e,t):M(C,f,p,d,t);N(this, -m,e,h,a,b)}break}case "reverse":if(1e?0:1),f,p,h-1,k-1),t=this.bidirectional&& +this.numeric=u(a.numeric,f)}else{try{this.split=u(this.split,y)}catch(d){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:u(b&&new Set(b),null,this.filter);this.dedupe=u(a.dedupe,!1,this.dedupe);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), +null,this.stemmer);this.replacer=u(a.replacer,null,this.replacer);this.minlength=u(a.minlength,1,this.minlength);this.maxlength=u(a.maxlength,0,this.maxlength);this.rtl=u(a.rtl,!1,this.rtl);if(this.cache=b=u(a.cache,!0,this.cache))this.l=null,this.A="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.o=this.m=128;this.g="";this.s=null;this.h="";this.u=null;if(this.matcher)for(const d of this.matcher.keys())this.g+=(this.g?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.h+= +(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){"function"===typeof a?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("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(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("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&G(this);return this}; +r.encode=function(a){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&&("function"===typeof this.normalize?a=this.normalize(a):a=E?a.normalize("NFKD").replace(E,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),d!==e&&this.filter&& +e.length>=this.minlength&&("function"===typeof this.filter?!this.filter(e):this.filter.has(e))&&(e=""));if(e&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(e&&this.replacer)for(d=0;e&&dthis.A&&(this.j.clear(),this.o=this.o/1.1|0));e&&b.push(e)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.m&&(this.i.set(a,b),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return b};function G(a){a.l=null;a.i.clear();a.j.clear()};function H(a,c,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>c?c?a.slice(b,b+c):a.slice(b):a;let f=[];for(let d=0,g,e;d=e){b-=e;continue}bc&&(g=g.slice(0,c),e=c);if(!f.length&&e>=c)return g;f.push(g);c-=e;if(!c)break}return f=1this.limit&&this.cache.delete(this.cache.keys().next().value)};I.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};I.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; +I.prototype.clear=function(){this.cache.clear();this.g=""};const J={normalize:function(a){return a.toLowerCase()}};const K={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};L.prototype.add=function(a,c,b,f){if(c&&(a||0===a)){if(!f&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(f=c.length){const n=w(),m=w(),v=this.depth,D=this.resolution;for(let p=0;pq;g--){e=l.substring(q,g);t=this.rtl?d-1-q:q;var h=this.score?this.score(c,l,p,e,t):M(D,f,p,d,t);N(this, +m,e,h,a,b)}break}case "reverse":if(1e?0:1),f,p,h-1,k-1),t=this.bidirectional&& l>g;N(this,n,t?g:l,q,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function N(a,c,b,f,d,g,e){let h=e?a.ctx:a.map,k;if(!c[b]||e&&!(k=c[b])[e])e?(c=k||(c[b]=w()),c[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function M(a,c,b,f,d){return b&&1c||d?e.slice(d,c+d):e;e=a}else{if(ac||d)e=e.slice(d,c+d)}m=e}else if(1===f){c=H.call(null,a[0],c,d);break a}c=m}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};L.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;fd.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function P(a,c){let b=0;if(a.constructor===Array)for(let f=0,d,g;fc||d?e.slice(d,c+d):e;e=a}else{if(ac||d)e=e.slice(d,c+d)}m=e}else if(1===f){c=H.call(null,a[0], +c,d);break a}c=m}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};L.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;fd.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function P(a,c){let b=0;if(a.constructor===Array)for(let f=0,d,g;fb.add(a,c)):this.add(a,c)}; -function Q(a){let c=0;if(a.constructor===Array)for(let b=0,f;b this.stemmer.get(k)), e.length < this.minlength || this.filter && this.filter.has(e)) && (e = ""); + this.stemmer && 2 < e.length && (this.u || (this.u = new RegExp("(?!^)(" + this.h + ")$")), d = e, e = e.replace(this.u, k => this.stemmer.get(k)), d !== e && this.filter && e.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(e) : this.filter.has(e)) && (e = "")); if (e && (this.mapper || this.dedupe && 1 < e.length)) { d = ""; for (let k = 0, n = "", m, v; k < e.length; k++) { @@ -299,12 +299,12 @@ L.prototype.add = function(a, c, b, f) { } c = this.encoder.encode(c); if (f = c.length) { - const n = w(), m = w(), v = this.depth, C = this.resolution; + const n = w(), m = w(), v = this.depth, D = this.resolution; for (let p = 0; p < f; p++) { let l = c[this.rtl ? f - 1 - p : p]; var d = l.length; if (d && (v || !m[l])) { - var g = this.score ? this.score(c, l, p, null, 0) : M(C, f, p), e = ""; + var g = this.score ? this.score(c, l, p, null, 0) : M(D, f, p), e = ""; switch(this.tokenize) { case "full": if (2 < d) { @@ -312,7 +312,7 @@ L.prototype.add = function(a, c, b, f) { for (g = d; g > q; g--) { e = l.substring(q, g); t = this.rtl ? d - 1 - q : q; - var h = this.score ? this.score(c, l, p, e, t) : M(C, f, p, d, t); + var h = this.score ? this.score(c, l, p, e, t) : M(D, f, p, d, t); N(this, m, e, h, a, b); } } @@ -322,7 +322,7 @@ L.prototype.add = function(a, c, b, f) { if (1 < d) { for (h = d - 1; 0 < h; h--) { e = l[this.rtl ? d - 1 - h : h] + e; - var k = this.score ? this.score(c, l, p, e, h) : M(C, f, p, d, h); + var k = this.score ? this.score(c, l, p, e, h) : M(D, f, p, d, h); N(this, m, e, k, a, b); } e = ""; @@ -398,7 +398,7 @@ function M(a, c, b, f, d) { l = O(this, q, m); a: { g = l; - var v = f, C = e, p = k; + var v = f, D = e, p = k; let t = []; if (g && g.length) { if (g.length <= p) { @@ -406,9 +406,9 @@ function M(a, c, b, f, d) { l = void 0; break a; } - for (let x = 0, E; x < p; x++) { - if (E = g[x]) { - t[x] = E; + for (let x = 0, A; x < p; x++) { + if (A = g[x]) { + t[x] = A; } } if (t.length) { @@ -417,7 +417,7 @@ function M(a, c, b, f, d) { break a; } } - l = C ? void 0 : t; + l = D ? void 0 : t; } if (l) { f = l; @@ -437,11 +437,14 @@ function M(a, c, b, f, d) { m = a.length; e = []; b = w(); - for (let l = 0, q, t, x, E; l < k; l++) { + for (let l = 0, q, t, x, A; l < k; l++) { for (n = 0; n < m; n++) { if (x = a[n], l < x.length && (q = x[l])) { for (g = 0; g < q.length; g++) { - t = q[g], (h = b[t]) ? b[t]++ : (h = 0, b[t] = 1), E = e[h] || (e[h] = []), E.push(t); + if (t = q[g], (h = b[t]) ? b[t]++ : (h = 0, b[t] = 1), A = e[h] || (e[h] = []), A.push(t), c && h === m - 1 && A.length - d === c) { + m = A; + break b; + } } } } @@ -556,11 +559,12 @@ function P(a, c) { const f = !0 === b ? {depth:1} : b || {}, d = a.encode || a.encoder || J; this.encoder = d.encode ? d : "object" === typeof d ? new F(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = (b = a.tokenize) && "default" !== b && b || "strict"; + this.tokenize = b = (b = a.tokenize) && "default" !== b && b || "strict"; this.depth = "strict" === b && f.depth || 0; this.bidirectional = !1 !== f.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; + f && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); b = !1; this.map = new Map(); this.ctx = new Map(); @@ -594,7 +598,7 @@ function Q(a) { (f = a[b]) && (c += f.length); } } else { - for (const b of a) { + for (const b of a.entries()) { const f = b[0], d = Q(b[1]); d ? c += d : a.delete(f); } diff --git a/dist/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js index db8cd10..b16561b 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -1,28 +1,29 @@ /**! - * FlexSearch.js v0.8.123 (Bundle) + * FlexSearch.js v0.8.132 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var r;function u(a,c,b){const f=typeof b,d=typeof a;if("undefined"!==f){if("undefined"!==d){if(b){if("function"===d&&f===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var g=new Map(b);for(var 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"undefined"===d?c:a}function w(){return Object.create(null)};const y=/[^\p{L}\p{N}]+/u,z=/(\d{3})/g,A=/(\D)(\d{3})/g,B=/(\d{3})(\D)/g,D="".normalize&&/[\u0300-\u036f]/g;function F(a={}){if(!this||this.constructor!==F)return new F(...arguments);if(arguments.length)for(a=0;a"a1a".split(b).length; -this.numeric=u(a.numeric,f)}else{try{this.split=u(this.split,y)}catch(d){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);this.rtl=u(a.rtl,!1,this.rtl);this.dedupe=u(a.dedupe,!1,this.dedupe);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), -null,this.stemmer);this.replacer=u(a.replacer,null,this.replacer);this.minlength=u(a.minlength,1,this.minlength);this.maxlength=u(a.maxlength,0,this.maxlength);if(this.cache=b=u(a.cache,!0,this.cache))this.l=null,this.A="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.o=this.m=128;this.g="";this.s=null;this.h="";this.u=null;if(this.matcher)for(const d of this.matcher.keys())this.g+=(this.g?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.h+=(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){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&G(this);return this};r.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(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("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&G(this);return this}; -r.encode=function(a){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&&("function"===typeof this.normalize?a=this.normalize(a):a=D?a.normalize("NFKD").replace(D,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),e.lengththis.matcher.get(k)));if(e&&this.replacer)for(d=0;e&&dthis.A&& -(this.j.clear(),this.o=this.o/1.1|0));e&&b.push(e)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.m&&(this.i.set(a,b),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return b};function G(a){a.l=null;a.i.clear();a.j.clear()};function H(a,c,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>c?c?a.slice(b,b+c):a.slice(b):a;let f=[];for(let d=0,g,e;d=e){b-=e;continue}bc&&(g=g.slice(0,c),e=c);if(!f.length&&e>=c)return g;f.push(g);c-=e;if(!c)break}return f=1this.limit&&this.cache.delete(this.cache.keys().next().value)};I.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};I.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; -I.prototype.clear=function(){this.cache.clear();this.g=""};const J={normalize:function(a){return a.toLowerCase()}};const K={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};L.prototype.add=function(a,c,b,f){if(c&&(a||0===a)){if(!f&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(f=c.length){const n=w(),m=w(),v=this.depth,C=this.resolution;for(let p=0;pq;g--){e=l.substring(q,g);t=this.rtl?d-1-q:q;var h=this.score?this.score(c,l,p,e,t):M(C,f,p,d,t);N(this, -m,e,h,a,b)}break}case "reverse":if(1e?0:1),f,p,h-1,k-1),t=this.bidirectional&& +this.numeric=u(a.numeric,f)}else{try{this.split=u(this.split,y)}catch(d){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:u(b&&new Set(b),null,this.filter);this.dedupe=u(a.dedupe,!1,this.dedupe);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), +null,this.stemmer);this.replacer=u(a.replacer,null,this.replacer);this.minlength=u(a.minlength,1,this.minlength);this.maxlength=u(a.maxlength,0,this.maxlength);this.rtl=u(a.rtl,!1,this.rtl);if(this.cache=b=u(a.cache,!0,this.cache))this.l=null,this.A="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.o=this.m=128;this.g="";this.s=null;this.h="";this.u=null;if(this.matcher)for(const d of this.matcher.keys())this.g+=(this.g?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.h+= +(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){"function"===typeof a?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("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(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("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&G(this);return this}; +r.encode=function(a){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&&("function"===typeof this.normalize?a=this.normalize(a):a=E?a.normalize("NFKD").replace(E,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),d!==e&&this.filter&& +e.length>=this.minlength&&("function"===typeof this.filter?!this.filter(e):this.filter.has(e))&&(e=""));if(e&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(e&&this.replacer)for(d=0;e&&dthis.A&&(this.j.clear(),this.o=this.o/1.1|0));e&&b.push(e)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.m&&(this.i.set(a,b),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return b};function G(a){a.l=null;a.i.clear();a.j.clear()};function H(a,c,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>c?c?a.slice(b,b+c):a.slice(b):a;let f=[];for(let d=0,g,e;d=e){b-=e;continue}bc&&(g=g.slice(0,c),e=c);if(!f.length&&e>=c)return g;f.push(g);c-=e;if(!c)break}return f=1this.limit&&this.cache.delete(this.cache.keys().next().value)};I.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};I.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; +I.prototype.clear=function(){this.cache.clear();this.g=""};const J={normalize:function(a){return a.toLowerCase()}};const K={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};L.prototype.add=function(a,c,b,f){if(c&&(a||0===a)){if(!f&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(f=c.length){const n=w(),m=w(),v=this.depth,D=this.resolution;for(let p=0;pq;g--){e=l.substring(q,g);t=this.rtl?d-1-q:q;var h=this.score?this.score(c,l,p,e,t):M(D,f,p,d,t);N(this, +m,e,h,a,b)}break}case "reverse":if(1e?0:1),f,p,h-1,k-1),t=this.bidirectional&& l>g;N(this,n,t?g:l,q,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function N(a,c,b,f,d,g,e){let h=e?a.ctx:a.map,k;if(!c[b]||e&&!(k=c[b])[e])e?(c=k||(c[b]=w()),c[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function M(a,c,b,f,d){return b&&1c||d?e.slice(d,c+d):e;e=a}else{if(ac||d)e=e.slice(d,c+d)}m=e}else if(1===f){c=H.call(null,a[0],c,d);break a}c=m}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};L.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;fd.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function P(a,c){let b=0;if(a.constructor===Array)for(let f=0,d,g;fc||d?e.slice(d,c+d):e;e=a}else{if(ac||d)e=e.slice(d,c+d)}m=e}else if(1===f){c=H.call(null,a[0], +c,d);break a}c=m}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};L.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;fd.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function P(a,c){let b=0;if(a.constructor===Array)for(let f=0,d,g;fb.add(a,c)):this.add(a,c)}; -function Q(a){let c=0;if(a.constructor===Array)for(let b=0,f;b} +// */ -/** - * @param {!number} count - * @returns {Array} - */ +// export function create_object_array(count){ +// +// const array = new Array(count); +// +// for(let i = 0; i < count; i++){ +// array[i] = create_object(); +// } +// +// return array; +// } -export function create_object_array(count) { +// /** +// * @param {!number} count +// * @returns {Array} +// */ - const array = Array(count); +// export function create_map_array(count){ +// +// const array = new Array(count); +// +// for(let i = 0; i < count; i++){ +// array[i] = new Map(); +// } +// +// return array; +// } - for (let i = 0; i < count; i++) { - array[i] = create_object(); - } +// export function create_arrays(count){ +// +// const array = new Array(count); +// +// for(let i = 0; i < count; i++){ +// array[i] = []; +// } +// +// return array; +// } +// +// /** +// * @param {!Object} obj +// * @returns {Array} +// */ - return array; -} - -/** - * @param {!number} count - * @returns {Array} - */ - -export function create_map_array(count) { - - const array = Array(count); - - for (let i = 0; i < count; i++) { - array[i] = new Map(); - } - - return array; -} - -export function create_arrays(count) { - - const array = Array(count); - - for (let i = 0; i < count; i++) { - array[i] = []; - } - - return array; -} - -/** - * @param {!Object} obj - * @returns {Array} - */ - -export function get_keys(obj) { - return Object.keys(obj); -} +// export function get_keys(obj){ +// return Object.keys(obj); +// } export function create_object() { return Object.create(null); diff --git a/dist/module-debug/db/clickhouse/index.js b/dist/module-debug/db/clickhouse/index.js index 70d479c..5d5bcfe 100644 --- a/dist/module-debug/db/clickhouse/index.js +++ b/dist/module-debug/db/clickhouse/index.js @@ -1,4 +1,3 @@ - import { ClickHouse } from "clickhouse"; import StorageInterface from "../interface.js"; import { concat, toArray } from "../../common.js"; @@ -174,8 +173,8 @@ ClickhouseDB.prototype.open = async function () { }; ClickhouseDB.prototype.close = function () { - this.db.close(); - this.db = null; + //DB && DB.close(); + this.db = DB = null; return this; }; @@ -306,17 +305,16 @@ ClickhouseDB.prototype.enrich = async function (ids) { return 1 === result.length ? result[0] : 1 < result.length ? concat(result) : result; }; -ClickhouseDB.prototype.has = function (id) { - return this.db.query(` - SELECT EXISTS( - SELECT 1 - FROM ${this.id}.reg - WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}} - LIMIT 1 - )`, { params: { id } }).toPromise(); +ClickhouseDB.prototype.has = async function (id) { + const result = await this.db.query(` + SELECT 1 as exist + FROM ${this.id}.reg + WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}} + LIMIT 1`, { params: { id } }).toPromise(); + return !!(result && result[0] && result[0].exist); }; -ClickhouseDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !0, tags) { +ClickhouseDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) { let rows; if (1 < query.length && flexsearch.depth) { let where = "", @@ -349,7 +347,7 @@ ClickhouseDB.prototype.search = function (flexsearch, query, limit = 100, offset ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM ${this.id}.ctx${this.field} WHERE ${where} GROUP BY id @@ -414,7 +412,7 @@ ClickhouseDB.prototype.search = function (flexsearch, query, limit = 100, offset ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM ${this.id}.map${this.field} WHERE ${where} GROUP BY id diff --git a/dist/module-debug/db/indexeddb/index.js b/dist/module-debug/db/indexeddb/index.js index 8963b04..d7590d0 100644 --- a/dist/module-debug/db/indexeddb/index.js +++ b/dist/module-debug/db/indexeddb/index.js @@ -114,7 +114,7 @@ IdxDB.prototype.open = function () { }; IdxDB.prototype.close = function () { - this.db.close(); + this.db && this.db.close(); this.db = null; }; @@ -253,7 +253,9 @@ IdxDB.prototype.has = function (id) { map = transaction.objectStore("reg"), req = map.getKey(id); - return promisfy(req); + return promisfy(req).then(function (result) { + return !!result; + }); }; IdxDB.prototype.search = null; diff --git a/dist/module-debug/db/mongodb/index.js b/dist/module-debug/db/mongodb/index.js index 821b24a..76a3497 100644 --- a/dist/module-debug/db/mongodb/index.js +++ b/dist/module-debug/db/mongodb/index.js @@ -124,8 +124,9 @@ MongoDB.prototype.open = async function () { }; MongoDB.prototype.close = function () { - this.db.close(); - this.db = null; + //CLIENT && CLIENT.close(); + this.db = CLIENT = null; + DB[this.id] = null; return this; }; @@ -257,7 +258,9 @@ MongoDB.prototype.enrich = function (ids) { }; MongoDB.prototype.has = function (id) { - return this.db.collection("reg").countDocuments({ id }, { limit: 1 }); + return this.db.collection("reg").countDocuments({ id }, { limit: 1 }).then(function (result) { + return !!result; + }); }; MongoDB.prototype.search = async function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) { @@ -281,12 +284,14 @@ MongoDB.prototype.search = async function (flexsearch, query, limit = 100, offse keyword = term; } - let project = resolve ? { _id: 1 } : { _id: 1, res: 1 }; + const project = { _id: 1 }; + if (!resolve) project.res = 1; + if (enrich) project.doc = 1; const stmt = [{ $match: { $or: params } }, { $group: { _id: "$id", - res: suggest ? { $sum: 1 } : { $min: 1 }, - count: { $sum: 1 } + count: { $sum: 1 }, + res: suggest ? { $sum: "$res" } : { $sum /*$min*/: "$res" } } }]; suggest || stmt.push({ $match: { count: query.length - 1 } }); @@ -319,32 +324,34 @@ MongoDB.prototype.search = async function (flexsearch, query, limit = 100, offse count++; } - stmt.push({ $project: project }, { $match: match }); - } else { - stmt.push({ $project: project }); + stmt.push( + //{ $project: project }, + { $match: match }); } stmt.push({ $sort: suggest ? { count: -1, res: 1 } : { res: 1 } }, { $skip: offset }, { $limit: limit }); - if (tags) { - project = { _id: 1 }; - if (!resolve) project.res = 1; - if (enrich) project.doc = 1; + // if(tags){ + // project = { _id: 1 }; + // if(!resolve) project["res"] = 1; + // if(enrich) project["doc"] = 1; + // } - stmt.push({ $project: project }); - } + stmt.push({ $project: project }); rows = await this.db.collection("ctx" + this.field).aggregate(stmt); } else { - let project = resolve ? { _id: 1 } : { _id: 1, res: 1 }; + const project = { _id: 1 }; + if (!resolve) project.res = 1; + if (enrich) project.doc = 1; const stmt = [{ $match: { key: { $in: query } } }, { $group: { _id: "$id", - res: suggest ? { $sum: 1 } : { $min: 1 }, - count: { $sum: 1 } + count: { $sum: 1 }, + res: suggest ? { $sum: "$res" } : { $sum /*$min*/: "$res" } } }]; suggest || stmt.push({ $match: { count: query.length } }); @@ -377,20 +384,20 @@ MongoDB.prototype.search = async function (flexsearch, query, limit = 100, offse count++; } - stmt.push({ $project: project }, { $match: match }); - } else { - stmt.push({ $project: project }); + stmt.push( + //{ $project: project }, + { $match: match }); } stmt.push({ $sort: suggest ? { count: -1, res: 1 } : { res: 1 } }, { $skip: offset }, { $limit: limit }); - if (tags) { - project = { _id: 1 }; - if (!resolve) project.res = 1; - if (enrich) project.doc = 1; + // if(tags){ + // project = { _id: 1 }; + // if(!resolve) project["res"] = 1; + // if(enrich) project["doc"] = 1; + // } - stmt.push({ $project: project }); - } + stmt.push({ $project: project }); rows = await this.db.collection("map" + this.field).aggregate(stmt); } diff --git a/dist/module-debug/db/postgres/index.js b/dist/module-debug/db/postgres/index.js index db7f62d..caf208a 100644 --- a/dist/module-debug/db/postgres/index.js +++ b/dist/module-debug/db/postgres/index.js @@ -1,5 +1,3 @@ - - import pg_promise from "pg-promise"; import StorageInterface from "../interface.js"; import { concat, toArray } from "../../common.js"; @@ -11,7 +9,7 @@ const defaults = { host: "localhost", port: "5432" }, - pgp = pg_promise({ noWarnings: ! /* tag? */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ }), + pgp = pg_promise(), VERSION = 1, MAXIMUM_QUERY_VARS = 16000, fields = ["map", "ctx", "reg", "tag", "cfg"], @@ -55,7 +53,7 @@ export default function PostgresDB(name, config = {}) { } if ("object" == typeof name) { config = name; - name = name.name; + name = config.name; } if (!name) { console.info("Default storage space was used, because a name was not passed."); @@ -63,7 +61,8 @@ export default function PostgresDB(name, config = {}) { this.id = (config.schema ? sanitize(config.schema) : defaults.schema) + (name ? "_" + sanitize(name) : ""); this.field = config.field ? "_" + sanitize(config.field) : ""; this.type = config.type ? types[config.type.toLowerCase()] : "text"; - this.support_tag_search = !0; + this.support_tag_search = /* tag? */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ + /*await rows.hasNext()*/; if (!this.type) throw new Error("Unknown type of ID '" + config.type + "'"); this.db = DB || (DB = config.db || null); Object.assign(defaults, config); @@ -178,8 +177,8 @@ PostgresDB.prototype.open = async function () { }; PostgresDB.prototype.close = function () { - this.db.close && this.db.close(); - this.db = DB = null; + //DB && DB.close && DB.close(); + this.db = /*DB =*/null; return this; }; @@ -318,7 +317,9 @@ PostgresDB.prototype.enrich = async function (ids) { }; PostgresDB.prototype.has = function (id) { - return this.db.oneOrNone("SELECT EXISTS(SELECT 1 FROM " + this.id + ".reg WHERE id = $1)", [id]); + return this.db.oneOrNone("SELECT EXISTS(SELECT 1 FROM " + this.id + ".reg WHERE id = $1)", [id]).then(function (result) { + return !!(result && result.exists); + }); }; PostgresDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) { @@ -356,7 +357,7 @@ PostgresDB.prototype.search = function (flexsearch, query, limit = 100, offset = ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM ${this.id}.ctx${this.field} WHERE ${where} GROUP BY id @@ -406,8 +407,7 @@ PostgresDB.prototype.search = function (flexsearch, query, limit = 100, offset = for (let i = 0; i < query_length; i++) { where += (where ? "," : "") + "$" + count++; - } - where = "key " + (1 < query_length ? "IN (" + where + ")" : "= " + where); + }where = "key " + (1 < query_length ? "IN (" + where + ")" : "= " + where); if (tags) { where = "(" + where + ")"; @@ -423,7 +423,7 @@ PostgresDB.prototype.search = function (flexsearch, query, limit = 100, offset = ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM ${this.id}.map${this.field} WHERE ${where} GROUP BY id @@ -523,17 +523,23 @@ PostgresDB.prototype.info = function () { // }; PostgresDB.prototype.transaction = function (task) { - if (TRX) { - return task.call(this, TRX); - } const self = this; - return (TRX || this.db).tx(function (trx) { - return task.call(self, TRX = trx); - }).finally(function () { - TRX = null; + return this.db.tx(function (trx) { + return task.call(self, trx); }); }; +// PostgresDB.prototype.transaction = async function(task){ +// if(TRX){ +// return await task.call(this, TRX); +// } +// const self = this; +// return this.db.tx(async function(trx){ +// await task.call(self, TRX = trx); +// TRX = null; +// }); +// }; + PostgresDB.prototype.commit = async function (flexsearch, _replace, _append) { // process cleanup tasks diff --git a/dist/module-debug/db/redis/index.js b/dist/module-debug/db/redis/index.js index 51d12d6..cdcdeae 100644 --- a/dist/module-debug/db/redis/index.js +++ b/dist/module-debug/db/redis/index.js @@ -1,5 +1,3 @@ - - import { createClient } from "redis"; const defaults = { host: "localhost", @@ -74,7 +72,7 @@ RedisDB.prototype.open = async function () { }; RedisDB.prototype.close = async function () { - await this.db.disconnect(); // this.db.client.disconnect(); + // this.db.client.disconnect(); this.db = null; return this; }; @@ -167,14 +165,14 @@ RedisDB.prototype.has = function (id) { }; RedisDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) { + let result, + params = []; - let result; if (1 < query.length && flexsearch.depth) { const key = this.id + "ctx" + this.field + ":"; - let params = [], - keyword = query[0], + let keyword = query[0], term; @@ -184,29 +182,37 @@ RedisDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, params.push(key + (swap ? term : keyword) + ":" + (swap ? keyword : term)); keyword = term; } - query = params; } else { const key = this.id + "map" + this.field + ":"; for (let i = 0; i < query.length; i++) { - query[i] = key + query[i]; + params.push(key + query[i]); } } + query = params; + const type = this.type; let key = this.id + "tmp:" + Math.random(); if (suggest) { - if (tags) for (let i = 0; i < tags.length; i += 2) { - query.push(this.id + "tag-" + sanitize(tags[i]) + ":" + tags[i + 1]); - } - const multi = this.db.multi().zUnionStore(key, query, { AGGREGATE: "SUM" }); // Strict Tag Intersection: it does not put tags into union, instead it calculates the // intersection against the term match union. This was the default behavior // of Tag-Search. But putting everything into union will also provide suggestions derived // from tags when no term was matched. + if (tags) { + // copy over zInterStore into the same destination surprisingly works fine + // const key2 = key + ":2"; + query = [key]; + for (let i = 0; i < tags.length; i += 2) { + query.push(this.id + "tag-" + sanitize(tags[i]) + ":" + tags[i + 1]); + } + multi.zInterStore(key, query, { AGGREGATE: "SUM" }); + // .unlink(key) + // key = key2; + } result = multi[resolve ? "zRange" : "zRangeWithScores"](key, "" + offset, "" + (offset + limit - 1), { REV: !0 }).unlink(key).exec(); } else { diff --git a/dist/module-debug/db/sqlite/index.js b/dist/module-debug/db/sqlite/index.js index 36c0f9c..3b6f068 100644 --- a/dist/module-debug/db/sqlite/index.js +++ b/dist/module-debug/db/sqlite/index.js @@ -1,5 +1,3 @@ - - //const sqlite3 = require("sqlite3").verbose(); import sqlite3 from "sqlite3"; import path from "path"; @@ -197,7 +195,7 @@ SqliteDB.prototype.open = async function () { }; SqliteDB.prototype.close = function () { - this.db.close(); + this.db && this.db.close(); this.db = null; DB[this.id] = null; TRX[this.id] = null; @@ -392,7 +390,7 @@ SqliteDB.prototype.has = function (id) { stmt: `SELECT EXISTS(SELECT 1 FROM main.reg WHERE id = ?) as exist`, params: [id] }).then(function (result) { - return result && result.exist; + return !!(result && result.exist); }); }; @@ -431,7 +429,7 @@ SqliteDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0 ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM main.ctx${this.field} WHERE ${stmt} GROUP BY id @@ -500,7 +498,7 @@ SqliteDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0 ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM main.map${this.field} WHERE ${stmt} GROUP BY id @@ -554,15 +552,13 @@ SqliteDB.prototype.info = function () { SqliteDB.prototype.transaction = function (task, callback) { - const self = this; - if (TRX[this.id]) { - return TRX[this.id].then(function () { - return self.transaction(task, callback); - }); + return task.call(this); } - const db = this.db; + const db = this.db, + self = this; + return TRX[this.id] = new Promise(function (resolve, reject) { db.exec("PRAGMA optimize"); @@ -780,8 +776,8 @@ SqliteDB.prototype.remove = function (ids) { this.db.run("DELETE FROM main.ctx" + self.field + " WHERE id IN (" + stmt + ")", ids); this.db.run("DELETE FROM main.tag" + self.field + " WHERE id IN (" + stmt + ")", ids); this.db.run("DELETE FROM main.reg WHERE id IN (" + stmt + ")", ids); - }).then(function (res) { - return next ? self.remove(next) : res; + }).then(function (result) { + return next ? self.remove(next) : result; }); }; diff --git a/dist/module-debug/document.js b/dist/module-debug/document.js index 5c8ed48..653aade 100644 --- a/dist/module-debug/document.js +++ b/dist/module-debug/document.js @@ -43,9 +43,7 @@ export default function Document(options) { keystore && (this.keystore = keystore); this.fastupdate = !!options.fastupdate; // Shared Registry - this.reg = this.fastupdate && !options.worker && !options.db ? keystore && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ - - ? new KeystoreMap(keystore) : new Map() : keystore && !0 ? new KeystoreSet(keystore) : new Set(); + this.reg = this.fastupdate && !options.worker && !options.db ? keystore && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ ? new KeystoreMap(keystore) : new Map() : keystore && !0 ? new KeystoreSet(keystore) : new Set(); // todo support custom filter function this.storetree = (tmp = document.store || null) && tmp && !0 !== tmp && []; @@ -54,9 +52,7 @@ export default function Document(options) { this.cache = (tmp = options.cache || null) && new Cache(tmp); // do not apply cache again for the indexes since .searchCache() // is just a wrapper over .search() - options.cache = /* suggest */ /* append: */ /* enrich */ - - !1; + options.cache = /* suggest */ /* append: */ /* enrich */!1; this.worker = options.worker; @@ -208,7 +204,7 @@ Document.prototype.commit = async function (replace, append) { // parallel: const promises = []; for (const index of this.index.values()) { - promises.push(index.db.commit(index, replace, append)); + promises.push(index.commit(index, replace, append)); } await Promise.all(promises); this.reg.clear(); @@ -404,15 +400,15 @@ Document.prototype.remove = function (id) { Document.prototype.clear = function () { - //const promises = []; + const promises = []; for (const index of this.index.values()) { // db index will add clear task - index.clear(); - // const promise = index.clear(); - // if(promise instanceof Promise){ - // promises.push(promise); - // } + const promise = index.clear(); + // worker indexes will return promises + if (promise.then) { + promises.push(promise); + } } if (this.tag) { @@ -425,9 +421,11 @@ Document.prototype.clear = function () { this.store.clear(); } - return this; /*promises.length - ? Promise.all(promises) - :*/ + if (this.cache) { + this.cache.clear(); + } + + return promises.length ? Promise.all(promises) : this; }; /** @@ -435,6 +433,7 @@ Document.prototype.clear = function () { * @return {boolean|Promise} */ Document.prototype.contain = function (id) { + if (this.db) { return this.index.get(this.field[0]).db.has(id); } diff --git a/dist/module-debug/document/search.js b/dist/module-debug/document/search.js index f16d0ce..d6f02b8 100644 --- a/dist/module-debug/document/search.js +++ b/dist/module-debug/document/search.js @@ -1,5 +1,5 @@ -import { DocumentSearchOptions, DocumentSearchResults, EnrichedDocumentSearchResults, MergedDocumentSearchResults, EnrichedSearchResults, SearchResults, IntermediateSearchResults } from "../type.js"; +import { DocumentSearchOptions, DocumentSearchResults, EnrichedDocumentSearchResults, MergedDocumentSearchResults, MergedDocumentSearchEntry, EnrichedSearchResults, SearchResults, IntermediateSearchResults } from "../type.js"; import { create_object, is_array, is_object, is_string, parse_simple } from "../common.js"; import { intersect_union } from "../intersect.js"; import Document from "../document.js"; @@ -105,7 +105,7 @@ Document.prototype.search = function (query, limit, options, _promises) { enrich = this.store && options.enrich && resolve; - highlight = options.highlight && enrich; + highlight = enrich && options.highlight; limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); @@ -438,7 +438,7 @@ function highlight_fields(result, query, index, field, tree, template) { // if(typeof template === "string"){ // template = new RegExp(template, "g"); // } - + console.log("template", template); let encoder, query_enc, tokenize; @@ -518,7 +518,7 @@ function highlight_fields(result, query, index, field, tree, template) { * @return {MergedDocumentSearchResults} */ function merge_fields(fields, limit) { - /** @type {MergedDocumentSearchResults} */ + /** @type {Array} */ const final = [], set = create_object(); @@ -547,7 +547,7 @@ function merge_fields(fields, limit) { return final; } entry.field = set[id] = [field.field]; - final.push(entry); + final.push( /** @type {MergedDocumentSearchEntry} */entry); } else { tmp.push(field.field); } diff --git a/dist/module-debug/encoder.js b/dist/module-debug/encoder.js index 5cc15e7..cbc522d 100644 --- a/dist/module-debug/encoder.js +++ b/dist/module-debug/encoder.js @@ -91,9 +91,7 @@ Encoder.prototype.assign = function (options) { * pre-processing string input * @type {Function|boolean} */ - this.normalize = /** @type {Function|boolean} */merge_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ - - /*await rows.hasNext()*/, this.normalize); + this.normalize = /** @type {Function|boolean} */merge_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, this.normalize); // { // letter: true, @@ -185,20 +183,16 @@ Encoder.prototype.assign = function (options) { /** @type {Array>} */normalize_polyfill); } - // options - - this.rtl = merge_option(options.rtl, !1, this.rtl); + tmp = options.filter; + this.filter = "function" == typeof tmp ? tmp : merge_option(tmp && new Set(tmp), null, this.filter); this.dedupe = merge_option(options.dedupe, !1, this.dedupe); - this.filter = merge_option((tmp = options.filter) && new Set(tmp), null, this.filter); this.matcher = merge_option((tmp = options.matcher) && new Map(tmp), null, this.matcher); this.mapper = merge_option((tmp = options.mapper) && new Map(tmp), null, this.mapper); this.stemmer = merge_option((tmp = options.stemmer) && new Map(tmp), null, this.stemmer); this.replacer = merge_option(options.replacer, null, this.replacer); this.minlength = merge_option(options.minlength, 1, this.minlength); this.maxlength = merge_option(options.maxlength, 0, this.maxlength); - - // minimum required tokenizer by this encoder - //this.tokenize = options["tokenize"] || ""; + this.rtl = merge_option(options.rtl, !1, this.rtl); // auto-balanced cache this.cache = tmp = merge_option(options.cache, !0, this.cache); @@ -260,8 +254,13 @@ Encoder.prototype.addStemmer = function (match, replace) { }; Encoder.prototype.addFilter = function (term) { - this.filter || (this.filter = new Set()); - this.filter.add(term); + if ("function" == typeof term) { + // does not support merge yet + this.filter = term; //merge_option(term, term, this.filter); + } else { + this.filter || (this.filter = new Set()); + this.filter.add(term); + } this.cache && clear(this); return this; }; @@ -401,7 +400,7 @@ Encoder.prototype.encode = function (str) { } // pre-filter before cache - if (this.filter && this.filter.has(word)) { + if (this.filter && ("function" == typeof this.filter ? !this.filter(word) : this.filter.has(word))) { continue; } @@ -416,16 +415,17 @@ Encoder.prototype.encode = function (str) { this.timer = setTimeout(clear, 50, this); } } + + // todo compare advantages when filter/stemmer are also encoded + // apply stemmer before bigger transformations if (this.stemmer && 2 < word.length) { // for(const item of this.stemmer){ // const key = item[0]; // const value = item[1]; - // // if(word.length > key.length && word.endsWith(key)){ // word = word.substring(0, word.length - key.length) + value; // break; // } - // // // const position = word.length - key.length; // // if(position > 0 && word.substring(position) === key){ // // word = word.substring(0, position) + value; @@ -433,11 +433,15 @@ Encoder.prototype.encode = function (str) { // // } // } this.stemmer_test || (this.stemmer_test = new RegExp("(?!^)(" + this.stemmer_str + ")$")); + + const old = word; word = word.replace(this.stemmer_test, match => this.stemmer.get(match)); - // 4. post-filter after matcher and stemmer was applied - if (word.length < this.minlength || this.filter && this.filter.has(word)) { - word = ""; + // 4. post-filter after stemmer was applied + if (old !== word && this.filter && word.length >= this.minlength) { + if ("function" == typeof this.filter ? !this.filter(word) : this.filter.has(word)) { + word = ""; + } } } diff --git a/dist/module-debug/index.js b/dist/module-debug/index.js index afb61ff..520b32b 100644 --- a/dist/module-debug/index.js +++ b/dist/module-debug/index.js @@ -35,9 +35,10 @@ export default function Index(options, _register) { options = /** @type IndexOptions */options ? apply_preset(options) : {}; + /** @type {*} */ let tmp = options.context; /** @type ContextOptions */ - const context = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ === tmp ? { depth: 1 } : tmp || {}, + const context = /** @type ContextOptions */ /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ === tmp ? { depth: 1 } : tmp || {}, encoder = is_string(options.encoder) ? Charset[options.encoder] : options.encode || options.encoder || default_encoder; /** @type Encoder */ @@ -47,12 +48,17 @@ export default function Index(options, _register) { this.resolution = options.resolution || 9; - this.tokenize = (tmp = options.tokenize) && "default" !== tmp && tmp || "strict"; + this.tokenize = tmp = (tmp = options.tokenize) && "default" !== tmp && tmp || "strict"; this.depth = "strict" === tmp && context.depth || 0; this.bidirectional = !1 !== context.bidirectional; this.fastupdate = !!options.fastupdate; this.score = options.score || null; + if (context && "strict" !== this.tokenize) { + console.warn("Context-Search could not applied, because it is just supported when using the tokenizer \"strict\"."); + } + + tmp = options.keystore || 0; tmp && (this.keystore = tmp); @@ -167,7 +173,7 @@ function cleanup_index(map) { for (let i = 0, arr; i < map.length; i++) { (arr = map[i]) && (count += arr.length); } - } else for (const item of map) { + } else for (const item of map.entries()) { const key = item[0], value = item[1], tmp = cleanup_index(value); diff --git a/dist/module-debug/index/search.js b/dist/module-debug/index/search.js index 2fcd863..75d25a3 100644 --- a/dist/module-debug/index/search.js +++ b/dist/module-debug/index/search.js @@ -57,7 +57,8 @@ Index.prototype.search = function (query, limit, options) { offset = options.offset || 0; context = options.context; suggest = options.suggest; - resolve = /*global_resolve &&*/ /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; + resolve = /*global_resolve &&*/ /* suggest */ + /* append: */ /* enrich */!1 !== options.resolve; //resolve || (global_resolve = 0); enrich = resolve && options.enrich; boost = options.boost; diff --git a/dist/module-debug/intersect.js b/dist/module-debug/intersect.js index c5110f9..cf7105b 100644 --- a/dist/module-debug/intersect.js +++ b/dist/module-debug/intersect.js @@ -77,6 +77,19 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res } tmp.push(id); + + // fast path early result when limit was set + if (resolve) { + if (limit && count === length - 1) { + // if(tmp.length - offset > limit){ + // return tmp.slice(offset, limit + offset); + // } + if (tmp.length - offset === limit) { + return tmp; + } + } + } + // todo break early on suggest: true } } } @@ -104,6 +117,8 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res result = result.slice(offset, limit + offset); } } else { + // todo this is doing the same as Resolver.resolve({limit}) ? + // todo check limit + offset when resolve = false const final = []; for (let i = 0, arr; i < result.length; i++) { arr = result[i]; diff --git a/dist/module-debug/keystore.js b/dist/module-debug/keystore.js index ea7ac78..10a837e 100644 --- a/dist/module-debug/keystore.js +++ b/dist/module-debug/keystore.js @@ -1,63 +1,57 @@ import { create_object } from "./common.js"; -/** - * @param bitlength - * @constructor - */ - -export function KeystoreObj(bitlength = 8) { - - if (!this) { - return new KeystoreObj(bitlength); - } - - this.index = create_object(); - this.keys = []; - - if (32 < bitlength) { - this.crc = lcg64; - this.bit = BigInt(bitlength); - } else { - this.crc = lcg; - this.bit = bitlength; - } - - return (/*this.proxy =*/new Proxy(this, { - get(target, key) { - const address = target.crc(key), - obj = target.index[address]; - - return obj && obj[key]; - }, - set(target, key, value) { - const address = target.crc(key); - let obj = target.index[address]; - if (!obj) { - target.index[address] = obj = create_object(); - target.keys.push(address); - } - obj[key] = value; - return (/* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ - // splice: - !0 /*await rows.hasNext()*/ - /*await rows.hasNext()*/ /*await rows.hasNext()*/ - ); - }, - delete(target, key) { - const address = target.crc(key), - obj = target.index[address]; - - obj && delete obj[key]; - return !0; - } - }) - ); -} - -KeystoreObj.prototype.clear = function () { - this.index = create_object(); - this.keys = []; -}; +// /** +// * @param bitlength +// * @constructor +// */ +// +// export function KeystoreObj(bitlength = 8){ +// +// if(!this || this.constructor !== KeystoreObj){ +// return new KeystoreObj(bitlength); +// } +// +// this.index = create_object(); +// this.keys = []; +// +// if(bitlength > 32){ +// this.crc = lcg64; +// this.bit = BigInt(bitlength); +// } +// else { +// this.crc = lcg; +// this.bit = bitlength; +// } +// +// return /*this.proxy =*/ new Proxy(this, { +// get(target, key) { +// const address = target.crc(key); +// const obj = target.index[address]; +// return obj && obj[key]; +// }, +// set(target, key, value){ +// const address = target.crc(key); +// let obj = target.index[address]; +// if(!obj){ +// target.index[address] = obj = create_object(); +// target.keys.push(address); +// } +// obj[key] = value; +// return true; +// }, +// delete(target, key){ +// const address = target.crc(key); +// const obj = target.index[address]; +// obj && delete obj[key]; +// return true; +// } +// }); +// } +// +// KeystoreObj.prototype.clear = function(){ +// this.index = create_object(); +// this.keys = []; +// }; // KeystoreObj.prototype.destroy = function(){ // this.index = null; @@ -94,7 +88,7 @@ function _slice(self, start, end, splice) { export function KeystoreArray(arr) { - if (!this) { + if (!this || this.constructor !== KeystoreArray) { return new KeystoreArray(arr); } @@ -138,7 +132,11 @@ export function KeystoreArray(arr) { return function (key) { for (let i = 0; i < self.index.length; i++) { if (self.index[i].includes(key)) { - return !0; + return (/* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ + /* skip update: */ /* skip_update: */ /* skip deletion */ + // splice: + !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ + ); } } return (/* suggest */ /* append: */ /* enrich */!1 @@ -189,22 +187,43 @@ KeystoreArray.prototype.destroy = function () { KeystoreArray.prototype.push = function () {}; +/** + * @interface + */ +function Keystore() { + /** @type {Object} */ + this.index; + /** @type {Array} */ + this.refs; + /** @type {number} */ + this.size; + /** @type {function((string|number)):number} */ + this.crc; + /** @type {bigint|number} */ + this.bit; +} + /** * @param bitlength * @constructor + * @implements {Keystore} */ export function KeystoreMap(bitlength = 8) { - if (!this) { + if (!this || this.constructor !== KeystoreMap) { return new KeystoreMap(bitlength); } + /** @type {Object} */ this.index = create_object(); + /** @type {Array} */ this.refs = []; + /** @type {number} */ this.size = 0; if (32 < bitlength) { + /** @type {function((string|number)):number} */ this.crc = lcg64; this.bit = BigInt(bitlength); } else { @@ -231,26 +250,31 @@ KeystoreMap.prototype.set = function (key, value) { } else { this.index[address] = map = new Map([[key, value]]); this.refs.push(map); + this.size++; } }; /** * @param bitlength * @constructor + * @implements {Keystore} */ export function KeystoreSet(bitlength = 8) { - if (!this) { + if (!this || this.constructor !== KeystoreSet) { return new KeystoreSet(bitlength); } - // using plain Object with numeric key access - // just for max performance + /** @type {Object} */ this.index = create_object(); + /** @type {Array} */ this.refs = []; + /** @type {number} */ + this.size = 0; if (32 < bitlength) { + /** @type {function((string|number)):number} */ this.crc = lcg64; this.bit = BigInt(bitlength); } else { @@ -270,6 +294,7 @@ KeystoreSet.prototype.add = function (key) { } else { this.index[address] = set = new Set([key]); this.refs.push(set); + this.size++; } }; diff --git a/dist/module-debug/serialize.js b/dist/module-debug/serialize.js index 83482ed..e92750c 100644 --- a/dist/module-debug/serialize.js +++ b/dist/module-debug/serialize.js @@ -412,20 +412,41 @@ ctx: "gulliver+travel:1,2,3|4,5,6|7,8,9;" export function serialize(withFunctionWrapper = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice: !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/) { - - if (!this.reg.size) return ""; - let reg = '', - type = ""; + map = '', + ctx = ''; - for (const key of this.reg.keys()) { - type || (type = typeof key); - reg += (reg ? ',' : '') + ("string" == type ? '"' + key + '"' : key); + + if (this.reg.size) { + + let type; + for (const key of this.reg.keys()) { + type || (type = typeof key); + reg += (reg ? ',' : '') + ("string" === type ? '"' + key + '"' : key); + } + reg = 'index.reg=new Set([' + reg + ']);'; + + map = parse_map(this.map, type); + map = "index.map=new Map([" + map + "]);"; + + for (const context of this.ctx.entries()) { + const key_ctx = context[0], + value_ctx = context[1]; + + let ctx_map = parse_map(value_ctx, type); + ctx_map = "new Map([" + ctx_map + "])"; + ctx_map = '["' + key_ctx + '",' + ctx_map + ']'; + ctx += (ctx ? ',' : '') + ctx_map; + } + ctx = "index.ctx=new Map([" + ctx + "]);"; } - reg = 'index.reg=new Set([' + reg + ']);'; - let map = ''; - for (const item of this.map.entries()) { + return withFunctionWrapper ? "function inject(index){" + reg + map + ctx + "}" : reg + map + ctx; +} + +function parse_map(map, type) { + let result = ''; + for (const item of map.entries()) { const key = item[0], value = item[1]; @@ -434,43 +455,13 @@ export function serialize(withFunctionWrapper = /* tag? */ /* stringify */ /* st ids = value[i] || ['']; let str = ''; for (let j = 0; j < ids.length; j++) { - str += (str ? ',' : '') + ("string" == type ? '"' + ids[j] + '"' : ids[j]); + str += (str ? ',' : '') + ("string" === type ? '"' + ids[j] + '"' : ids[j]); } str = '[' + str + ']'; res += (res ? ',' : '') + str; } res = '["' + key + '",[' + res + ']]'; - map += (map ? ',' : '') + res; + result += (result ? ',' : '') + res; } - map = "index.map=new Map([" + map + "]);"; - - let ctx = ''; - for (const context of this.ctx.entries()) { - const key_ctx = context[0], - value_ctx = context[1]; - - - for (const item of value_ctx.entries()) { - const key = item[0], - value = item[1]; - - - let res = ''; - for (let i = 0, ids; i < value.length; i++) { - ids = value[i] || ['']; - let str = ''; - for (let j = 0; j < ids.length; j++) { - str += (str ? ',' : '') + ("string" == type ? '"' + ids[j] + '"' : ids[j]); - } - str = '[' + str + ']'; - res += (res ? ',' : '') + str; - } - res = 'new Map([["' + key + '",[' + res + ']]])'; - res = '["' + key_ctx + '",' + res + ']'; - ctx += (ctx ? ',' : '') + res; - } - } - ctx = "index.ctx=new Map([" + ctx + "]);"; - - return withFunctionWrapper ? "function inject(index){" + reg + map + ctx + "}" : reg + map + ctx; + return result; } \ No newline at end of file diff --git a/dist/module-debug/type.js b/dist/module-debug/type.js index 23342fd..0bc2652 100644 --- a/dist/module-debug/type.js +++ b/dist/module-debug/type.js @@ -186,12 +186,17 @@ export let DocumentSearchResults = []; export let EnrichedDocumentSearchResults = []; /** - * @typedef Array<{ + * @typedef {{ * id: (number|string), * doc: (Object|null), * field: (Array|undefined), * tag: (Array|undefined) - * }> + * }} + */ +export let MergedDocumentSearchEntry = {}; + +/** + * @typedef Array */ export let MergedDocumentSearchResults = []; @@ -218,7 +223,7 @@ export let EncoderSplitOptions = {}; * normalize: (boolean|(function(string):string)|undefined), * prepare: ((function(string):string)|undefined), * finalize: ((function(Array):(Array|void))|undefined), - * filter: (Set|undefined), + * filter: (Set|function(string):boolean|undefined), * matcher: (Map|undefined), * mapper: (Map|undefined), * stemmer: (Map|undefined), diff --git a/dist/module-min/bundle.js b/dist/module-min/bundle.js index 4b57439..a3ef4f7 100644 --- a/dist/module-min/bundle.js +++ b/dist/module-min/bundle.js @@ -1 +1 @@ -import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,FieldOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions,ResolverOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Index.prototype.encoder,Encoder.prototype.assign,Encoder.prototype.encode,Encoder.prototype.addMatcher,Encoder.prototype.addStemmer,Encoder.prototype.addFilter,Encoder.prototype.addMapper,Encoder.prototype.addReplacer,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Document.prototype.field,Document.prototype.index,Document.prototype.reg,Document.prototype.tag,Document.prototype.store,Document.prototype.fastupdate,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,Resolver.prototype.result,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.fastupdate,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,Charset.ArabicDefault,Charset.CjkDefault,Charset.CyrillicDefault,IndexOptions.preset,IndexOptions.context,IndexOptions.encoder,IndexOptions.encode,IndexOptions.resolution,IndexOptions.tokenize,IndexOptions.fastupdate,IndexOptions.score,IndexOptions.keystore,IndexOptions.rtl,IndexOptions.cache,IndexOptions.resolve,IndexOptions.db,IndexOptions.worker,IndexOptions.config,IndexOptions.priority,IndexOptions.export,IndexOptions.import,FieldOptions.preset,FieldOptions.context,FieldOptions.encoder,FieldOptions.encode,FieldOptions.resolution,FieldOptions.tokenize,FieldOptions.fastupdate,FieldOptions.score,FieldOptions.keystore,FieldOptions.rtl,FieldOptions.cache,FieldOptions.db,FieldOptions.config,FieldOptions.resolve,FieldOptions.field,FieldOptions.filter,FieldOptions.custom,FieldOptions.worker,DocumentOptions.context,DocumentOptions.encoder,DocumentOptions.encode,DocumentOptions.resolution,DocumentOptions.tokenize,DocumentOptions.fastupdate,DocumentOptions.score,DocumentOptions.keystore,DocumentOptions.rtl,DocumentOptions.cache,DocumentOptions.db,DocumentOptions.doc,DocumentOptions.document,DocumentOptions.worker,DocumentOptions.priority,DocumentOptions.export,DocumentOptions.import,ContextOptions.depth,ContextOptions.bidirectional,ContextOptions.resolution,DocumentDescriptor.field,DocumentDescriptor.index,DocumentDescriptor.tag,DocumentDescriptor.store,DocumentDescriptor.id,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,SearchOptions.resolution,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,DocumentSearchOptions.highlight,EncoderOptions.rtl,EncoderOptions.dedupe,EncoderOptions.split,EncoderOptions.include,EncoderOptions.exclude,EncoderOptions.prepare,EncoderOptions.finalize,EncoderOptions.filter,EncoderOptions.matcher,EncoderOptions.mapper,EncoderOptions.stemmer,EncoderOptions.replacer,EncoderOptions.minlength,EncoderOptions.maxlength,EncoderOptions.cache,EncoderSplitOptions.letter,EncoderSplitOptions.number,EncoderSplitOptions.symbol,EncoderSplitOptions.punctuation,EncoderSplitOptions.control,EncoderSplitOptions.char,PersistentOptions.name,PersistentOptions.field,PersistentOptions.type,PersistentOptions.db,ResolverOptions.index,ResolverOptions.query,ResolverOptions.limit,ResolverOptions.offset,ResolverOptions.enrich,ResolverOptions.resolve,ResolverOptions.suggest,ResolverOptions.and,ResolverOptions.or,ResolverOptions.xor,ResolverOptions.not;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{const a=self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch}export default FlexSearch;export{Index,Document,Encoder,Charset,WorkerIndex as Worker,Resolver,IdxDB as IndexedDB}; \ No newline at end of file +import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,FieldOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions,ResolverOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";import{KeystoreMap,KeystoreArray,KeystoreSet}from"./keystore.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Index.prototype.encoder,Encoder.prototype.assign,Encoder.prototype.encode,Encoder.prototype.addMatcher,Encoder.prototype.addStemmer,Encoder.prototype.addFilter,Encoder.prototype.addMapper,Encoder.prototype.addReplacer,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Document.prototype.field,Document.prototype.index,Document.prototype.reg,Document.prototype.tag,Document.prototype.store,Document.prototype.fastupdate,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,Resolver.prototype.result,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.fastupdate,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,KeystoreArray.length,KeystoreMap.size,KeystoreSet.size,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,Charset.ArabicDefault,Charset.CjkDefault,Charset.CyrillicDefault,IndexOptions.preset,IndexOptions.context,IndexOptions.encoder,IndexOptions.encode,IndexOptions.resolution,IndexOptions.tokenize,IndexOptions.fastupdate,IndexOptions.score,IndexOptions.keystore,IndexOptions.rtl,IndexOptions.cache,IndexOptions.resolve,IndexOptions.db,IndexOptions.worker,IndexOptions.config,IndexOptions.priority,IndexOptions.export,IndexOptions.import,FieldOptions.preset,FieldOptions.context,FieldOptions.encoder,FieldOptions.encode,FieldOptions.resolution,FieldOptions.tokenize,FieldOptions.fastupdate,FieldOptions.score,FieldOptions.keystore,FieldOptions.rtl,FieldOptions.cache,FieldOptions.db,FieldOptions.config,FieldOptions.resolve,FieldOptions.field,FieldOptions.filter,FieldOptions.custom,FieldOptions.worker,DocumentOptions.context,DocumentOptions.encoder,DocumentOptions.encode,DocumentOptions.resolution,DocumentOptions.tokenize,DocumentOptions.fastupdate,DocumentOptions.score,DocumentOptions.keystore,DocumentOptions.rtl,DocumentOptions.cache,DocumentOptions.db,DocumentOptions.doc,DocumentOptions.document,DocumentOptions.worker,DocumentOptions.priority,DocumentOptions.export,DocumentOptions.import,ContextOptions.depth,ContextOptions.bidirectional,ContextOptions.resolution,DocumentDescriptor.field,DocumentDescriptor.index,DocumentDescriptor.tag,DocumentDescriptor.store,DocumentDescriptor.id,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,SearchOptions.resolution,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,DocumentSearchOptions.highlight,EncoderOptions.rtl,EncoderOptions.dedupe,EncoderOptions.split,EncoderOptions.include,EncoderOptions.exclude,EncoderOptions.prepare,EncoderOptions.finalize,EncoderOptions.filter,EncoderOptions.matcher,EncoderOptions.mapper,EncoderOptions.stemmer,EncoderOptions.replacer,EncoderOptions.minlength,EncoderOptions.maxlength,EncoderOptions.cache,EncoderSplitOptions.letter,EncoderSplitOptions.number,EncoderSplitOptions.symbol,EncoderSplitOptions.punctuation,EncoderSplitOptions.control,EncoderSplitOptions.char,PersistentOptions.name,PersistentOptions.field,PersistentOptions.type,PersistentOptions.db,ResolverOptions.index,ResolverOptions.query,ResolverOptions.limit,ResolverOptions.offset,ResolverOptions.enrich,ResolverOptions.resolve,ResolverOptions.suggest,ResolverOptions.and,ResolverOptions.or,ResolverOptions.xor,ResolverOptions.not;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{const a=self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch}export default FlexSearch;export{Index,Document,Encoder,Charset,WorkerIndex as Worker,Resolver,IdxDB as IndexedDB}; \ No newline at end of file diff --git a/dist/module-min/common.js b/dist/module-min/common.js index fbdc6fe..de04bf5 100644 --- a/dist/module-min/common.js +++ b/dist/module-min/common.js @@ -1 +1 @@ -export function merge_option(a,b,c){const d=typeof c,e=typeof a;if("undefined"!=d){if("undefined"!=e){if(c){if("function"==e&&d==e)return function(b){return a(c(b))};const b=a.constructor,f=c.constructor;if(b===f){if(b===Array)return c.concat(a);if(b===Map){const b=new Map(c);for(const c of a){const a=c[0],d=c[1];b.set(a,d)}return b}if(b===Set){const b=new Set(c);for(const c of a.values())b.add(c);return b}}}return a}return c}return"undefined"==e?b:a}export function create_object_array(a){const b=Array(a);for(let c=0;cb?a.slice(d,d+b):d?a.slice(d):a;d+=e.length;let f={},g="";for(let a=0;am;k+=(k?" OR ":"")+`(ctx = {ctx${c}:String} AND key = {key${c}:String})`,l["ctx"+c]=d?j:m,l["key"+c]=d?m:j,m=j}if(h){k="("+k+")";for(let a=0,b=1;am;k+=(k?" OR ":"")+`(ctx = {ctx${c}:String} AND key = {key${c}:String})`,l["ctx"+c]=d?j:m,l["key"+c]=d?m:j,m=j}if(h){k="("+k+")";for(let a=0,b=1;a{b.objectStoreNames.contains(a)||b.createObjectStore(a)})},d.onblocked=function(a){console.error("blocked",a),c()},d.onerror=function(a){console.error(this.error,a),c()},d.onsuccess=function(){a.db=this.result,a.db.onversionchange=function(){a.close()},b(a)}})},IdxDB.prototype.close=function(){this.db.close(),this.db=null},IdxDB.prototype.destroy=function(){const a=IndexedDB.deleteDatabase(this.id+(this.field?":"+this.field:""));return promisfy(a)},IdxDB.prototype.clear=function(){const a=this.db.transaction(fields,"readwrite");for(let b=0;b=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b{e.onerror=a=>{e.abort(),e=d=null,g(a)},e.oncomplete=a=>{e=d=null,f(a||!0)};const h=c.call(this,d);return this.trx[a+":"+b]=null,h})},IdxDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;ca)||f||"string"!=typeof c||isNaN(c)||(a=h.indexOf(parseInt(c,10)),a&&(f=1)),0<=a)if(e=1,1{a.onsuccess=function(){b&&b(this.result),c(this.result)},a.oncomplete=function(){b&&b(this.result),c(this.result)},a.onerror=d,a=null})} \ No newline at end of file +import{PersistentOptions,SearchResults,EnrichedSearchResults}from"../../type.js";const VERSION=1,IndexedDB="undefined"!=typeof window&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),IDBTransaction="undefined"!=typeof window&&(window.IDBTransaction||window.webkitIDBTransaction||window.msIDBTransaction),IDBKeyRange="undefined"!=typeof window&&(window.IDBKeyRange||window.webkitIDBKeyRange||window.msIDBKeyRange),fields=["map","ctx","tag","reg","cfg"];import StorageInterface from"../interface.js";import{toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}export default function IdxDB(a,b={}){return this?void("object"==typeof a&&(b=a,a=a.name),!a&&console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(a?":"+sanitize(a):""),this.field=b.field?sanitize(b.field):"",this.type=b.type,this.support_tag_search=!1,this.fastupdate=!1,this.db=null,this.trx={}):new IdxDB(a,b)}IdxDB.prototype.mount=function(a){return a.encoder?(a.db=this,this.open()):a.mount(this)},IdxDB.prototype.open=function(){let a=this;return navigator.storage&&navigator.storage.persist(),this.db||new Promise(function(b,c){const d=IndexedDB.open(a.id+(a.field?":"+a.field:""),VERSION);d.onupgradeneeded=function(){const b=a.db=this.result;fields.forEach(a=>{b.objectStoreNames.contains(a)||b.createObjectStore(a)})},d.onblocked=function(a){console.error("blocked",a),c()},d.onerror=function(a){console.error(this.error,a),c()},d.onsuccess=function(){a.db=this.result,a.db.onversionchange=function(){a.close()},b(a)}})},IdxDB.prototype.close=function(){this.db&&this.db.close(),this.db=null},IdxDB.prototype.destroy=function(){const a=IndexedDB.deleteDatabase(this.id+(this.field?":"+this.field:""));return promisfy(a)},IdxDB.prototype.clear=function(){const a=this.db.transaction(fields,"readwrite");for(let b=0;b=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b{e.onerror=a=>{e.abort(),e=d=null,g(a)},e.oncomplete=a=>{e=d=null,f(a||!0)};const h=c.call(this,d);return this.trx[a+":"+b]=null,h})},IdxDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;ca)||f||"string"!=typeof c||isNaN(c)||(a=h.indexOf(parseInt(c,10)),a&&(f=1)),0<=a)if(e=1,1{a.onsuccess=function(){b&&b(this.result),c(this.result)},a.oncomplete=function(){b&&b(this.result),c(this.result)},a.onerror=d,a=null})} \ No newline at end of file diff --git a/dist/module-min/db/mongodb/index.js b/dist/module-min/db/mongodb/index.js index 9691b31..8dad3f9 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,DB=Object.create(null);export default function MongoDB(a,b={}){return this?void("object"==typeof a&&(b=a,a=a.name),!a&&console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(a?"-"+sanitize(a):""),this.field=b.field?"-"+sanitize(b.field):"",this.type=b.type||"",this.db=b.db||DB[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.encoder?(a.db=this,this.open()):a.mount(this)};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=DB[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=DB[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}let m=f?{_id:1}:{_id:1,res:1};const n=[{$match:{$or:k}},{$group:{_id:"$id",res:e?{$sum:1}:{$min:1},count:{$sum:1}}}];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;bMAXIMUM_QUERY_VARS?a.slice(c,c+MAXIMUM_QUERY_VARS):c?a.slice(c):a;c+=d.length;let e="";for(let a=1;a<=d.length;a++)e+=(e?",":"")+"$"+a;const f=await this.db.any(` SELECT id, doc FROM ${this.id}.reg - WHERE id IN (${e})`,a);if(f&&f.length){for(let a,b=0;bm;k+=(k?" OR ":"")+`(ctx = $${n++} AND key = $${n++})`,l.push(d?j:m,d?m:j),m=j}if(h){k="("+k+")";for(let a=0;am;k+=(k?" OR ":"")+`(ctx = $${n++} AND key = $${n++})`,l.push(d?j:m,d?m:j),m=j}if(h){k="("+k+")";for(let a=0;aconsole.error(a)).connect()},RedisDB.prototype.close=async function(){return await this.db.disconnect(),this.db=null,this},RedisDB.prototype.destroy=function(){return this.clear()},RedisDB.prototype.clear=function(){return this.db.unlink([this.id+"map"+this.field,this.id+"ctx"+this.field,this.id+"tag"+this.field,this.id+"cfg"+this.field,this.id+"doc",this.id+"reg"])};function create_result(a,b,c,d){if(c){for(let c,d,e=0;e=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",a).then(function(b){for(let c=0;cf,e.push(c+(g?d:f)+":"+(g?f:d)),f=d;b=e}else{const a=this.id+"map"+this.field+":";for(let c=0;cconsole.error(a)).connect()},RedisDB.prototype.close=async function(){return DB,this.db=null,this},RedisDB.prototype.destroy=function(){return this.clear()},RedisDB.prototype.clear=function(){return this.db.unlink([this.id+"map"+this.field,this.id+"ctx"+this.field,this.id+"tag"+this.field,this.id+"cfg"+this.field,this.id+"doc",this.id+"reg"])};function create_result(a,b,c,d){if(c){for(let c,d,e=0;e=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",a).then(function(b){for(let c=0;ce,j.push(c+(f?d:e)+":"+(f?e:d)),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;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)&&(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=function(a,b){if(TRX[this.id])return 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,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;cMAXIMUM_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 diff --git a/dist/module-min/document.js b/dist/module-min/document.js index ddaf761..2087919 100644 --- a/dist/module-min/document.js +++ b/dist/module-min/document.js @@ -1 +1 @@ -import{IndexOptions,DocumentOptions,DocumentDescriptor,FieldOptions,StoreOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Cache,{searchCache}from"./cache.js";import{is_string,is_object,parse_simple}from"./common.js";import apply_async from"./async.js";import{exportDocument,importDocument}from"./serialize.js";import{KeystoreMap,KeystoreSet}from"./keystore.js";import"./document/add.js";import"./document/search.js";export default function Document(a){if(!this||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),this.cache=(c=a.cache||null)&&new Cache(c),a.cache=!1,this.worker=a.worker,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;d"a1a".split(d).length;this.numeric=merge_option(a.numeric,b)}else{try{this.split=merge_option(this.split,whitespace)}catch(a){!1,this.split=/\s+/}this.numeric=merge_option(a.numeric,merge_option(this.numeric,!0))}if(this.prepare=merge_option(a.prepare,null,this.prepare),this.finalize=merge_option(a.finalize,null,this.finalize),!normalize&&(this.mapper=new Map(normalize_polyfill)),this.rtl=merge_option(a.rtl,!1,this.rtl),this.dedupe=merge_option(a.dedupe,!1,this.dedupe),this.filter=merge_option((d=a.filter)&&new Set(d),null,this.filter),this.matcher=merge_option((d=a.matcher)&&new Map(d),null,this.matcher),this.mapper=merge_option((d=a.mapper)&&new Map(d),null,this.mapper),this.stemmer=merge_option((d=a.stemmer)&&new Map(d),null,this.stemmer),this.replacer=merge_option(a.replacer,null,this.replacer),this.minlength=merge_option(a.minlength,1,this.minlength),this.maxlength=merge_option(a.maxlength,0,this.maxlength),this.cache=d=merge_option(a.cache,!0,this.cache),d&&(this.timer=null,this.cache_size="number"==typeof d?d:2e5,this.cache_enc=new Map,this.cache_term=new Map,this.cache_enc_length=128,this.cache_term_length=128),this.matcher_str="",this.matcher_test=null,this.stemmer_str="",this.stemmer_test=null,this.matcher)for(const a of this.matcher.keys())this.matcher_str+=(this.matcher_str?"|":"")+a;if(this.stemmer)for(const a of this.stemmer.keys())this.stemmer_str+=(this.stemmer_str?"|":"")+a;return this},Encoder.prototype.addStemmer=function(a,b){return this.stemmer||(this.stemmer=new Map),this.stemmer.set(a,b),this.stemmer_str+=(this.stemmer_str?"|":"")+a,this.stemmer_test=null,this.cache&&clear(this),this},Encoder.prototype.addFilter=function(a){return this.filter||(this.filter=new Set),this.filter.add(a),this.cache&&clear(this),this},Encoder.prototype.addMapper=function(a,b){return"object"==typeof a?this.addReplacer(a,b):1a.length&&(this.dedupe||this.mapper)?this.addMapper(a,b):(this.matcher||(this.matcher=new Map),this.matcher.set(a,b),this.matcher_str+=(this.matcher_str?"|":"")+a,this.matcher_test=null,this.cache&&clear(this),this)},Encoder.prototype.addReplacer=function(a,b){return"string"==typeof a?this.addMatcher(a,b):(this.replacer||(this.replacer=[]),this.replacer.push(a,b),this.cache&&clear(this),this)},Encoder.prototype.encode=function(a){if(this.cache&&a.length<=this.cache_enc_length)if(!this.timer)this.timer=setTimeout(clear,50,this);else if(this.cache_enc.has(a))return this.cache_enc.get(a);this.normalize&&("function"==typeof this.normalize?a=this.normalize(a):normalize?a=a.normalize("NFKD").replace(normalize,"").toLowerCase():a=a.toLowerCase()),this.prepare&&(a=this.prepare(a)),this.numeric&&3this.stemmer.get(a)),(e.lengththis.matcher.get(a))),e&&this.replacer)for(let a=0;e&&athis.cache_size&&(this.cache_term.clear(),this.cache_term_length=0|this.cache_term_length/1.1)),e&&c.push(e)}}return this.finalize&&(c=this.finalize(c)||c),this.cache&&a.length<=this.cache_enc_length&&(this.cache_enc.set(a,c),this.cache_enc.size>this.cache_size&&(this.cache_enc.clear(),this.cache_enc_length=0|this.cache_enc_length/1.1)),c};function clear(a){a.timer=null,a.cache_enc.clear(),a.cache_term.clear()} \ No newline at end of file +import{merge_option}from"./common.js";import normalize_polyfill from"./charset/normalize.js";import{EncoderOptions}from"./type.js";const whitespace=/[^\p{L}\p{N}]+/u,numeric_split_length=/(\d{3})/g,numeric_split_prev_char=/(\D)(\d{3})/g,numeric_split_next_char=/(\d{3})(\D)/g,normalize=/[\u0300-\u036f]/g;export default function Encoder(a={}){if(!this||this.constructor!==Encoder)return new Encoder(...arguments);if(arguments.length)for(let a=0;a"a1a".split(d).length;this.numeric=merge_option(a.numeric,b)}else{try{this.split=merge_option(this.split,whitespace)}catch(a){!1,this.split=/\s+/}this.numeric=merge_option(a.numeric,merge_option(this.numeric,!0))}if(this.prepare=merge_option(a.prepare,null,this.prepare),this.finalize=merge_option(a.finalize,null,this.finalize),!normalize&&(this.mapper=new Map(normalize_polyfill)),d=a.filter,this.filter="function"==typeof d?d:merge_option(d&&new Set(d),null,this.filter),this.dedupe=merge_option(a.dedupe,!1,this.dedupe),this.matcher=merge_option((d=a.matcher)&&new Map(d),null,this.matcher),this.mapper=merge_option((d=a.mapper)&&new Map(d),null,this.mapper),this.stemmer=merge_option((d=a.stemmer)&&new Map(d),null,this.stemmer),this.replacer=merge_option(a.replacer,null,this.replacer),this.minlength=merge_option(a.minlength,1,this.minlength),this.maxlength=merge_option(a.maxlength,0,this.maxlength),this.rtl=merge_option(a.rtl,!1,this.rtl),this.cache=d=merge_option(a.cache,!0,this.cache),d&&(this.timer=null,this.cache_size="number"==typeof d?d:2e5,this.cache_enc=new Map,this.cache_term=new Map,this.cache_enc_length=128,this.cache_term_length=128),this.matcher_str="",this.matcher_test=null,this.stemmer_str="",this.stemmer_test=null,this.matcher)for(const a of this.matcher.keys())this.matcher_str+=(this.matcher_str?"|":"")+a;if(this.stemmer)for(const a of this.stemmer.keys())this.stemmer_str+=(this.stemmer_str?"|":"")+a;return this},Encoder.prototype.addStemmer=function(a,b){return this.stemmer||(this.stemmer=new Map),this.stemmer.set(a,b),this.stemmer_str+=(this.stemmer_str?"|":"")+a,this.stemmer_test=null,this.cache&&clear(this),this},Encoder.prototype.addFilter=function(a){return"function"==typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a)),this.cache&&clear(this),this},Encoder.prototype.addMapper=function(a,b){return"object"==typeof a?this.addReplacer(a,b):1a.length&&(this.dedupe||this.mapper)?this.addMapper(a,b):(this.matcher||(this.matcher=new Map),this.matcher.set(a,b),this.matcher_str+=(this.matcher_str?"|":"")+a,this.matcher_test=null,this.cache&&clear(this),this)},Encoder.prototype.addReplacer=function(a,b){return"string"==typeof a?this.addMatcher(a,b):(this.replacer||(this.replacer=[]),this.replacer.push(a,b),this.cache&&clear(this),this)},Encoder.prototype.encode=function(a){if(this.cache&&a.length<=this.cache_enc_length)if(!this.timer)this.timer=setTimeout(clear,50,this);else if(this.cache_enc.has(a))return this.cache_enc.get(a);this.normalize&&("function"==typeof this.normalize?a=this.normalize(a):normalize?a=a.normalize("NFKD").replace(normalize,"").toLowerCase():a=a.toLowerCase()),this.prepare&&(a=this.prepare(a)),this.numeric&&3this.stemmer.get(a)),a!==e&&this.filter&&e.length>=this.minlength&&("function"==typeof this.filter?!this.filter(e):this.filter.has(e))&&(e="")}if(e&&(this.mapper||this.dedupe&&1this.matcher.get(a))),e&&this.replacer)for(let a=0;e&&athis.cache_size&&(this.cache_term.clear(),this.cache_term_length=0|this.cache_term_length/1.1)),e&&c.push(e)}}return this.finalize&&(c=this.finalize(c)||c),this.cache&&a.length<=this.cache_enc_length&&(this.cache_enc.set(a,c),this.cache_enc.size>this.cache_size&&(this.cache_enc.clear(),this.cache_enc_length=0|this.cache_enc_length/1.1)),c};function clear(a){a.timer=null,a.cache_enc.clear(),a.cache_term.clear()} \ No newline at end of file diff --git a/dist/module-min/index.js b/dist/module-min/index.js index 01053ec..66f7bea 100644 --- a/dist/module-min/index.js +++ b/dist/module-min/index.js @@ -1 +1 @@ -import{IndexOptions,ContextOptions,EncoderOptions}from"./type.js";import Encoder from"./encoder.js";import Cache,{searchCache}from"./cache.js";import Charset from"./charset.js";import{KeystoreMap,KeystoreSet}from"./keystore.js";import{is_array,is_string}from"./common.js";import{exportIndex,importIndex,serialize}from"./serialize.js";import default_encoder from"./charset/latin/default.js";import apply_preset from"./preset.js";import apply_async from"./async.js";import tick from"./profiler.js";import"./index/add.js";import"./index/search.js";import"./index/remove.js";export default function Index(a,b){if(!this||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||default_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=a.tokenize)&&"default"!==c&&c||"strict",this.depth="strict"===c&&d.depth||0,this.bidirectional=!1!==d.bidirectional,this.fastupdate=!!a.fastupdate,this.score=a.score||null,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(a,b){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.commit(this,a,b)},Index.prototype.destroy=function(){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.destroy()};export function autoCommit(a,b,c){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null,a.db.commit(a,b,c)},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=[{clear:!0}]),this},Index.prototype.append=function(a,b){return this.add(a,b,!0)},Index.prototype.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)},Index.prototype.update=function(a,b){const c=this,d=this.remove(a);return d&&d.then?d.then(()=>c.add(a,b)):this.add(a,b)};function cleanup_index(a){let b=0;if(is_array(a))for(let c,d=0;dc.add(a,b)):this.add(a,b)};function cleanup_index(a){let b=0;if(is_array(a))for(let c,d=0;dc||d)&&(k=k.slice(d,c+d));else{const a=[];for(let b,e=0;ed){d-=b.length;continue}if((b.length>c||d)&&(b=b.slice(d,c+d),c-=b.length,d&&(d-=b.length)),a.push(b),!c)break}k=1c||d?k.slice(d,c+d):k;return k}export function union(a,b,c,d,e){const f=[],g=create_object();let h,l,m,n=a.length;if(!d)for(let d,j=n-1,i=0;0<=j;j--){d=a[j];for(let a=0;ac||d)&&(k=k.slice(d,c+d));else{const a=[];for(let b,e=0;ed){d-=b.length;continue}if((b.length>c||d)&&(b=b.slice(d,c+d),c-=b.length,d&&(d-=b.length)),a.push(b),!c)break}k=1c||d?k.slice(d,c+d):k;return k}export function union(a,b,c,d,e){const f=[],g=create_object();let h,l,m,n=a.length;if(!d)for(let d,j=n-1,i=0;0<=j;j--){d=a[j];for(let a=0;a=f.length)b-=f.length;else{const g=f[d?"splice":"slice"](b,c),h=g.length;if(h&&(e=e.length?e.concat(g):g,c-=h,d&&(a.length-=h),!c))break;b=0}return e}export function KeystoreArray(a){if(!this)return new KeystoreArray(a);this.index=a?[a]:[],this.length=a?a.length:0;const b=this;return new Proxy([],{get(a,c){if("length"===c)return b.length;if("push"===c)return function(a){b.index[b.index.length-1].push(a),b.length++};if("pop"===c)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===c)return function(a){let c=0;for(let d,e,f=0;f=f.length)b-=f.length;else{const g=f[d?"splice":"slice"](b,c),h=g.length;if(h&&(e=e.length?e.concat(g):g,c-=h,d&&(a.length-=h),!c))break;b=0}return e}export function KeystoreArray(a){if(!this||this.constructor!==KeystoreArray)return new KeystoreArray(a);this.index=a?[a]:[],this.length=a?a.length:0;const b=this;return new Proxy([],{get(a,c){if("length"===c)return b.length;if("push"===c)return function(a){b.index[b.index.length-1].push(a),b.length++};if("pop"===c)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===c)return function(a){let c=0;for(let d,e,f=0;f} +// */ -/** - * @param {!number} count - * @returns {Array} - */ +// export function create_object_array(count){ +// +// const array = new Array(count); +// +// for(let i = 0; i < count; i++){ +// array[i] = create_object(); +// } +// +// return array; +// } -export function create_object_array(count) { +// /** +// * @param {!number} count +// * @returns {Array} +// */ - const array = Array(count); +// export function create_map_array(count){ +// +// const array = new Array(count); +// +// for(let i = 0; i < count; i++){ +// array[i] = new Map(); +// } +// +// return array; +// } - for (let i = 0; i < count; i++) { - array[i] = create_object(); - } +// export function create_arrays(count){ +// +// const array = new Array(count); +// +// for(let i = 0; i < count; i++){ +// array[i] = []; +// } +// +// return array; +// } +// +// /** +// * @param {!Object} obj +// * @returns {Array} +// */ - return array; -} - -/** - * @param {!number} count - * @returns {Array} - */ - -export function create_map_array(count) { - - const array = Array(count); - - for (let i = 0; i < count; i++) { - array[i] = new Map(); - } - - return array; -} - -export function create_arrays(count) { - - const array = Array(count); - - for (let i = 0; i < count; i++) { - array[i] = []; - } - - return array; -} - -/** - * @param {!Object} obj - * @returns {Array} - */ - -export function get_keys(obj) { - return Object.keys(obj); -} +// export function get_keys(obj){ +// return Object.keys(obj); +// } export function create_object() { return Object.create(null); diff --git a/dist/module/db/clickhouse/index.js b/dist/module/db/clickhouse/index.js index 70d479c..5d5bcfe 100644 --- a/dist/module/db/clickhouse/index.js +++ b/dist/module/db/clickhouse/index.js @@ -1,4 +1,3 @@ - import { ClickHouse } from "clickhouse"; import StorageInterface from "../interface.js"; import { concat, toArray } from "../../common.js"; @@ -174,8 +173,8 @@ ClickhouseDB.prototype.open = async function () { }; ClickhouseDB.prototype.close = function () { - this.db.close(); - this.db = null; + //DB && DB.close(); + this.db = DB = null; return this; }; @@ -306,17 +305,16 @@ ClickhouseDB.prototype.enrich = async function (ids) { return 1 === result.length ? result[0] : 1 < result.length ? concat(result) : result; }; -ClickhouseDB.prototype.has = function (id) { - return this.db.query(` - SELECT EXISTS( - SELECT 1 - FROM ${this.id}.reg - WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}} - LIMIT 1 - )`, { params: { id } }).toPromise(); +ClickhouseDB.prototype.has = async function (id) { + const result = await this.db.query(` + SELECT 1 as exist + FROM ${this.id}.reg + WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}} + LIMIT 1`, { params: { id } }).toPromise(); + return !!(result && result[0] && result[0].exist); }; -ClickhouseDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !0, tags) { +ClickhouseDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) { let rows; if (1 < query.length && flexsearch.depth) { let where = "", @@ -349,7 +347,7 @@ ClickhouseDB.prototype.search = function (flexsearch, query, limit = 100, offset ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM ${this.id}.ctx${this.field} WHERE ${where} GROUP BY id @@ -414,7 +412,7 @@ ClickhouseDB.prototype.search = function (flexsearch, query, limit = 100, offset ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM ${this.id}.map${this.field} WHERE ${where} GROUP BY id diff --git a/dist/module/db/indexeddb/index.js b/dist/module/db/indexeddb/index.js index 8963b04..d7590d0 100644 --- a/dist/module/db/indexeddb/index.js +++ b/dist/module/db/indexeddb/index.js @@ -114,7 +114,7 @@ IdxDB.prototype.open = function () { }; IdxDB.prototype.close = function () { - this.db.close(); + this.db && this.db.close(); this.db = null; }; @@ -253,7 +253,9 @@ IdxDB.prototype.has = function (id) { map = transaction.objectStore("reg"), req = map.getKey(id); - return promisfy(req); + return promisfy(req).then(function (result) { + return !!result; + }); }; IdxDB.prototype.search = null; diff --git a/dist/module/db/mongodb/index.js b/dist/module/db/mongodb/index.js index 821b24a..76a3497 100644 --- a/dist/module/db/mongodb/index.js +++ b/dist/module/db/mongodb/index.js @@ -124,8 +124,9 @@ MongoDB.prototype.open = async function () { }; MongoDB.prototype.close = function () { - this.db.close(); - this.db = null; + //CLIENT && CLIENT.close(); + this.db = CLIENT = null; + DB[this.id] = null; return this; }; @@ -257,7 +258,9 @@ MongoDB.prototype.enrich = function (ids) { }; MongoDB.prototype.has = function (id) { - return this.db.collection("reg").countDocuments({ id }, { limit: 1 }); + return this.db.collection("reg").countDocuments({ id }, { limit: 1 }).then(function (result) { + return !!result; + }); }; MongoDB.prototype.search = async function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) { @@ -281,12 +284,14 @@ MongoDB.prototype.search = async function (flexsearch, query, limit = 100, offse keyword = term; } - let project = resolve ? { _id: 1 } : { _id: 1, res: 1 }; + const project = { _id: 1 }; + if (!resolve) project.res = 1; + if (enrich) project.doc = 1; const stmt = [{ $match: { $or: params } }, { $group: { _id: "$id", - res: suggest ? { $sum: 1 } : { $min: 1 }, - count: { $sum: 1 } + count: { $sum: 1 }, + res: suggest ? { $sum: "$res" } : { $sum /*$min*/: "$res" } } }]; suggest || stmt.push({ $match: { count: query.length - 1 } }); @@ -319,32 +324,34 @@ MongoDB.prototype.search = async function (flexsearch, query, limit = 100, offse count++; } - stmt.push({ $project: project }, { $match: match }); - } else { - stmt.push({ $project: project }); + stmt.push( + //{ $project: project }, + { $match: match }); } stmt.push({ $sort: suggest ? { count: -1, res: 1 } : { res: 1 } }, { $skip: offset }, { $limit: limit }); - if (tags) { - project = { _id: 1 }; - if (!resolve) project.res = 1; - if (enrich) project.doc = 1; + // if(tags){ + // project = { _id: 1 }; + // if(!resolve) project["res"] = 1; + // if(enrich) project["doc"] = 1; + // } - stmt.push({ $project: project }); - } + stmt.push({ $project: project }); rows = await this.db.collection("ctx" + this.field).aggregate(stmt); } else { - let project = resolve ? { _id: 1 } : { _id: 1, res: 1 }; + const project = { _id: 1 }; + if (!resolve) project.res = 1; + if (enrich) project.doc = 1; const stmt = [{ $match: { key: { $in: query } } }, { $group: { _id: "$id", - res: suggest ? { $sum: 1 } : { $min: 1 }, - count: { $sum: 1 } + count: { $sum: 1 }, + res: suggest ? { $sum: "$res" } : { $sum /*$min*/: "$res" } } }]; suggest || stmt.push({ $match: { count: query.length } }); @@ -377,20 +384,20 @@ MongoDB.prototype.search = async function (flexsearch, query, limit = 100, offse count++; } - stmt.push({ $project: project }, { $match: match }); - } else { - stmt.push({ $project: project }); + stmt.push( + //{ $project: project }, + { $match: match }); } stmt.push({ $sort: suggest ? { count: -1, res: 1 } : { res: 1 } }, { $skip: offset }, { $limit: limit }); - if (tags) { - project = { _id: 1 }; - if (!resolve) project.res = 1; - if (enrich) project.doc = 1; + // if(tags){ + // project = { _id: 1 }; + // if(!resolve) project["res"] = 1; + // if(enrich) project["doc"] = 1; + // } - stmt.push({ $project: project }); - } + stmt.push({ $project: project }); rows = await this.db.collection("map" + this.field).aggregate(stmt); } diff --git a/dist/module/db/postgres/index.js b/dist/module/db/postgres/index.js index 753f788..caf208a 100644 --- a/dist/module/db/postgres/index.js +++ b/dist/module/db/postgres/index.js @@ -1,5 +1,3 @@ - - import pg_promise from "pg-promise"; import StorageInterface from "../interface.js"; import { concat, toArray } from "../../common.js"; @@ -11,7 +9,7 @@ const defaults = { host: "localhost", port: "5432" }, - pgp = pg_promise({ noWarnings: !!1 }), + pgp = pg_promise(), VERSION = 1, MAXIMUM_QUERY_VARS = 16000, fields = ["map", "ctx", "reg", "tag", "cfg"], @@ -55,7 +53,7 @@ export default function PostgresDB(name, config = {}) { } if ("object" == typeof name) { config = name; - name = name.name; + name = config.name; } if (!name) { console.info("Default storage space was used, because a name was not passed."); @@ -63,7 +61,8 @@ export default function PostgresDB(name, config = {}) { this.id = (config.schema ? sanitize(config.schema) : defaults.schema) + (name ? "_" + sanitize(name) : ""); this.field = config.field ? "_" + sanitize(config.field) : ""; this.type = config.type ? types[config.type.toLowerCase()] : "text"; - this.support_tag_search = /* tag? */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; + this.support_tag_search = /* tag? */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ + /*await rows.hasNext()*/; if (!this.type) throw new Error("Unknown type of ID '" + config.type + "'"); this.db = DB || (DB = config.db || null); Object.assign(defaults, config); @@ -178,8 +177,8 @@ PostgresDB.prototype.open = async function () { }; PostgresDB.prototype.close = function () { - this.db.close && this.db.close(); - this.db = DB = null; + //DB && DB.close && DB.close(); + this.db = /*DB =*/null; return this; }; @@ -318,7 +317,9 @@ PostgresDB.prototype.enrich = async function (ids) { }; PostgresDB.prototype.has = function (id) { - return this.db.oneOrNone("SELECT EXISTS(SELECT 1 FROM " + this.id + ".reg WHERE id = $1)", [id]); + return this.db.oneOrNone("SELECT EXISTS(SELECT 1 FROM " + this.id + ".reg WHERE id = $1)", [id]).then(function (result) { + return !!(result && result.exists); + }); }; PostgresDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) { @@ -356,7 +357,7 @@ PostgresDB.prototype.search = function (flexsearch, query, limit = 100, offset = ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM ${this.id}.ctx${this.field} WHERE ${where} GROUP BY id @@ -406,8 +407,7 @@ PostgresDB.prototype.search = function (flexsearch, query, limit = 100, offset = for (let i = 0; i < query_length; i++) { where += (where ? "," : "") + "$" + count++; - } - where = "key " + (1 < query_length ? "IN (" + where + ")" : "= " + where); + }where = "key " + (1 < query_length ? "IN (" + where + ")" : "= " + where); if (tags) { where = "(" + where + ")"; @@ -423,7 +423,7 @@ PostgresDB.prototype.search = function (flexsearch, query, limit = 100, offset = ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM ${this.id}.map${this.field} WHERE ${where} GROUP BY id @@ -523,17 +523,23 @@ PostgresDB.prototype.info = function () { // }; PostgresDB.prototype.transaction = function (task) { - if (TRX) { - return task.call(this, TRX); - } const self = this; - return (TRX || this.db).tx(function (trx) { - return task.call(self, TRX = trx); - }).finally(function () { - TRX = null; + return this.db.tx(function (trx) { + return task.call(self, trx); }); }; +// PostgresDB.prototype.transaction = async function(task){ +// if(TRX){ +// return await task.call(this, TRX); +// } +// const self = this; +// return this.db.tx(async function(trx){ +// await task.call(self, TRX = trx); +// TRX = null; +// }); +// }; + PostgresDB.prototype.commit = async function (flexsearch, _replace, _append) { // process cleanup tasks diff --git a/dist/module/db/redis/index.js b/dist/module/db/redis/index.js index 51d12d6..cdcdeae 100644 --- a/dist/module/db/redis/index.js +++ b/dist/module/db/redis/index.js @@ -1,5 +1,3 @@ - - import { createClient } from "redis"; const defaults = { host: "localhost", @@ -74,7 +72,7 @@ RedisDB.prototype.open = async function () { }; RedisDB.prototype.close = async function () { - await this.db.disconnect(); // this.db.client.disconnect(); + // this.db.client.disconnect(); this.db = null; return this; }; @@ -167,14 +165,14 @@ RedisDB.prototype.has = function (id) { }; RedisDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) { + let result, + params = []; - let result; if (1 < query.length && flexsearch.depth) { const key = this.id + "ctx" + this.field + ":"; - let params = [], - keyword = query[0], + let keyword = query[0], term; @@ -184,29 +182,37 @@ RedisDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, params.push(key + (swap ? term : keyword) + ":" + (swap ? keyword : term)); keyword = term; } - query = params; } else { const key = this.id + "map" + this.field + ":"; for (let i = 0; i < query.length; i++) { - query[i] = key + query[i]; + params.push(key + query[i]); } } + query = params; + const type = this.type; let key = this.id + "tmp:" + Math.random(); if (suggest) { - if (tags) for (let i = 0; i < tags.length; i += 2) { - query.push(this.id + "tag-" + sanitize(tags[i]) + ":" + tags[i + 1]); - } - const multi = this.db.multi().zUnionStore(key, query, { AGGREGATE: "SUM" }); // Strict Tag Intersection: it does not put tags into union, instead it calculates the // intersection against the term match union. This was the default behavior // of Tag-Search. But putting everything into union will also provide suggestions derived // from tags when no term was matched. + if (tags) { + // copy over zInterStore into the same destination surprisingly works fine + // const key2 = key + ":2"; + query = [key]; + for (let i = 0; i < tags.length; i += 2) { + query.push(this.id + "tag-" + sanitize(tags[i]) + ":" + tags[i + 1]); + } + multi.zInterStore(key, query, { AGGREGATE: "SUM" }); + // .unlink(key) + // key = key2; + } result = multi[resolve ? "zRange" : "zRangeWithScores"](key, "" + offset, "" + (offset + limit - 1), { REV: !0 }).unlink(key).exec(); } else { diff --git a/dist/module/db/sqlite/index.js b/dist/module/db/sqlite/index.js index 36c0f9c..3b6f068 100644 --- a/dist/module/db/sqlite/index.js +++ b/dist/module/db/sqlite/index.js @@ -1,5 +1,3 @@ - - //const sqlite3 = require("sqlite3").verbose(); import sqlite3 from "sqlite3"; import path from "path"; @@ -197,7 +195,7 @@ SqliteDB.prototype.open = async function () { }; SqliteDB.prototype.close = function () { - this.db.close(); + this.db && this.db.close(); this.db = null; DB[this.id] = null; TRX[this.id] = null; @@ -392,7 +390,7 @@ SqliteDB.prototype.has = function (id) { stmt: `SELECT EXISTS(SELECT 1 FROM main.reg WHERE id = ?) as exist`, params: [id] }).then(function (result) { - return result && result.exist; + return !!(result && result.exist); }); }; @@ -431,7 +429,7 @@ SqliteDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0 ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM main.ctx${this.field} WHERE ${stmt} GROUP BY id @@ -500,7 +498,7 @@ SqliteDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0 ${enrich ? ", doc" : ""} FROM ( SELECT id, count(*) as count, - ${suggest ? "SUM" : "MIN"}(res) as res + ${suggest ? "SUM" : "SUM" /*"MIN"*/}(res) as res FROM main.map${this.field} WHERE ${stmt} GROUP BY id @@ -554,15 +552,13 @@ SqliteDB.prototype.info = function () { SqliteDB.prototype.transaction = function (task, callback) { - const self = this; - if (TRX[this.id]) { - return TRX[this.id].then(function () { - return self.transaction(task, callback); - }); + return task.call(this); } - const db = this.db; + const db = this.db, + self = this; + return TRX[this.id] = new Promise(function (resolve, reject) { db.exec("PRAGMA optimize"); @@ -780,8 +776,8 @@ SqliteDB.prototype.remove = function (ids) { this.db.run("DELETE FROM main.ctx" + self.field + " WHERE id IN (" + stmt + ")", ids); this.db.run("DELETE FROM main.tag" + self.field + " WHERE id IN (" + stmt + ")", ids); this.db.run("DELETE FROM main.reg WHERE id IN (" + stmt + ")", ids); - }).then(function (res) { - return next ? self.remove(next) : res; + }).then(function (result) { + return next ? self.remove(next) : result; }); }; diff --git a/dist/module/document.js b/dist/module/document.js index db0f12b..2778e32 100644 --- a/dist/module/document.js +++ b/dist/module/document.js @@ -43,9 +43,7 @@ export default function Document(options) { keystore && (this.keystore = keystore); this.fastupdate = !!options.fastupdate; // Shared Registry - this.reg = this.fastupdate && !options.worker && !options.db ? keystore && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ - - ? new KeystoreMap(keystore) : new Map() : keystore && !0 ? new KeystoreSet(keystore) : new Set(); + this.reg = this.fastupdate && !options.worker && !options.db ? keystore && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ ? new KeystoreMap(keystore) : new Map() : keystore && !0 ? new KeystoreSet(keystore) : new Set(); // todo support custom filter function this.storetree = (tmp = document.store || null) && tmp && !0 !== tmp && []; @@ -54,9 +52,7 @@ export default function Document(options) { this.cache = (tmp = options.cache || null) && new Cache(tmp); // do not apply cache again for the indexes since .searchCache() // is just a wrapper over .search() - options.cache = /* suggest */ /* append: */ /* enrich */ - - !1; + options.cache = /* suggest */ /* append: */ /* enrich */!1; this.worker = options.worker; @@ -204,7 +200,7 @@ Document.prototype.commit = async function (replace, append) { // parallel: const promises = []; for (const index of this.index.values()) { - promises.push(index.db.commit(index, replace, append)); + promises.push(index.commit(index, replace, append)); } await Promise.all(promises); this.reg.clear(); @@ -400,15 +396,15 @@ Document.prototype.remove = function (id) { Document.prototype.clear = function () { - //const promises = []; + const promises = []; for (const index of this.index.values()) { // db index will add clear task - index.clear(); - // const promise = index.clear(); - // if(promise instanceof Promise){ - // promises.push(promise); - // } + const promise = index.clear(); + // worker indexes will return promises + if (promise.then) { + promises.push(promise); + } } if (this.tag) { @@ -421,9 +417,11 @@ Document.prototype.clear = function () { this.store.clear(); } - return this; /*promises.length - ? Promise.all(promises) - :*/ + if (this.cache) { + this.cache.clear(); + } + + return promises.length ? Promise.all(promises) : this; }; /** @@ -431,6 +429,7 @@ Document.prototype.clear = function () { * @return {boolean|Promise} */ Document.prototype.contain = function (id) { + if (this.db) { return this.index.get(this.field[0]).db.has(id); } diff --git a/dist/module/document/search.js b/dist/module/document/search.js index 6918b33..4afaf52 100644 --- a/dist/module/document/search.js +++ b/dist/module/document/search.js @@ -1,5 +1,5 @@ -import { DocumentSearchOptions, DocumentSearchResults, EnrichedDocumentSearchResults, MergedDocumentSearchResults, EnrichedSearchResults, SearchResults, IntermediateSearchResults } from "../type.js"; +import { DocumentSearchOptions, DocumentSearchResults, EnrichedDocumentSearchResults, MergedDocumentSearchResults, MergedDocumentSearchEntry, EnrichedSearchResults, SearchResults, IntermediateSearchResults } from "../type.js"; import { create_object, is_array, is_object, is_string, parse_simple } from "../common.js"; import { intersect_union } from "../intersect.js"; import Document from "../document.js"; @@ -97,7 +97,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } enrich = this.store && options.enrich && resolve; - highlight = options.highlight && enrich; + highlight = enrich && options.highlight; limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); @@ -418,7 +418,7 @@ function highlight_fields(result, query, index, field, tree, template) { // if(typeof template === "string"){ // template = new RegExp(template, "g"); // } - + console.log("template", template); let encoder, query_enc, tokenize; @@ -498,7 +498,7 @@ function highlight_fields(result, query, index, field, tree, template) { * @return {MergedDocumentSearchResults} */ function merge_fields(fields, limit) { - /** @type {MergedDocumentSearchResults} */ + /** @type {Array} */ const final = [], set = create_object(); @@ -527,7 +527,7 @@ function merge_fields(fields, limit) { return final; } entry.field = set[id] = [field.field]; - final.push(entry); + final.push( /** @type {MergedDocumentSearchEntry} */entry); } else { tmp.push(field.field); } diff --git a/dist/module/encoder.js b/dist/module/encoder.js index a2fe6a3..62c0b1e 100644 --- a/dist/module/encoder.js +++ b/dist/module/encoder.js @@ -91,9 +91,7 @@ Encoder.prototype.assign = function (options) { * pre-processing string input * @type {Function|boolean} */ - this.normalize = /** @type {Function|boolean} */merge_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ - - /*await rows.hasNext()*/, this.normalize); + this.normalize = /** @type {Function|boolean} */merge_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, this.normalize); // { // letter: true, @@ -183,20 +181,16 @@ Encoder.prototype.assign = function (options) { /** @type {Array>} */normalize_polyfill); } - // options - - this.rtl = merge_option(options.rtl, !1, this.rtl); + tmp = options.filter; + this.filter = "function" == typeof tmp ? tmp : merge_option(tmp && new Set(tmp), null, this.filter); this.dedupe = merge_option(options.dedupe, !1, this.dedupe); - this.filter = merge_option((tmp = options.filter) && new Set(tmp), null, this.filter); this.matcher = merge_option((tmp = options.matcher) && new Map(tmp), null, this.matcher); this.mapper = merge_option((tmp = options.mapper) && new Map(tmp), null, this.mapper); this.stemmer = merge_option((tmp = options.stemmer) && new Map(tmp), null, this.stemmer); this.replacer = merge_option(options.replacer, null, this.replacer); this.minlength = merge_option(options.minlength, 1, this.minlength); this.maxlength = merge_option(options.maxlength, 0, this.maxlength); - - // minimum required tokenizer by this encoder - //this.tokenize = options["tokenize"] || ""; + this.rtl = merge_option(options.rtl, !1, this.rtl); // auto-balanced cache this.cache = tmp = merge_option(options.cache, !0, this.cache); @@ -258,8 +252,13 @@ Encoder.prototype.addStemmer = function (match, replace) { }; Encoder.prototype.addFilter = function (term) { - this.filter || (this.filter = new Set()); - this.filter.add(term); + if ("function" == typeof term) { + // does not support merge yet + this.filter = term; //merge_option(term, term, this.filter); + } else { + this.filter || (this.filter = new Set()); + this.filter.add(term); + } this.cache && clear(this); return this; }; @@ -399,7 +398,7 @@ Encoder.prototype.encode = function (str) { } // pre-filter before cache - if (this.filter && this.filter.has(word)) { + if (this.filter && ("function" == typeof this.filter ? !this.filter(word) : this.filter.has(word))) { continue; } @@ -414,16 +413,17 @@ Encoder.prototype.encode = function (str) { this.timer = setTimeout(clear, 50, this); } } + + // todo compare advantages when filter/stemmer are also encoded + // apply stemmer before bigger transformations if (this.stemmer && 2 < word.length) { // for(const item of this.stemmer){ // const key = item[0]; // const value = item[1]; - // // if(word.length > key.length && word.endsWith(key)){ // word = word.substring(0, word.length - key.length) + value; // break; // } - // // // const position = word.length - key.length; // // if(position > 0 && word.substring(position) === key){ // // word = word.substring(0, position) + value; @@ -431,11 +431,15 @@ Encoder.prototype.encode = function (str) { // // } // } this.stemmer_test || (this.stemmer_test = new RegExp("(?!^)(" + this.stemmer_str + ")$")); + + const old = word; word = word.replace(this.stemmer_test, match => this.stemmer.get(match)); - // 4. post-filter after matcher and stemmer was applied - if (word.length < this.minlength || this.filter && this.filter.has(word)) { - word = ""; + // 4. post-filter after stemmer was applied + if (old !== word && this.filter && word.length >= this.minlength) { + if ("function" == typeof this.filter ? !this.filter(word) : this.filter.has(word)) { + word = ""; + } } } diff --git a/dist/module/index.js b/dist/module/index.js index caa4743..4aa1ce7 100644 --- a/dist/module/index.js +++ b/dist/module/index.js @@ -35,9 +35,10 @@ export default function Index(options, _register) { options = /** @type IndexOptions */options ? apply_preset(options) : {}; + /** @type {*} */ let tmp = options.context; /** @type ContextOptions */ - const context = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ === tmp ? { depth: 1 } : tmp || {}, + const context = /** @type ContextOptions */ /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ === tmp ? { depth: 1 } : tmp || {}, encoder = is_string(options.encoder) ? Charset[options.encoder] : options.encode || options.encoder || default_encoder; /** @type Encoder */ @@ -47,7 +48,7 @@ export default function Index(options, _register) { this.resolution = options.resolution || 9; - this.tokenize = (tmp = options.tokenize) && "default" !== tmp && tmp || "strict"; + this.tokenize = tmp = (tmp = options.tokenize) && "default" !== tmp && tmp || "strict"; this.depth = "strict" === tmp && context.depth || 0; this.bidirectional = !1 !== context.bidirectional; this.fastupdate = !!options.fastupdate; @@ -167,7 +168,7 @@ function cleanup_index(map) { for (let i = 0, arr; i < map.length; i++) { (arr = map[i]) && (count += arr.length); } - } else for (const item of map) { + } else for (const item of map.entries()) { const key = item[0], value = item[1], tmp = cleanup_index(value); diff --git a/dist/module/index/search.js b/dist/module/index/search.js index 2fcd863..75d25a3 100644 --- a/dist/module/index/search.js +++ b/dist/module/index/search.js @@ -57,7 +57,8 @@ Index.prototype.search = function (query, limit, options) { offset = options.offset || 0; context = options.context; suggest = options.suggest; - resolve = /*global_resolve &&*/ /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; + resolve = /*global_resolve &&*/ /* suggest */ + /* append: */ /* enrich */!1 !== options.resolve; //resolve || (global_resolve = 0); enrich = resolve && options.enrich; boost = options.boost; diff --git a/dist/module/intersect.js b/dist/module/intersect.js index c5110f9..cf7105b 100644 --- a/dist/module/intersect.js +++ b/dist/module/intersect.js @@ -77,6 +77,19 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res } tmp.push(id); + + // fast path early result when limit was set + if (resolve) { + if (limit && count === length - 1) { + // if(tmp.length - offset > limit){ + // return tmp.slice(offset, limit + offset); + // } + if (tmp.length - offset === limit) { + return tmp; + } + } + } + // todo break early on suggest: true } } } @@ -104,6 +117,8 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res result = result.slice(offset, limit + offset); } } else { + // todo this is doing the same as Resolver.resolve({limit}) ? + // todo check limit + offset when resolve = false const final = []; for (let i = 0, arr; i < result.length; i++) { arr = result[i]; diff --git a/dist/module/keystore.js b/dist/module/keystore.js index ea7ac78..10a837e 100644 --- a/dist/module/keystore.js +++ b/dist/module/keystore.js @@ -1,63 +1,57 @@ import { create_object } from "./common.js"; -/** - * @param bitlength - * @constructor - */ - -export function KeystoreObj(bitlength = 8) { - - if (!this) { - return new KeystoreObj(bitlength); - } - - this.index = create_object(); - this.keys = []; - - if (32 < bitlength) { - this.crc = lcg64; - this.bit = BigInt(bitlength); - } else { - this.crc = lcg; - this.bit = bitlength; - } - - return (/*this.proxy =*/new Proxy(this, { - get(target, key) { - const address = target.crc(key), - obj = target.index[address]; - - return obj && obj[key]; - }, - set(target, key, value) { - const address = target.crc(key); - let obj = target.index[address]; - if (!obj) { - target.index[address] = obj = create_object(); - target.keys.push(address); - } - obj[key] = value; - return (/* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ - // splice: - !0 /*await rows.hasNext()*/ - /*await rows.hasNext()*/ /*await rows.hasNext()*/ - ); - }, - delete(target, key) { - const address = target.crc(key), - obj = target.index[address]; - - obj && delete obj[key]; - return !0; - } - }) - ); -} - -KeystoreObj.prototype.clear = function () { - this.index = create_object(); - this.keys = []; -}; +// /** +// * @param bitlength +// * @constructor +// */ +// +// export function KeystoreObj(bitlength = 8){ +// +// if(!this || this.constructor !== KeystoreObj){ +// return new KeystoreObj(bitlength); +// } +// +// this.index = create_object(); +// this.keys = []; +// +// if(bitlength > 32){ +// this.crc = lcg64; +// this.bit = BigInt(bitlength); +// } +// else { +// this.crc = lcg; +// this.bit = bitlength; +// } +// +// return /*this.proxy =*/ new Proxy(this, { +// get(target, key) { +// const address = target.crc(key); +// const obj = target.index[address]; +// return obj && obj[key]; +// }, +// set(target, key, value){ +// const address = target.crc(key); +// let obj = target.index[address]; +// if(!obj){ +// target.index[address] = obj = create_object(); +// target.keys.push(address); +// } +// obj[key] = value; +// return true; +// }, +// delete(target, key){ +// const address = target.crc(key); +// const obj = target.index[address]; +// obj && delete obj[key]; +// return true; +// } +// }); +// } +// +// KeystoreObj.prototype.clear = function(){ +// this.index = create_object(); +// this.keys = []; +// }; // KeystoreObj.prototype.destroy = function(){ // this.index = null; @@ -94,7 +88,7 @@ function _slice(self, start, end, splice) { export function KeystoreArray(arr) { - if (!this) { + if (!this || this.constructor !== KeystoreArray) { return new KeystoreArray(arr); } @@ -138,7 +132,11 @@ export function KeystoreArray(arr) { return function (key) { for (let i = 0; i < self.index.length; i++) { if (self.index[i].includes(key)) { - return !0; + return (/* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ + /* skip update: */ /* skip_update: */ /* skip deletion */ + // splice: + !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ + ); } } return (/* suggest */ /* append: */ /* enrich */!1 @@ -189,22 +187,43 @@ KeystoreArray.prototype.destroy = function () { KeystoreArray.prototype.push = function () {}; +/** + * @interface + */ +function Keystore() { + /** @type {Object} */ + this.index; + /** @type {Array} */ + this.refs; + /** @type {number} */ + this.size; + /** @type {function((string|number)):number} */ + this.crc; + /** @type {bigint|number} */ + this.bit; +} + /** * @param bitlength * @constructor + * @implements {Keystore} */ export function KeystoreMap(bitlength = 8) { - if (!this) { + if (!this || this.constructor !== KeystoreMap) { return new KeystoreMap(bitlength); } + /** @type {Object} */ this.index = create_object(); + /** @type {Array} */ this.refs = []; + /** @type {number} */ this.size = 0; if (32 < bitlength) { + /** @type {function((string|number)):number} */ this.crc = lcg64; this.bit = BigInt(bitlength); } else { @@ -231,26 +250,31 @@ KeystoreMap.prototype.set = function (key, value) { } else { this.index[address] = map = new Map([[key, value]]); this.refs.push(map); + this.size++; } }; /** * @param bitlength * @constructor + * @implements {Keystore} */ export function KeystoreSet(bitlength = 8) { - if (!this) { + if (!this || this.constructor !== KeystoreSet) { return new KeystoreSet(bitlength); } - // using plain Object with numeric key access - // just for max performance + /** @type {Object} */ this.index = create_object(); + /** @type {Array} */ this.refs = []; + /** @type {number} */ + this.size = 0; if (32 < bitlength) { + /** @type {function((string|number)):number} */ this.crc = lcg64; this.bit = BigInt(bitlength); } else { @@ -270,6 +294,7 @@ KeystoreSet.prototype.add = function (key) { } else { this.index[address] = set = new Set([key]); this.refs.push(set); + this.size++; } }; diff --git a/dist/module/serialize.js b/dist/module/serialize.js index 83482ed..e92750c 100644 --- a/dist/module/serialize.js +++ b/dist/module/serialize.js @@ -412,20 +412,41 @@ ctx: "gulliver+travel:1,2,3|4,5,6|7,8,9;" export function serialize(withFunctionWrapper = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice: !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/) { - - if (!this.reg.size) return ""; - let reg = '', - type = ""; + map = '', + ctx = ''; - for (const key of this.reg.keys()) { - type || (type = typeof key); - reg += (reg ? ',' : '') + ("string" == type ? '"' + key + '"' : key); + + if (this.reg.size) { + + let type; + for (const key of this.reg.keys()) { + type || (type = typeof key); + reg += (reg ? ',' : '') + ("string" === type ? '"' + key + '"' : key); + } + reg = 'index.reg=new Set([' + reg + ']);'; + + map = parse_map(this.map, type); + map = "index.map=new Map([" + map + "]);"; + + for (const context of this.ctx.entries()) { + const key_ctx = context[0], + value_ctx = context[1]; + + let ctx_map = parse_map(value_ctx, type); + ctx_map = "new Map([" + ctx_map + "])"; + ctx_map = '["' + key_ctx + '",' + ctx_map + ']'; + ctx += (ctx ? ',' : '') + ctx_map; + } + ctx = "index.ctx=new Map([" + ctx + "]);"; } - reg = 'index.reg=new Set([' + reg + ']);'; - let map = ''; - for (const item of this.map.entries()) { + return withFunctionWrapper ? "function inject(index){" + reg + map + ctx + "}" : reg + map + ctx; +} + +function parse_map(map, type) { + let result = ''; + for (const item of map.entries()) { const key = item[0], value = item[1]; @@ -434,43 +455,13 @@ export function serialize(withFunctionWrapper = /* tag? */ /* stringify */ /* st ids = value[i] || ['']; let str = ''; for (let j = 0; j < ids.length; j++) { - str += (str ? ',' : '') + ("string" == type ? '"' + ids[j] + '"' : ids[j]); + str += (str ? ',' : '') + ("string" === type ? '"' + ids[j] + '"' : ids[j]); } str = '[' + str + ']'; res += (res ? ',' : '') + str; } res = '["' + key + '",[' + res + ']]'; - map += (map ? ',' : '') + res; + result += (result ? ',' : '') + res; } - map = "index.map=new Map([" + map + "]);"; - - let ctx = ''; - for (const context of this.ctx.entries()) { - const key_ctx = context[0], - value_ctx = context[1]; - - - for (const item of value_ctx.entries()) { - const key = item[0], - value = item[1]; - - - let res = ''; - for (let i = 0, ids; i < value.length; i++) { - ids = value[i] || ['']; - let str = ''; - for (let j = 0; j < ids.length; j++) { - str += (str ? ',' : '') + ("string" == type ? '"' + ids[j] + '"' : ids[j]); - } - str = '[' + str + ']'; - res += (res ? ',' : '') + str; - } - res = 'new Map([["' + key + '",[' + res + ']]])'; - res = '["' + key_ctx + '",' + res + ']'; - ctx += (ctx ? ',' : '') + res; - } - } - ctx = "index.ctx=new Map([" + ctx + "]);"; - - return withFunctionWrapper ? "function inject(index){" + reg + map + ctx + "}" : reg + map + ctx; + return result; } \ No newline at end of file diff --git a/dist/module/type.js b/dist/module/type.js index 23342fd..0bc2652 100644 --- a/dist/module/type.js +++ b/dist/module/type.js @@ -186,12 +186,17 @@ export let DocumentSearchResults = []; export let EnrichedDocumentSearchResults = []; /** - * @typedef Array<{ + * @typedef {{ * id: (number|string), * doc: (Object|null), * field: (Array|undefined), * tag: (Array|undefined) - * }> + * }} + */ +export let MergedDocumentSearchEntry = {}; + +/** + * @typedef Array */ export let MergedDocumentSearchResults = []; @@ -218,7 +223,7 @@ export let EncoderSplitOptions = {}; * normalize: (boolean|(function(string):string)|undefined), * prepare: ((function(string):string)|undefined), * finalize: ((function(Array):(Array|void))|undefined), - * filter: (Set|undefined), + * filter: (Set|function(string):boolean|undefined), * matcher: (Map|undefined), * mapper: (Map|undefined), * stemmer: (Map|undefined), diff --git a/index.d.ts b/index.d.ts index 87fca40..6d5d732 100644 --- a/index.d.ts +++ b/index.d.ts @@ -120,7 +120,7 @@ declare module "flexsearch" { normalize?: boolean|((str: string) => string); prepare?: (str: string) => string; finalize?: (terms: string[]) => string[]; - filter?: Set; + filter?: Set|((term: string) => boolean); matcher?: Map; mapper?: Map; stemmer?: Map; diff --git a/package-lock.json b/package-lock.json index ad91fb8..ced64f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.123", + "version": "0.8.132", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.123", + "version": "0.8.132", "funding": [ { "type": "github", diff --git a/package.json b/package.json index dcc1ac7..d2794e7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.123", + "version": "0.8.132", "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/bundle.js b/src/bundle.js index 5ee4f0a..a20173b 100644 --- a/src/bundle.js +++ b/src/bundle.js @@ -33,6 +33,7 @@ import Resolver from "./resolver.js"; import Encoder from "./encoder.js"; import IdxDB from "./db/indexeddb/index.js"; import Charset from "./charset.js"; +import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; /** @export */ Index.prototype.add; /** @export */ Index.prototype.append; @@ -142,6 +143,10 @@ if(SUPPORT_SERIALIZE){ /** @export */ StorageInterface.prototype.commit; /** @export */ StorageInterface.prototype.remove; +/** @export */ KeystoreArray.length; +/** @export */ KeystoreMap.size; +/** @export */ KeystoreSet.size; + /** @export */ Charset.LatinExact; /** @export */ Charset.LatinDefault; /** @export */ Charset.LatinSimple; diff --git a/src/common.js b/src/common.js index cbc8b2b..99dff3a 100644 --- a/src/common.js +++ b/src/common.js @@ -63,58 +63,58 @@ export function merge_option(value, default_value, merge_value){ ? default_value : value; } +// +// /** +// * @param {!number} count +// * @returns {Array} +// */ -/** - * @param {!number} count - * @returns {Array} - */ +// export function create_object_array(count){ +// +// const array = new Array(count); +// +// for(let i = 0; i < count; i++){ +// array[i] = create_object(); +// } +// +// return array; +// } -export function create_object_array(count){ +// /** +// * @param {!number} count +// * @returns {Array} +// */ - const array = new Array(count); +// export function create_map_array(count){ +// +// const array = new Array(count); +// +// for(let i = 0; i < count; i++){ +// array[i] = new Map(); +// } +// +// return array; +// } - for(let i = 0; i < count; i++){ - array[i] = create_object(); - } +// export function create_arrays(count){ +// +// const array = new Array(count); +// +// for(let i = 0; i < count; i++){ +// array[i] = []; +// } +// +// return array; +// } +// +// /** +// * @param {!Object} obj +// * @returns {Array} +// */ - return array; -} - -/** - * @param {!number} count - * @returns {Array} - */ - -export function create_map_array(count){ - - const array = new Array(count); - - for(let i = 0; i < count; i++){ - array[i] = new Map(); - } - - return array; -} - -export function create_arrays(count){ - - const array = new Array(count); - - for(let i = 0; i < count; i++){ - array[i] = []; - } - - return array; -} - -/** - * @param {!Object} obj - * @returns {Array} - */ - -export function get_keys(obj){ - return Object.keys(obj); -} +// export function get_keys(obj){ +// return Object.keys(obj); +// } export function create_object(){ return Object.create(null); diff --git a/src/db/clickhouse/index.js b/src/db/clickhouse/index.js index cefba78..59fd133 100644 --- a/src/db/clickhouse/index.js +++ b/src/db/clickhouse/index.js @@ -1,6 +1,3 @@ -// COMPILER BLOCK --> -import { DEBUG } from "../../config.js"; -// <-- COMPILER BLOCK import { ClickHouse } from "clickhouse"; import StorageInterface from "../interface.js"; import { concat, toArray } from "../../common.js"; @@ -178,8 +175,8 @@ ClickhouseDB.prototype.open = async function(){ }; ClickhouseDB.prototype.close = function(){ - this.db.close(); - this.db = null; + //DB && DB.close(); + this.db = DB = null; return this; }; @@ -339,19 +336,18 @@ ClickhouseDB.prototype.enrich = async function(ids){ : result; } -ClickhouseDB.prototype.has = function(id){ - return this.db.query(` - SELECT EXISTS( - SELECT 1 - FROM ${this.id}.reg - WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}} - LIMIT 1 - )`, +ClickhouseDB.prototype.has = async function(id){ + const result = await this.db.query(` + SELECT 1 as exist + FROM ${this.id}.reg + WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}} + LIMIT 1`, { params: { id }} ).toPromise(); + return !!(result && result[0] && result[0].exist); }; -ClickhouseDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = true, tags){ +ClickhouseDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ let rows; if(query.length > 1 && flexsearch.depth){ @@ -384,7 +380,7 @@ ClickhouseDB.prototype.search = function(flexsearch, query, limit = 100, offset ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM ${ this.id }.ctx${ this.field } WHERE ${ where } GROUP BY id @@ -450,7 +446,7 @@ ClickhouseDB.prototype.search = function(flexsearch, query, limit = 100, offset ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM ${ this.id }.map${ this.field } WHERE ${ where } GROUP BY id diff --git a/src/db/indexeddb/index.js b/src/db/indexeddb/index.js index 5261a30..e9d998e 100644 --- a/src/db/indexeddb/index.js +++ b/src/db/indexeddb/index.js @@ -138,7 +138,7 @@ IdxDB.prototype.open = function(){ }; IdxDB.prototype.close = function(){ - this.db.close(); + this.db && this.db.close(); this.db = null; }; @@ -285,7 +285,9 @@ IdxDB.prototype.has = function(id){ const transaction = this.db.transaction("reg", "readonly"); const map = transaction.objectStore("reg"); const req = map.getKey(id); - return promisfy(req); + return promisfy(req).then(function(result){ + return !!result; + }); }; IdxDB.prototype.search = null; diff --git a/src/db/mongodb/index.js b/src/db/mongodb/index.js index 3b62043..ce98cd8 100644 --- a/src/db/mongodb/index.js +++ b/src/db/mongodb/index.js @@ -123,8 +123,9 @@ MongoDB.prototype.open = async function(){ }; MongoDB.prototype.close = function(){ - this.db.close(); - this.db = null; + //CLIENT && CLIENT.close(); + this.db = CLIENT = null; + DB[this.id] = null; return this; }; @@ -308,7 +309,9 @@ MongoDB.prototype.enrich = function(ids){ }; MongoDB.prototype.has = function(id){ - return this.db.collection("reg").countDocuments({ id }, { limit: 1 }); + return this.db.collection("reg").countDocuments({ id }, { limit: 1 }).then(function(result){ + return !!result; + }); }; MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ @@ -331,16 +334,17 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset keyword = term; } - let project = resolve - ? { _id: 1 } - : { _id: 1, res: 1 }; + + const project = { _id: 1 }; + if(!resolve) project["res"] = 1; + if(enrich) project["doc"] = 1; const stmt = [ { $match: { $or: params } }, { $group: { _id: "$id", - res: suggest ? { $sum: 1 } : { $min: 1 }, - count: { $sum: 1 } + count: { $sum: 1 }, + res: suggest ? { $sum: "$res" } : { $sum /*$min*/: "$res" } } } ]; @@ -382,14 +386,14 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset } stmt.push( - { $project: project }, + //{ $project: project }, { $match: match } ); } - else{ - stmt.push( - { $project: project } - ); + else { + // stmt.push( + // { $project: project } + // ); } stmt.push( @@ -400,23 +404,23 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset { $limit: limit } ); - if(tags){ - project = { _id: 1 }; - if(!resolve) project["res"] = 1; - if(enrich) project["doc"] = 1; + // if(tags){ + // project = { _id: 1 }; + // if(!resolve) project["res"] = 1; + // if(enrich) project["doc"] = 1; + // } - stmt.push( - { $project: project } - ); - } + stmt.push( + { $project: project } + ); rows = await this.db.collection("ctx" + this.field).aggregate(stmt); } else{ - let project = resolve - ? { _id: 1 } - : { _id: 1, res: 1 }; + const project = { _id: 1 }; + if(!resolve) project["res"] = 1; + if(enrich) project["doc"] = 1; const stmt = [ { $match: { @@ -424,8 +428,8 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset } }, { $group: { _id: "$id", - res: suggest ? { $sum: 1 } : { $min: 1 }, - count: { $sum: 1 } + count: { $sum: 1 }, + res: suggest ? { $sum: "$res" } : { $sum /*$min*/: "$res" } } } ]; @@ -467,14 +471,14 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset } stmt.push( - { $project: project }, + //{ $project: project }, { $match: match } ); } - else{ - stmt.push( - { $project: project } - ); + else { + // stmt.push( + // { $project: project } + // ); } stmt.push( @@ -483,17 +487,17 @@ MongoDB.prototype.search = async function(flexsearch, query, limit = 100, offset : { res: 1 } }, { $skip: offset}, { $limit: limit } - ) + ); - if(tags){ - project = { _id: 1 }; - if(!resolve) project["res"] = 1; - if(enrich) project["doc"] = 1; + // if(tags){ + // project = { _id: 1 }; + // if(!resolve) project["res"] = 1; + // if(enrich) project["doc"] = 1; + // } - stmt.push( - { $project: project } - ); - } + stmt.push( + { $project: project } + ); rows = await this.db.collection("map" + this.field).aggregate(stmt); } diff --git a/src/db/postgres/index.js b/src/db/postgres/index.js index 482afb0..5c6f17d 100644 --- a/src/db/postgres/index.js +++ b/src/db/postgres/index.js @@ -1,7 +1,3 @@ -// COMPILER BLOCK --> -import { DEBUG } from "../../config.js"; -// <-- COMPILER BLOCK - import pg_promise from "pg-promise"; import StorageInterface from "../interface.js"; import { concat, toArray } from "../../common.js"; @@ -14,7 +10,7 @@ const defaults = { port: "5432" }; -const pgp = pg_promise({ noWarnings: !DEBUG }); +const pgp = pg_promise(/*{ noWarnings: true }*/); const VERSION = 1; const MAXIMUM_QUERY_VARS = 16000; const fields = ["map", "ctx", "reg", "tag", "cfg"]; @@ -57,7 +53,7 @@ export default function PostgresDB(name, config = {}){ } if(typeof name === "object"){ config = name; - name = name.name; + name = config.name; } if(!name){ console.info("Default storage space was used, because a name was not passed."); @@ -184,8 +180,8 @@ PostgresDB.prototype.open = async function(){ }; PostgresDB.prototype.close = function(){ - this.db.close && this.db.close(); - this.db = DB = null; + //DB && DB.close && DB.close(); + this.db = /*DB =*/ null; return this; }; @@ -342,7 +338,9 @@ PostgresDB.prototype.enrich = async function(ids){ }; PostgresDB.prototype.has = function(id){ - return this.db.oneOrNone("SELECT EXISTS(SELECT 1 FROM " + this.id + ".reg WHERE id = $1)", [id]); + return this.db.oneOrNone("SELECT EXISTS(SELECT 1 FROM " + this.id + ".reg WHERE id = $1)", [id]).then(function(result){ + return !!(result && result.exists); + }); }; PostgresDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ @@ -380,7 +378,7 @@ PostgresDB.prototype.search = function(flexsearch, query, limit = 100, offset = ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM ${ this.id }.ctx${ this.field } WHERE ${ where } GROUP BY id @@ -449,7 +447,7 @@ PostgresDB.prototype.search = function(flexsearch, query, limit = 100, offset = ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM ${ this.id }.map${ this.field } WHERE ${ where } GROUP BY id @@ -549,17 +547,23 @@ PostgresDB.prototype.info = function(){ // }; PostgresDB.prototype.transaction = function(task){ - if(TRX){ - return task.call(this, TRX); - } const self = this; - return (TRX || this.db).tx(function(trx){ - return task.call(self, TRX = trx); - }).finally(function(){ - TRX = null; - }) + return this.db.tx(function(trx){ + return task.call(self, trx); + }); }; +// PostgresDB.prototype.transaction = async function(task){ +// if(TRX){ +// return await task.call(this, TRX); +// } +// const self = this; +// return this.db.tx(async function(trx){ +// await task.call(self, TRX = trx); +// TRX = null; +// }); +// }; + PostgresDB.prototype.commit = async function(flexsearch, _replace, _append){ // process cleanup tasks diff --git a/src/db/redis/index.js b/src/db/redis/index.js index b0a571c..3ddf01c 100644 --- a/src/db/redis/index.js +++ b/src/db/redis/index.js @@ -1,7 +1,3 @@ -// COMPILER BLOCK --> -import { DEBUG } from "../../config.js"; -// <-- COMPILER BLOCK - import { createClient } from "redis"; const defaults = { host: "localhost", @@ -82,7 +78,7 @@ RedisDB.prototype.open = async function(){ }; RedisDB.prototype.close = async function(){ - await this.db.disconnect(); // this.db.client.disconnect(); + DB && await this.db.disconnect(); // this.db.client.disconnect(); this.db = null; return this; }; @@ -205,11 +201,11 @@ RedisDB.prototype.has = function(id){ RedisDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ let result; + let params = []; if(query.length > 1 && flexsearch.depth){ const key = this.id + "ctx" + this.field + ":"; - let params = []; let keyword = query[0]; let term; @@ -219,19 +215,20 @@ RedisDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, params.push(key + (swap ? term : keyword) + ":" + (swap ? keyword : term)); keyword = term; } - query = params; } - else{ + else { const key = this.id + "map" + this.field + ":"; for(let i = 0; i < query.length; i++){ - query[i] = key + query[i]; + params.push(key + query[i]); } } + query = params; + const type = this.type; let key = this.id + "tmp:" + Math.random(); - const strict_tag_intersection = false; + const strict_tag_intersection = true; if(suggest){ if(!strict_tag_intersection){ diff --git a/src/db/sqlite/index.js b/src/db/sqlite/index.js index 8e35f51..6ab2152 100644 --- a/src/db/sqlite/index.js +++ b/src/db/sqlite/index.js @@ -1,7 +1,3 @@ -// COMPILER BLOCK --> -import { DEBUG } from "../../config.js"; -// <-- COMPILER BLOCK - //const sqlite3 = require("sqlite3").verbose(); import sqlite3 from "sqlite3"; import path from "path"; @@ -203,7 +199,7 @@ SqliteDB.prototype.open = async function(){ }; SqliteDB.prototype.close = function(){ - this.db.close(); + this.db && this.db.close(); this.db = null; DB[this.id] = null; TRX[this.id] = null; @@ -411,7 +407,7 @@ SqliteDB.prototype.has = function(id){ stmt: `SELECT EXISTS(SELECT 1 FROM main.reg WHERE id = ?) as exist`, params: [id] }).then(function(result){ - return result && result.exist; + return !!(result && result.exist); }); }; @@ -450,7 +446,7 @@ SqliteDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM main.ctx${ this.field } WHERE ${ stmt } GROUP BY id @@ -520,7 +516,7 @@ SqliteDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, ${ enrich ? ", doc" : "" } FROM ( SELECT id, count(*) as count, - ${ suggest ? "SUM" : "MIN" }(res) as res + ${ suggest ? "SUM" : "SUM" /*"MIN"*/ }(res) as res FROM main.map${ this.field } WHERE ${ stmt } GROUP BY id @@ -574,15 +570,12 @@ SqliteDB.prototype.info = function(){ SqliteDB.prototype.transaction = function(task, callback){ - const self = this; - if(TRX[this.id]){ - return TRX[this.id].then(function(){ - return self.transaction(task, callback); - }); + return task.call(this); } const db = this.db; + const self = this; return TRX[this.id] = new Promise(function(resolve, reject){ db.exec("PRAGMA optimize"); @@ -802,10 +795,10 @@ SqliteDB.prototype.remove = function(ids){ this.db.run("DELETE FROM main.ctx" + self.field + " WHERE id IN (" + stmt + ")", ids); this.db.run("DELETE FROM main.tag" + self.field + " WHERE id IN (" + stmt + ")", ids); this.db.run("DELETE FROM main.reg WHERE id IN (" + stmt + ")", ids); - }).then(function(res){ + }).then(function(result){ return next ? self.remove(next) - : res; + : result; }); }; diff --git a/src/document.js b/src/document.js index 9552cea..8bdd1c2 100644 --- a/src/document.js +++ b/src/document.js @@ -241,7 +241,7 @@ if(SUPPORT_PERSISTENT){ // parallel: const promises = []; for(const index of this.index.values()){ - promises.push(index.db.commit(index, replace, append)); + promises.push(index.commit(index, replace, append)); } await Promise.all(promises); this.reg.clear(); @@ -446,15 +446,15 @@ Document.prototype.remove = function(id){ Document.prototype.clear = function(){ - //const promises = []; + const promises = []; for(const index of this.index.values()){ // db index will add clear task - index.clear(); - // const promise = index.clear(); - // if(promise instanceof Promise){ - // promises.push(promise); - // } + const promise = index.clear(); + // worker indexes will return promises + if(promise.then){ + promises.push(promise); + } } if(SUPPORT_TAGS && this.tag){ @@ -467,9 +467,13 @@ Document.prototype.clear = function(){ this.store.clear(); } - return this; /*promises.length + if(SUPPORT_CACHE && this.cache){ + this.cache.clear(); + } + + return promises.length ? Promise.all(promises) - :*/ + : this }; /** diff --git a/src/document/search.js b/src/document/search.js index 3c09a0f..52b2dc9 100644 --- a/src/document/search.js +++ b/src/document/search.js @@ -120,7 +120,7 @@ Document.prototype.search = function(query, limit, options, _promises){ } enrich = SUPPORT_STORE && this.store && options.enrich && resolve; - highlight = options.highlight && enrich; + highlight = enrich && options.highlight; limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); @@ -500,7 +500,7 @@ function highlight_fields(result, query, index, field, tree, template, limit, of // if(typeof template === "string"){ // template = new RegExp(template, "g"); // } - + console.log("template", template) let encoder; let query_enc; let tokenize; diff --git a/src/encoder.js b/src/encoder.js index 155e0dc..c637bd5 100644 --- a/src/encoder.js +++ b/src/encoder.js @@ -209,20 +209,16 @@ Encoder.prototype.assign = function(options){ ); } - // options - - this.rtl = merge_option(options.rtl, false, this.rtl); + tmp = options.filter; + this.filter = typeof tmp === "function" ? tmp : merge_option(tmp && new Set(tmp), null, this.filter); this.dedupe = merge_option(options.dedupe, false, this.dedupe); - this.filter = merge_option((tmp = options.filter) && new Set(tmp), null, this.filter); this.matcher = merge_option((tmp = options.matcher) && new Map(tmp), null, this.matcher); this.mapper = merge_option((tmp = options.mapper) && new Map(tmp), null, this.mapper); this.stemmer = merge_option((tmp = options.stemmer) && new Map(tmp), null, this.stemmer); this.replacer = merge_option(options.replacer, null, this.replacer); this.minlength = merge_option(options.minlength, 1, this.minlength); this.maxlength = merge_option(options.maxlength, 0, this.maxlength); - - // minimum required tokenizer by this encoder - //this.tokenize = options["tokenize"] || ""; + this.rtl = merge_option(options.rtl, false, this.rtl); // auto-balanced cache if(SUPPORT_CACHE){ @@ -286,8 +282,14 @@ Encoder.prototype.addStemmer = function(match, replace){ }; Encoder.prototype.addFilter = function(term){ - this.filter || (this.filter = new Set()); - this.filter.add(term); + if(typeof term === "function"){ + // does not support merge yet + this.filter = term; //merge_option(term, term, this.filter); + } + else{ + this.filter || (this.filter = new Set()); + this.filter.add(term); + } SUPPORT_CACHE && this.cache && clear(this); return this; }; @@ -415,6 +417,7 @@ Encoder.prototype.encode = function(str){ const skip = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); let final = []; + let changed; let words = this.split || this.split === "" ? str.split(/** @type {string|RegExp} */ (this.split)) : str; //[str]; @@ -433,7 +436,11 @@ Encoder.prototype.encode = function(str){ } // pre-filter before cache - if(this.filter && this.filter.has(word)){ + if(this.filter && ( + typeof this.filter === "function" + ? !this.filter(word) + : this.filter.has(word) + )){ continue; } @@ -450,17 +457,16 @@ Encoder.prototype.encode = function(str){ } } - // apply stemmer after matcher + // todo compare advantages when filter/stemmer are also encoded + // apply stemmer before bigger transformations if(this.stemmer && (word.length > 2)){ // for(const item of this.stemmer){ // const key = item[0]; // const value = item[1]; - // // if(word.length > key.length && word.endsWith(key)){ // word = word.substring(0, word.length - key.length) + value; // break; // } - // // // const position = word.length - key.length; // // if(position > 0 && word.substring(position) === key){ // // word = word.substring(0, position) + value; @@ -470,11 +476,18 @@ Encoder.prototype.encode = function(str){ this.stemmer_test || ( this.stemmer_test = new RegExp("(?!^)(" + this.stemmer_str + ")$") ); + + const old = word; word = word.replace(this.stemmer_test, match => this.stemmer.get(match)); - // 4. post-filter after matcher and stemmer was applied - if(word.length < this.minlength || (this.filter && this.filter.has(word))){ - word = ""; + // 4. post-filter after stemmer was applied + if(old !== word && this.filter && word.length >= this.minlength){ + if(typeof this.filter === "function" + ? !this.filter(word) + : this.filter.has(word) + ){ + word = ""; + } } } diff --git a/src/index.js b/src/index.js index f2645c0..9ef84f9 100644 --- a/src/index.js +++ b/src/index.js @@ -57,10 +57,15 @@ export default function Index(options, _register){ : {} ); + /** @type {*} */ let tmp = options.context; /** @type ContextOptions */ - const context = tmp === true - ? { depth: 1 } : tmp || {}; + const context = /** @type ContextOptions */ ( + tmp === true + ? { depth: 1 } + : tmp || {} + ); + const encoder = SUPPORT_CHARSET && is_string(options.encoder) ? Charset[options.encoder] : options.encode || options.encoder || ( @@ -83,12 +88,18 @@ export default function Index(options, _register){ } this.resolution = options.resolution || 9; - this.tokenize = ((tmp = options.tokenize) && (tmp !== "default") && tmp) || "strict"; + this.tokenize = tmp = ((tmp = options.tokenize) && (tmp !== "default") && tmp) || "strict"; this.depth = (tmp === "strict" && context.depth) || 0; this.bidirectional = context.bidirectional !== false; this.fastupdate = !!options.fastupdate; this.score = options.score || null; + if(DEBUG){ + if(context && this.tokenize !== "strict"){ + console.warn("Context-Search could not applied, because it is just supported when using the tokenizer \"strict\".") + } + } + tmp = SUPPORT_KEYSTORE && (options.keystore || 0); tmp && (this.keystore = tmp); @@ -225,7 +236,7 @@ function cleanup_index(map){ (count += arr.length); } } - else for(const item of map){ + else for(const item of map.entries()){ const key = item[0]; const value = item[1]; const tmp = cleanup_index(value); diff --git a/src/intersect.js b/src/intersect.js index f596838..9af00e3 100644 --- a/src/intersect.js +++ b/src/intersect.js @@ -79,6 +79,19 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res } tmp.push(id); + + // fast path early result when limit was set + if(!SUPPORT_RESOLVER || resolve){ + if(limit && (count === length - 1)){ + // if(tmp.length - offset > limit){ + // return tmp.slice(offset, limit + offset); + // } + if(tmp.length - offset === limit){ + return tmp; + } + } + } + // todo break early on suggest: true } } } @@ -109,6 +122,8 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res } } else{ + // todo this is doing the same as Resolver.resolve({limit}) ? + // todo check limit + offset when resolve = false const final = []; for(let i = 0, arr; i < result.length; i++){ arr = result[i]; diff --git a/src/keystore.js b/src/keystore.js index a39510c..f05c42c 100644 --- a/src/keystore.js +++ b/src/keystore.js @@ -1,57 +1,57 @@ import { create_object } from "./common.js"; -/** - * @param bitlength - * @constructor - */ - -export function KeystoreObj(bitlength = 8){ - - if(!this){ - return new KeystoreObj(bitlength); - } - - this.index = create_object(); - this.keys = []; - - if(bitlength > 32){ - this.crc = lcg64; - this.bit = BigInt(bitlength); - } - else { - this.crc = lcg; - this.bit = bitlength; - } - - return /*this.proxy =*/ new Proxy(this, { - get(target, key) { - const address = target.crc(key); - const obj = target.index[address]; - return obj && obj[key]; - }, - set(target, key, value){ - const address = target.crc(key); - let obj = target.index[address]; - if(!obj){ - target.index[address] = obj = create_object(); - target.keys.push(address); - } - obj[key] = value; - return true; - }, - delete(target, key){ - const address = target.crc(key); - const obj = target.index[address]; - obj && delete obj[key]; - return true; - } - }); -} - -KeystoreObj.prototype.clear = function(){ - this.index = create_object(); - this.keys = []; -}; +// /** +// * @param bitlength +// * @constructor +// */ +// +// export function KeystoreObj(bitlength = 8){ +// +// if(!this || this.constructor !== KeystoreObj){ +// return new KeystoreObj(bitlength); +// } +// +// this.index = create_object(); +// this.keys = []; +// +// if(bitlength > 32){ +// this.crc = lcg64; +// this.bit = BigInt(bitlength); +// } +// else { +// this.crc = lcg; +// this.bit = bitlength; +// } +// +// return /*this.proxy =*/ new Proxy(this, { +// get(target, key) { +// const address = target.crc(key); +// const obj = target.index[address]; +// return obj && obj[key]; +// }, +// set(target, key, value){ +// const address = target.crc(key); +// let obj = target.index[address]; +// if(!obj){ +// target.index[address] = obj = create_object(); +// target.keys.push(address); +// } +// obj[key] = value; +// return true; +// }, +// delete(target, key){ +// const address = target.crc(key); +// const obj = target.index[address]; +// obj && delete obj[key]; +// return true; +// } +// }); +// } +// +// KeystoreObj.prototype.clear = function(){ +// this.index = create_object(); +// this.keys = []; +// }; // KeystoreObj.prototype.destroy = function(){ // this.index = null; @@ -90,7 +90,7 @@ function _slice(self, start, end, splice){ export function KeystoreArray(arr){ - if(!this){ + if(!this || this.constructor !== KeystoreArray){ return new KeystoreArray(arr); } @@ -193,19 +193,39 @@ KeystoreArray.prototype.destroy = function(){ KeystoreArray.prototype.push = function(val){}; +/** + * @interface + */ +function Keystore() { + /** @type {Object} */ + this.index; + /** @type {Array} */ + this.refs; + /** @type {number} */ + this.size; + /** @type {function((string|bigint|number)):number} */ + this.crc; + /** @type {bigint|number} */ + this.bit; +} + /** * @param bitlength * @constructor + * @implements Keystore */ export function KeystoreMap(bitlength = 8){ - if(!this){ + if(!this || this.constructor !== KeystoreMap){ return new KeystoreMap(bitlength); } + /** @type {Object} */ this.index = create_object(); + /** @type {Array} */ this.refs = []; + /** @type {number} */ this.size = 0; if(bitlength > 32){ @@ -218,12 +238,17 @@ export function KeystoreMap(bitlength = 8){ } } +/** @param {number|string} key */ KeystoreMap.prototype.get = function(key) { const address = this.crc(key); const map = this.index[address]; return map && map.get(key); }; +/** + * @param {number|string} key + * @param {*} value + */ KeystoreMap.prototype.set = function(key, value){ const address = this.crc(key); let map = this.index[address]; @@ -236,24 +261,28 @@ KeystoreMap.prototype.set = function(key, value){ else{ this.index[address] = map = new Map([[key, value]]); this.refs.push(map); + this.size++; } }; /** * @param bitlength * @constructor + * @implements Keystore */ export function KeystoreSet(bitlength = 8){ - if(!this){ + if(!this || this.constructor !== KeystoreSet){ return new KeystoreSet(bitlength); } - // using plain Object with numeric key access - // just for max performance + /** @type {Object} */ this.index = create_object(); + /** @type {Array} */ this.refs = []; + /** @type {number} */ + this.size = 0; if(bitlength > 32){ this.crc = lcg64; @@ -265,6 +294,7 @@ export function KeystoreSet(bitlength = 8){ } } +/** @param {number|string} key */ KeystoreSet.prototype.add = function(key){ const address = this.crc(key); let set = this.index[address]; @@ -277,10 +307,12 @@ KeystoreSet.prototype.add = function(key){ else{ this.index[address] = set = new Set([key]); this.refs.push(set); + this.size++; } }; KeystoreMap.prototype.has = +/** @param {number|string} key */ KeystoreSet.prototype.has = function(key) { const address = this.crc(key); const map_or_set = this.index[address]; @@ -300,6 +332,7 @@ KeystoreSet.prototype.size = function(){ */ KeystoreMap.prototype.delete = +/** @param {number|string} key */ KeystoreSet.prototype.delete = function(key){ const address = this.crc(key); const map_or_set = this.index[address]; @@ -325,6 +358,9 @@ KeystoreSet.prototype.clear = function(){ // this.proxy = null; // }; +/** + * @return Iterable + */ KeystoreMap.prototype.values = KeystoreSet.prototype.values = function*(){ // alternatively iterate through this.keys[] @@ -336,6 +372,9 @@ KeystoreSet.prototype.values = function*(){ } }; +/** + * @return Iterable + */ KeystoreMap.prototype.keys = KeystoreSet.prototype.keys = function*(){ //const values = Object.values(this.index); @@ -346,6 +385,9 @@ KeystoreSet.prototype.keys = function*(){ } }; +/** + * @return Iterable + */ KeystoreMap.prototype.entries = KeystoreSet.prototype.entries = function*(){ //const values = Object.values(this.index); @@ -358,7 +400,7 @@ KeystoreSet.prototype.entries = function*(){ /** * Linear Congruential Generator (LCG) - * @param str + * @param {!number|bigint|string} str * @this {KeystoreMap|KeystoreSet} */ @@ -379,20 +421,20 @@ function lcg(str) { } /** - * @param str + * @param {!number|bigint|string} str * @this {KeystoreMap|KeystoreSet} */ function lcg64(str) { - let range = BigInt(2) ** /** @type {!BigInt} */ (this.bit) - BigInt(1); + let range = BigInt(2) ** /** @type {!bigint} */ (this.bit) - BigInt(1); let type = typeof str; if(type === "bigint"){ - return /** @type {!BigInt} */ (str) & range; + return /** @type {!bigint} */ (str) & range; } if(type === "number"){ return BigInt(str) & range; } - let crc = BigInt(0), bit = /** @type {!BigInt} */ (this.bit) + BigInt(1); + let crc = BigInt(0), bit = /** @type {!bigint} */ (this.bit) + BigInt(1); for(let i = 0; i < str.length; i++){ crc = (crc * bit ^ BigInt(str.charCodeAt(i))) & range; } diff --git a/src/serialize.js b/src/serialize.js index 69bbb4e..12ef734 100644 --- a/src/serialize.js +++ b/src/serialize.js @@ -452,18 +452,41 @@ ctx: "gulliver+travel:1,2,3|4,5,6|7,8,9;" export function serialize(withFunctionWrapper = true){ - if(!this.reg.size) return ""; - let reg = ''; - let type = ""; - for(const key of this.reg.keys()){ - type || (type = typeof key); - reg += (reg ? ',' : '') + (type === "string" ? '"' + key + '"' : key); - } - reg = 'index.reg=new Set([' + reg + ']);'; - let map = ''; - for(const item of this.map.entries()){ + let ctx = ''; + + if(this.reg.size){ + + let type; + for(const key of this.reg.keys()){ + type || (type = typeof key); + reg += (reg ? ',' : '') + (type === "string" ? '"' + key + '"' : key); + } + reg = 'index.reg=new Set([' + reg + ']);'; + + map = parse_map(this.map, type); + map = "index.map=new Map([" + map + "]);"; + + for(const context of this.ctx.entries()){ + const key_ctx = context[0]; + const value_ctx = context[1]; + let ctx_map = parse_map(value_ctx, type); + ctx_map = "new Map([" + ctx_map + "])"; + ctx_map = '["' + key_ctx + '",' + ctx_map + ']'; + ctx += (ctx ? ',' : '') + ctx_map; + } + ctx = "index.ctx=new Map([" + ctx + "]);"; + } + + return withFunctionWrapper + ? "function inject(index){" + reg + map + ctx + "}" + : reg + map + ctx +} + +function parse_map(map, type){ + let result = ''; + for(const item of map.entries()){ const key = item[0]; const value = item[1]; let res = ''; @@ -477,37 +500,7 @@ export function serialize(withFunctionWrapper = true){ res += (res ? ',' : '') + str; } res = '["' + key + '",[' + res + ']]'; - map += (map ? ',' : '') + res; + result += (result ? ',' : '') + res; } - map = "index.map=new Map([" + map + "]);"; - - let ctx = ''; - for(const context of this.ctx.entries()){ - const key_ctx = context[0]; - const value_ctx = context[1]; - - for(const item of value_ctx.entries()){ - const key = item[0]; - const value = item[1]; - - let res = ''; - for(let i = 0, ids; i < value.length; i++){ - ids = value[i] || ['']; - let str = ''; - for(let j = 0; j < ids.length; j++){ - str += (str ? ',' : '') + (type === "string" ? '"' + ids[j] + '"' : ids[j]); - } - str = '[' + str + ']'; - res += (res ? ',' : '') + str; - } - res = 'new Map([["' + key + '",[' + res + ']]])'; - res = '["' + key_ctx + '",' + res + ']'; - ctx += (ctx ? ',' : '') + res; - } - } - ctx = "index.ctx=new Map([" + ctx + "]);"; - - return withFunctionWrapper - ? "function inject(index){" + reg + map + ctx + "}" - : reg + map + ctx -} + return result; +} \ No newline at end of file diff --git a/src/type.js b/src/type.js index a8dbacb..532d780 100644 --- a/src/type.js +++ b/src/type.js @@ -224,7 +224,7 @@ export let EncoderSplitOptions = {}; * normalize: (boolean|(function(string):string)|undefined), * prepare: ((function(string):string)|undefined), * finalize: ((function(Array):(Array|void))|undefined), - * filter: (Set|undefined), + * filter: (Set|function(string):boolean|undefined), * matcher: (Map|undefined), * mapper: (Map|undefined), * stemmer: (Map|undefined), diff --git a/test/async.js b/test/async.js index c3d0f60..357d8de 100644 --- a/test/async.js +++ b/test/async.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; console.log("--RELEASE-------------"); console.log(env ? "dist/" + env + ".js" : "src/bundle.js") diff --git a/test/basic.js b/test/basic.js index f15d64a..fabf8a9 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; // console.log("--------------"); // console.log(env ? "dist/" + env + ".js" : "src/bundle.js") @@ -204,6 +204,9 @@ describe("Search Scoring", function(){ expect(result.length).to.equal(1); expect(result).to.eql([1]); + result = index.search("cute dogs cats", { suggest: true }); + expect(result).to.eql([1, 6, 5, 4, 3, 2, 0]); + result = index.search("cute cat"); expect(result.length).to.equal(0); }); @@ -311,7 +314,10 @@ describe("Update (Sync)", function(){ it("Should have been updated to the index", function(){ - const index = new Index({ tokenize: "full" }); + const index = new Index({ + fastupdate: true, + tokenize: "full" + }); index.add(1, "foo"); index.add(2, "bar"); index.add(3, "foobar"); @@ -365,7 +371,10 @@ describe("Remove (Sync)", function(){ it("Should have been removed from the index", function(){ - const index = new Index({ tokenize: "full" }); + const index = new Index({ + fastupdate: true, + tokenize: "full" + }); index.add(1, "bar"); index.add(2, "foobar"); index.add(3, "foo"); @@ -382,577 +391,63 @@ describe("Remove (Sync)", function(){ }); }); -// if(env !== "light") describe("Operators", function(){ -// -// var data = [{ -// id: 2, -// title: "Title 3", -// body: "Body 3", -// blacklist: "x1" -// },{ -// id: 1, -// title: "Title 2", -// body: "Body 2", -// blacklist: "x2" -// },{ -// id: 0, -// title: "Title 1", -// body: "Body 1", -// blacklist: "x3" -// }]; -// -// var index = new FlexSearch({ -// tokenize: "forward", -// doc: { -// id: "id", -// field: ["title", "body", "blacklist"] -// } -// }); -// -// it("Should have been properly applied logic", function(){ -// -// index.add(data); -// -// expect(index.search([{ -// field: "title", -// query: "title", -// bool: "and" -// },{ -// field: "body", -// query: "body", -// bool: "and" -// },{ -// field: "blacklist", -// query: "xxx", -// bool: "not" -// }])).to.have.members(data); -// -// expect(index.search([{ -// field: "title", -// query: "title", -// bool: "and" -// },{ -// field: "body", -// query: "title", -// bool: "and" -// },{ -// field: "blacklist", -// query: "xxx", -// bool: "not" -// }])).to.have.length(0); -// -// expect(index.search([{ -// field: "title", -// query: "title", -// bool: "and" -// },{ -// field: "body", -// query: "title", -// bool: "or" -// },{ -// field: "blacklist", -// query: "xxx", -// bool: "not" -// }])).to.have.members(data); -// -// expect(index.search([{ -// field: "title", -// query: "title", -// bool: "and" -// },{ -// field: "body", -// query: "title", -// bool: "or" -// }])).to.have.members(data); -// -// expect(index.search([{ -// field: "title", -// query: "title", -// bool: "and" -// },{ -// field: "body", -// query: "title", -// bool: "or" -// },{ -// field: "blacklist", -// query: "x1", -// bool: "not" -// }])).to.have.members([data[1], data[2]]); -// -// expect(index.search([{ -// field: "title", -// query: "body", -// bool: "or" -// },{ -// field: "body", -// query: "title", -// bool: "or" -// },{ -// field: "blacklist", -// query: "x1", -// bool: "not" -// }])).to.have.length(0); -// -// expect(index.search([{ -// field: "blacklist", -// query: "x1", -// bool: "not" -// },{ -// field: "title", -// query: "title", -// bool: "or" -// },{ -// field: "body", -// query: "body", -// bool: "or" -// }])).to.have.members([data[1], data[2]]); -// -// expect(index.search([{ -// field: "title", -// query: "body", -// bool: "or" -// },{ -// field: "body", -// query: "body", -// bool: "and" -// },{ -// field: "blacklist", -// query: "x2", -// bool: "not" -// }])).to.have.members([data[0], data[2]]); -// -// expect(index.search([{ -// field: "blacklist", -// query: "x2", -// bool: "not" -// },{ -// field: "title", -// query: "body", -// bool: "or" -// },{ -// field: "body", -// query: "body", -// bool: "and" -// }])).to.have.members([data[0], data[2]]); -// -// expect(index.search([{ -// field: "title", -// query: "body", -// bool: "or" -// },{ -// field: "blacklist", -// query: "x2", -// bool: "not" -// },{ -// field: "body", -// query: "body", -// bool: "and" -// }])).to.have.members([data[0], data[2]]); -// -// expect(index.search([{ -// field: "title", -// query: "title", -// bool: "and" -// },{ -// field: "body", -// query: "body", -// bool: "and" -// },{ -// field: "blacklist", -// query: "x", -// bool: "not" -// }])).to.have.length(0); -// -// expect(index.search([{ -// field: "title", -// query: "title", -// bool: "not" -// },{ -// field: "body", -// query: "body", -// bool: "not" -// },{ -// field: "blacklist", -// query: "x", -// bool: "not" -// }])).to.have.length(0); -// }); -// }); -// -// describe("Reserved Words", function(){ -// -// it("Should have been indexed properly", function(){ -// -// var index = new FlexSearch({ -// encode: function(str){ return [str]; }, -// tokenize: "strict", -// threshold: 0, -// depth: 3 -// }); -// -// var array = Object.getOwnPropertyNames({}.__proto__); -// array = array.concat(Object.getOwnPropertyNames(index)); -// -// array.push("prototype"); -// array.push("constructor"); -// array.push("__proto__"); -// -// if(env !== "min"){ -// -// array.push("concat"); -// array.push("hasOwnProperty"); -// array.push("length"); -// } -// -// for(var i = 0; i < array.length; i++){ -// -// index.add(array[i], array[i]); -// } -// -// for(var i = 0; i < array.length; i++){ -// -// // TODO: this word is reserved and can't be indexed -// if(array[i] === "_ctx"){ -// -// continue; -// } -// -// expect(index.search(array[i])).to.have.members([array[i]]); -// } -// }); -// }); -// -// // ------------------------------------------------------------------------ -// // Export / Import -// // ------------------------------------------------------------------------ -// -// if(env !== "light") describe("Export / Import", function(){ -// -// var data; -// -// it("Should have been exported properly", function(){ -// -// var index = new FlexSearch("match"); -// -// index.add(0, "foo"); -// index.add(1, "bar"); -// index.add(2, "foobar"); -// -// data = index.export(); -// -// if(env === ""){ -// -// expect(data).to.equal(JSON.stringify( -// [ -// index._map, -// index._ctx, -// Object.keys(index._ids) -// ] -// )); -// } -// }); -// -// it("Should have been imported properly", function(){ -// -// var index = new FlexSearch("match"); -// -// index.import(data); -// -// expect(index.length).to.equal(3); -// -// expect(index.search("foo")).to.have.lengthOf(2); -// expect(index.search("bar")).to.have.lengthOf(2); -// expect(index.search("foobar")).to.have.lengthOf(1); -// expect(index.search("foobar")[0]).to.equal(2); -// }); -// -// it("Should have been exported properly (documents)", function(){ -// -// var index = new FlexSearch({ -// -// tokenize: "strict", -// threshold: 1, -// resolution: 3, -// depth: 1, -// doc: { -// id: "id", -// field: ["title", "content"] -// } -// }); -// -// var docs = [{ -// id: 1, -// title: "Title 2", -// content: "foobar" -// },{ -// id: 0, -// title: "Title 1", -// content: "foo" -// },{ -// id: 2, -// title: "Title 3", -// content: "bar" -// }]; -// -// index.add(docs); -// data = index.export(); -// -// if(env === ""){ -// -// expect(index.doc.index["title"].length).to.equal(3); -// expect(data).to.equal(JSON.stringify([ -// [ -// index.doc.index["title"]._map, -// index.doc.index["title"]._ctx, -// Object.keys(index.doc.index["title"]._ids) -// ], -// [ -// index.doc.index["content"]._map, -// index.doc.index["content"]._ctx, -// Object.keys(index.doc.index["content"]._ids) -// ], -// index._doc -// ])); -// } -// }); -// -// it("Should have been imported properly (documents)", function(){ -// -// var index = new FlexSearch({ -// -// tokenize: "strict", -// threshold: 1, -// resolution: 3, -// depth: 1, -// doc: { -// id: "id", -// field: ["title", "content"] -// } -// }); -// -// index.import(data); -// -// if(env === ""){ -// -// expect(index.doc.index["title"].length).to.equal(3); -// expect(index.doc.index["content"].length).to.equal(3); -// } -// -// expect(index.search("foo")).to.have.lengthOf(1); -// expect(index.search("bar")).to.have.lengthOf(1); -// expect(index.search("foobar")).to.have.lengthOf(1); -// expect(index.search("foobar")[0].id).to.equal(1); -// }); -// }); -// -// // ------------------------------------------------------------------------ -// // Presets -// // ------------------------------------------------------------------------ -// -// describe("Presets", function(){ -// -// it("Should have been properly initialized", function(){ -// -// expect(FlexSearch("memory").length).to.equal(0); -// expect(FlexSearch("speed").length).to.equal(0); -// expect(FlexSearch("match").length).to.equal(0); -// expect(FlexSearch("score").length).to.equal(0); -// expect(FlexSearch("balance").length).to.equal(0); -// expect(FlexSearch("fast").length).to.equal(0); -// }); -// -// it("Should have been properly extended", function(){ -// -// var index = FlexSearch("fast"); -// index.add(0, "foobar"); -// expect(index.search("bar")).to.have.lengthOf(0); -// -// index = FlexSearch({preset: "speed", id: "test", tokenize: "reverse"}); -// expect(index.id).to.equal("test"); -// index.add(0, "foobar"); -// expect(index.search("bar")).to.have.lengthOf(1); -// expect(index.search("bar")).to.have.members([0]) -// }); -// }); -// -// // ------------------------------------------------------------------------ -// // Feature Tests -// // ------------------------------------------------------------------------ -// -// describe("Add Matchers", function(){ -// -// it("Should have been added properly", function(){ -// -// flexsearch_forward.init({ -// -// tokenize: "forward", -// matcher: { -// -// "1": "a", -// "2": "b", -// "3": "c", -// "7": "e", -// "8": "f", -// "[456]": "d" -// } -// -// }).add(0, "12345678"); -// -// expect(flexsearch_forward.search("12345678")).to.include(0); -// expect(flexsearch_forward.search("abcd")).to.include(0); -// expect(flexsearch_forward.encode("12345678")).to.eql(["abcdddef"]); -// }); -// }); -// -// // ------------------------------------------------------------------------ -// // Caching -// // ------------------------------------------------------------------------ -// -// if(env !== "light"){ -// -// describe("Caching", function(){ -// -// it("Should have been cached properly", function(){ -// -// flexsearch_cache.add(0, "foo") -// .add(1, "bar") -// .add(2, "foobar"); -// // fetch: -// expect(flexsearch_cache.search("foo")).to.have.members([0, 2]); -// expect(flexsearch_cache.search("bar")).to.have.members([1, 2]); -// expect(flexsearch_cache.search("foobar")).to.include(2); -// -// // cache: -// expect(flexsearch_cache.search("foo")).to.have.members([0, 2]); -// expect(flexsearch_cache.search("bar")).to.have.members([1, 2]); -// expect(flexsearch_cache.search("foobar")).to.include(2); -// -// // update: -// flexsearch_cache.remove(2).update(1, "foo").add(3, "foobar"); -// -// // fetch: -// expect(flexsearch_cache.search("foo")).to.have.members([0, 1, 3]); -// expect(flexsearch_cache.search("bar")).to.include(3); -// expect(flexsearch_cache.search("foobar")).to.include(3); -// -// // cache: -// expect(flexsearch_cache.search("foo")).to.have.members([0, 1, 3]); -// expect(flexsearch_cache.search("bar")).to.include(3); -// expect(flexsearch_cache.search("foobar")).to.include(3); -// }); -// }); -// } -// -// // ------------------------------------------------------------------------ -// // Debug Information -// // ------------------------------------------------------------------------ -// -// if(env !== "light" && env !== "min"){ -// -// describe("Debug", function(){ -// -// it("Should have been debug mode activated", function(){ -// -// var info = flexsearch_cache.info(); -// -// expect(info).to.have.keys([ -// -// "id", -// //"chars", -// "cache", -// "items", -// "matcher", -// //"memory", -// //"sequences", -// "resolution", -// "worker", -// "contextual", -// "depth", -// "threshold" -// ]); -// }); -// }); -// } -// -// // ------------------------------------------------------------------------ -// // Destroy -// // ------------------------------------------------------------------------ -// -// describe("Destroy", function(){ -// -// it("Should have been destroyed properly", function(){ -// -// var index = FlexSearch() -// .add(0, "foo") -// .add(1, "bar"); -// -// expect(index.search("foo")).to.include(0); -// expect(index.search("bar")).to.include(1); -// -// index.destroy(); -// -// expect(index.search("foo")).to.have.lengthOf(0); -// expect(index.search("bar")).to.have.lengthOf(0); -// }); -// -// if(env !== "light") it("Should have been destroyed properly (documents)", function(){ -// -// var data = [{id: 0, title: "foo"}, {id: 1, title: "bar"}]; -// -// var index = FlexSearch({doc: {id: "id", field: "title"}}) -// .add(data) -// .add(data); -// -// expect(index.search("foo")).to.have.members([data[0]]); -// expect(index.search("bar")).to.have.members([data[1]]); -// -// index.destroy(); -// -// expect(index.search("foo")).to.have.lengthOf(0); -// expect(index.search("bar")).to.have.lengthOf(0); -// }); -// }); -// -// // ------------------------------------------------------------------------ -// // Chaining -// // ------------------------------------------------------------------------ -// -// describe("Chaining", function(){ -// -// it("Should have been chained properly", function(){ -// -// var index = FlexSearch({tokenize: "forward", matcher: {"â": "a"}}) -// .add(0, "foo") -// .add(1, "bar"); -// -// expect(index.search("foo")).to.include(0); -// expect(index.search("bar")).to.include(1); -// expect(index.encode("bâr")).to.eql(["bar"]); -// -// index.remove(0).update(1, "foo").add(2, "foobâr"); -// -// expect(index.search("foo")).to.have.members([1, 2]); -// expect(index.search("bar")).to.have.lengthOf(0); -// expect(index.search("foobar")).to.include(2); -// -// index.clear().add(0, "foo").add(1, "bar"); -// -// expect(index.search("foo")).to.include(0); -// expect(index.search("bar")).to.include(1); -// expect(index.search("foobar")).to.have.lengthOf(0); -// -// flexsearch_cache.destroy().init().add(0, "foo").add(1, "bar"); -// -// expect(flexsearch_cache.search("foo")).to.include(0); -// expect(flexsearch_cache.search("bar")).to.include(1); -// expect(flexsearch_cache.search("foobar")).to.have.lengthOf(0); -// }); -// }); -//} +describe("Reserved Words", function(){ -/* Test Helpers */ + it("Should have reserved properties taken into account", function(){ -function test_encoder(str){ + const index = new Index({ + encode: function(str){ return [str]; }, + tokenize: "strict" + }); - return "-[" + str.toUpperCase() + "]-"; -} \ No newline at end of file + let array = Object.getOwnPropertyNames({}.__proto__); + array = array.concat(Object.getOwnPropertyNames(index)); + array = array.concat(Object.getOwnPropertyNames(index.map)); + array.includes("prototype") || array.push("prototype"); + array.includes("constructor") || array.push("constructor"); + array.includes("__proto__") || array.push("__proto__"); + array.includes("concat") || array.push("concat"); + array.includes("hasOwnProperty") || array.push("hasOwnProperty"); + array.includes("length") || array.push("length"); + array.includes("ctx") || array.push("ctx"); + + for(let i = 0; i < array.length; i++){ + index.add(i, array[i]); + } + + for(let i = 0; i < array.length; i++){ + expect(index.search(array[i])).to.eql([i]); + } + }); +}); + +describe("Presets", function(){ + + it("Should have been properly initialized", function(){ + + expect(Index("memory").reg.size).to.equal(0); + expect(Index("performance").reg.size).to.equal(0); + expect(Index("match").reg.size).to.equal(0); + expect(Index("score").reg.size).to.equal(0); + expect(Index("default").reg.size).to.equal(0); + }); + + it("Should have been properly extended", function(){ + + let index = Index({ preset: "performance" }); + index.add(0, "foobar"); + expect(index.search("bar")).to.have.lengthOf(0); + + index = Index({ + preset: "performance", + tokenize: "reverse" + }); + + index.add(0, "foobar"); + expect(index.search("bar")).to.eql([0]); + + index = Index("match"); + index.add(0, "foobar"); + expect(index.search("foo")).to.eql([0]); + }); +}); diff --git a/test/cache.js b/test/cache.js new file mode 100644 index 0000000..ad25392 --- /dev/null +++ b/test/cache.js @@ -0,0 +1,71 @@ +global.self = global; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; +import { expect } from "chai"; +let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); +if(FlexSearch.default) FlexSearch = FlexSearch.default; +if(FlexSearch.FlexSearch) FlexSearch = FlexSearch.FlexSearch; +const { Index, Document, Worker, Charset: _Charset, Encoder, Resolver } = FlexSearch; +const build_light = env && env.includes(".light"); +const build_compact = env && env.includes(".compact"); +const build_esm = !env || env.startsWith("module"); +const Charset = _Charset || (await import("../src/charset.js")).default; + +describe("Caching", function(){ + + it("Should have been cached and sorted by popularity/latest", function(){ + + const index = new Index({ + cache: 2, + tokenize: "reverse" + }); + + index.add(0, "foo") + .add(1, "bar") + .add(2, "foobar"); + + expect(index.searchCache("foo")).to.eql([0, 2]); + expect(index.searchCache("bar")).to.eql([1, 2]); + expect(index.searchCache("foobar")).to.eql([2]); + + expect(index.cache.cache.size).to.equal(2); // limit = 2 + env || expect(index.cache.last).to.equal("foobar"); + expect(Array.from(index.cache.cache.values()).pop()).to.eql([2]); + + expect(index.searchCache("foobar")).to.eql([2]); + expect(index.searchCache("bar")).to.eql([1, 2]); + expect(index.searchCache("foo")).to.eql([0, 2]); + + expect(index.cache.cache.size).to.equal(2); + env || expect(index.cache.last).to.equal("foo"); + expect(Array.from(index.cache.cache.values()).pop()).to.eql([0, 2]); + + expect(index.searchCache("bar")).to.eql([1, 2]); + expect(Array.from(index.cache.cache.values()).pop()).to.eql([1, 2]); + + // Synchronization + // ------------------------------------ + + index.remove(2).update(1, "foo").add(3, "foobar"); + + // 2 was removed + expect(index.cache.cache.size).to.equal(1); + // 2 was removed, 3 was added, the cache takes the original reference + // that's why this was automatically added here + // it does not need to invalidate for this reason + expect(Array.from(index.cache.cache.values()).pop()).to.eql([0, 1, 3]); + + expect(index.searchCache("foo")).to.eql([0, 1, 3]); + expect(index.search("foo")).to.eql([0, 1, 3]); + expect(Array.from(index.cache.cache.values()).pop()).to.eql([0, 1, 3]); + + expect(index.searchCache("bar")).to.eql([3]); + expect(index.search("bar")).to.eql([3]); + expect(Array.from(index.cache.cache.values()).pop()).to.eql([3]); + expect(index.searchCache("foobar")).to.eql([3]); + expect(index.search("foobar")).to.eql([3]); + expect(Array.from(index.cache.cache.values()).pop()).to.eql([3]); + + expect(index.searchCache("foo")).to.eql([0, 1, 3]); + expect(Array.from(index.cache.cache.values()).pop()).to.eql([0, 1, 3]); + }); +}); diff --git a/test/context.js b/test/context.js index 67026f7..eb8dc48 100644 --- a/test/context.js +++ b/test/context.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); if(FlexSearch.default) FlexSearch = FlexSearch.default; diff --git a/test/debug.js b/test/debug.js new file mode 100644 index 0000000..723a252 --- /dev/null +++ b/test/debug.js @@ -0,0 +1,15 @@ +global.self = global; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; +import { expect } from "chai"; +let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); +if(FlexSearch.default) FlexSearch = FlexSearch.default; +if(FlexSearch.FlexSearch) FlexSearch = FlexSearch.FlexSearch; +const { Index, Document, Worker, Charset: _Charset, Encoder, Resolver } = FlexSearch; +const build_light = env && env.includes(".light"); +const build_compact = env && env.includes(".compact"); +const build_esm = !env || env.startsWith("module"); +const Charset = _Charset || (await import("../src/charset.js")).default; + +describe("Debug", function(){ + +}); diff --git a/test/document.js b/test/document.js index 2e98b66..ea1227f 100644 --- a/test/document.js +++ b/test/document.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); if(FlexSearch.default) FlexSearch = FlexSearch.default; @@ -47,6 +47,8 @@ if(!build_light) describe("Document (Multi-Field Search)", function(){ }); const document_with_store = new Document({ + keystore: 2, + fastupdate: true, document: { store: true, id: "id", @@ -401,4 +403,35 @@ if(!build_light) describe("Document (Multi-Field Search)", function(){ offset: 3 })).to.eql([]); }); + + it("Custom Document Store", function(){ + + const document = new Document({ + document: { + store: [ + "data:title" + ], + id: "id", + field: [ + "data:title", + "data:body" + ] + } + }); + + for(let i = 0; i < data.length; i++){ + document.add(data[i]); + } + + expect(document.search({ + query: "title", + enrich: true, + suggest: true, + merge: true + }).map(res => res.doc)).to.eql([ + { data: { title: data[0].data.title }}, + { data: { title: data[1].data.title }}, + { data: { title: data[2].data.title }} + ]); + }); }); diff --git a/test/document.tag.js b/test/document.tag.js index ffad3fa..aebf883 100644 --- a/test/document.tag.js +++ b/test/document.tag.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); if(FlexSearch.default) FlexSearch = FlexSearch.default; @@ -201,4 +201,60 @@ if(!build_light) describe("Documents: Tag-Search", function(){ query: "bar" })).to.eql([]); }); + + it("Should have been cleared everything properly", function(){ + + const document = new Document({ + cache: true, + context: { + depth: 1 + }, + document: { + store: true, + id: "id", + field: [ + { field: "data:body", + context: { depth: 1 } + }, + { field: "data:title", + context: { depth: 1 } + } + ], + tag: "data:cat" + } + }); + + for(let i = 0; i < data.length; i++){ + document.add(data[i]); + document.searchCache(data[i].data.title) + } + + expect(document.reg.size).to.equal(3); + expect(document.tag.get("data:cat").size).to.equal(2); + expect(document.tag.get("data:cat").get("A").length).to.equal(2); + expect(document.tag.get("data:cat").get("B").length).to.equal(1); + expect(document.store.size).to.equal(3); + expect(document.cache.cache.size).to.equal(3); + expect(document.index.get("data:title").reg.size).to.equal(3); + expect(document.index.get("data:title").map.size).to.equal(4); // 4 terms + expect(document.index.get("data:title").ctx.size).to.equal(1); // 1 keyword + expect(document.index.get("data:title").ctx.get("title").size).to.equal(3); // 3 context terms + expect(document.index.get("data:body").reg.size).to.equal(3); + expect(document.index.get("data:body").map.size).to.equal(4); // 4 terms + expect(document.index.get("data:body").ctx.size).to.equal(1); // 1 keyword + expect(document.index.get("data:body").ctx.get("body").size).to.equal(3); // 3 context terms + + document.clear(); + + expect(document.reg.size).to.equal(0); + expect(document.tag.get("data:cat").size).to.equal(0); + expect(document.store.size).to.equal(0); + expect(document.cache.cache.size).to.equal(0); + expect(document.index.get("data:title").reg.size).to.equal(0); + expect(document.index.get("data:title").map.size).to.equal(0); + expect(document.index.get("data:title").ctx.size).to.equal(0); + expect(document.index.get("data:body").reg.size).to.equal(0); + expect(document.index.get("data:body").map.size).to.equal(0); + expect(document.index.get("data:body").ctx.size).to.equal(0); + }); }); diff --git a/test/encoder.js b/test/encoder.js index 949a760..77dd34b 100644 --- a/test/encoder.js +++ b/test/encoder.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); if(FlexSearch.default) FlexSearch = FlexSearch.default; @@ -32,45 +32,59 @@ describe("Encoder: Latin Charset", function(){ it("Should have been encoded properly: LatinDefault", function(){ const index = new Index({ encoder: Charset.LatinDefault }); - expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql(["björn", "phillipp", "mayer"]); + expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql( + ["björn", "phillipp", "mayer"] + ); }); - if(env !== "light"){ + if(!build_light){ it("Should have been encoded properly: LatinExact", function(){ const index = new Index({ encoder: Charset.LatinExact }); - expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql(["Björn-Phillipp", "Mayer"]); + expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql( + ["Björn-Phillipp", "Mayer"] + ); }); it("Should have been encoded properly: LatinSimple", function(){ const index = new Index({ encoder: Charset.LatinSimple }); - expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql(index.encoder.encode("bjorn/phillipp mayer")); + expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql( + index.encoder.encode("bjorn/phillipp mayer") + ); }); it("Should have been encoded properly: LatinBalance", function(){ const index = new Index({ encoder: Charset.LatinBalance }); - expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql(index.encoder.encode("bjorn philip mair")); + expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql( + index.encoder.encode("bjorn philip mair") + ); }); it("Should have been encoded properly: LatinAdvanced", function(){ const index = new Index({ encoder: Charset.LatinAdvanced }); - expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql(index.encoder.encode("bjoern filip mair")); + expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql( + index.encoder.encode("bjoern filip mair") + ); }); it("Should have been encoded properly: LatinExtra", function(){ const index = new Index({ encoder: Charset.LatinExtra }); - expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql(index.encoder.encode("bjorm filib mayr")); + expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql( + index.encoder.encode("bjorm filib mayr") + ); }); it("Should have been encoded properly: LatinSoundex", function(){ const index = new Index({ encoder: Charset.LatinSoundex }); - expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql(index.encoder.encode("bjoernsen philippo mayr")); + expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql( + index.encoder.encode("bjoernsen philippo mayr") + ); }); } @@ -206,12 +220,54 @@ describe("Filter", function(){ index.add(0, "Today in the morning."); expect(index.search("in the")).to.have.length(0); + + // extend + index.encoder.assign({ + filter: ["morning"] + }); + + index.add(0, "Today in the morning."); + expect(index.search("in the")).to.have.length(0); + expect(index.search("morning")).to.have.length(0); + expect(index.search("Today")).to.eql([0]); }); it("Should have been filtered properly (custom function)", function(){ const encoder = new Encoder({ - filter: ["in", "the"], + filter: function(word){ + return word.length > 3; + } + }); + const index = new Index({ + tokenize: "strict", + encoder: encoder + }); + + index.add(0, "Today in the morning."); + + expect(index.search("today in the morning.")).to.include(0); + expect(index.search("today morning")).to.include(0); + expect(index.search("in the")).to.have.length(0); + + encoder.assign({ + filter: function(word){ + return word.length > 3 && + word !== "today"; + } + }); + + index.add(0, "Today in the morning."); + + expect(index.search("today in the morning.")).to.include(0); + expect(index.search("today morning")).to.include(0); + expect(index.search("in the")).to.have.length(0); + expect(index.search("today")).to.have.length(0); + }); + + it("Should have been filtered properly (finalize)", function(){ + + const encoder = new Encoder({ finalize: function(word){ return word.filter(t => t.length > 3); } @@ -226,12 +282,23 @@ describe("Filter", function(){ expect(index.search("today in the morning.")).to.include(0); expect(index.search("today morning")).to.include(0); expect(index.search("in the")).to.have.length(0); + + // extend + encoder.assign({ + finalize: function(word){ + return word.filter(t => t.length > 5); + } + }); + + expect(index.search("today in the morning.")).to.include(0); + expect(index.search("today morning")).to.include(0); + expect(index.search("in the")).to.have.length(0); + expect(index.search("today")).to.have.length(0); }); it("Should have been filtered properly (minlength)", function(){ const encoder = new Encoder({ - filter: ["in", "the"], minlength: 4 }); const index = new Index({ @@ -266,7 +333,21 @@ describe("Stemmer", function(){ expect(index.search("Just a multinational colonization.")).to.include(0); expect(index.search("multinational colonization")).to.include(0); - expect(index.search("tional tion")).to.have.length(0); + expect(index.search("multination colonize")).to.include(0); + + // extend + encoder.assign({ + stemmer: new Map([ + ["licate", "e"] + ]) + }); + + index.add(0, "Just a duplicate multinational colonization."); + + expect(index.search("Just a multinational colonization.")).to.include(0); + expect(index.search("multinational colonization")).to.include(0); + expect(index.search("multination colonize")).to.include(0); + expect(index.search("dupe")).to.include(0); }); // it("Should have been stemmed properly (custom function)", function(){ @@ -336,3 +417,139 @@ describe("Stemmer", function(){ // expect(index.search("tional tion")).to.have.length(0); // }); }); + +describe("Mapper", function(){ + + it("Should have been applied custom Mapper properly", function(){ + + const index = new Index({ + tokenize: "forward", + encoder: new Encoder({ + numeric: false, + dedupe: false, + mapper: new Map([ + ["1", "a"], + ["2", "b"], + ["3", "c"], + ["4", "d"], + ["5", "d"], + ["6", "d"], + ["7", "e"], + ["8", "f"] + ]) + }) + }); + + index.add(0, "12345678"); + + expect(index.search("12345678")).to.eql([0]); + expect(index.search("abcd")).to.eql([0]); + expect(index.encoder.encode("12345678")).to.eql(["abcdddef"]); + + // extend + index.encoder.assign({ + mapper: new Map([ + ["1", "x"], + ["2", "y"], + ["3", "z"], + ["7", "x"], + ["8", "y"] + ]) + }); + + index.add(0, "12345678"); + + expect(index.search("12345678")).to.eql([0]); + expect(index.search("xyzd")).to.eql([0]); + expect(index.encoder.encode("12345678")).to.eql(["xyzdddxy"]); + }); +}); + +describe("Matcher", function(){ + + it("Should have been applied custom Matcher properly", function(){ + + const index = new Index({ + tokenize: "forward", + encoder: new Encoder({ + numeric: false, + dedupe: false, + matcher: new Map([ + ["1", "a"], + ["2", "b"], + ["3", "c"], + ["456", "d"], + ["7", "e"], + ["8", "f"] + ]) + }) + }); + + index.add(0, "12345678"); + + expect(index.search("12345678")).to.eql([0]); + expect(index.search("abcd")).to.eql([0]); + expect(index.encoder.encode("12345678")).to.eql(["abcdef"]); + + // extend + index.encoder.assign({ + matcher: new Map([ + ["1", "x"], + ["456", "ddd"], + ["8", "y"] + ]) + }); + + index.add(0, "12345678"); + + expect(index.search("12345678")).to.eql([0]); + expect(index.search("xbcd")).to.eql([0]); + expect(index.encoder.encode("12345678")).to.eql(["xbcdddey"]); + }); +}); + +describe("Replacer", function(){ + + it("Should have been applied custom Replacer properly", function(){ + + const index = new Index({ + tokenize: "forward", + encoder: new Encoder({ + numeric: false, + dedupe: false, + replacer: [ + "1", "a", + "2", "b", + "3", "c", + /[456]/g, "d", + "7", "e", + "8", "f" + ] + }) + }); + + index.add(0, "12345678"); + + expect(index.search("12345678")).to.eql([0]); + expect(index.search("abcd")).to.eql([0]); + expect(index.encoder.encode("12345678")).to.eql(["abcdddef"]); + + // extend + index.encoder.assign({ + replacer: [ + "a", "1", + "b", "2", + "c", "3", + "e", "7", + "f", "8" + ] + }); + + index.add(0, "12345678"); + + expect(index.search("12345678")).to.eql([0]); + expect(index.search("123d")).to.eql([0]); + expect(index.search("abcd")).to.eql([0]); + expect(index.encoder.encode("12345678")).to.eql(["123ddd78"]); + }); +}); diff --git a/test/highlight.js b/test/highlight.js new file mode 100644 index 0000000..55fec58 --- /dev/null +++ b/test/highlight.js @@ -0,0 +1,64 @@ +global.self = global; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; +import { expect } from "chai"; +let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); +if(FlexSearch.default) FlexSearch = FlexSearch.default; +if(FlexSearch.FlexSearch) FlexSearch = FlexSearch.FlexSearch; +const { Index, Document, Worker, Charset: _Charset, Encoder, Resolver } = FlexSearch; +const build_light = env && env.includes(".light"); +const build_compact = env && env.includes(".compact"); +const build_esm = !env || env.startsWith("module"); +const Charset = _Charset || (await import("../src/charset.js")).default; + +if(!build_light) describe("Result Highlighting", function(){ + + it("Should have been indexed properly (tag)", function(){ + + // some test data + const data = [{ + "id": 1, + "title": "Carmencita" + },{ + "id": 2, + "title": "Le clown et ses chiens" + }]; + + // create the document index + const index = new Document({ + document: { + store: true, + index: [{ + field: "title", + tokenize: "forward", + encoder: Charset.LatinBalance + }] + } + }); + + // add test data + for(let i = 0; i < data.length; i++){ + index.add(data[i]); + } + + // perform a query + const result = index.search({ + query: "karmen or clown or not found", + suggest: true, + // set enrich to true (required) + enrich: true, + // highlight template + // $1 is a placeholder for the matched partial + highlight: "$1" + }); + + expect(result[0].result).to.eql([{ + id: 1, + doc: data[0], + highlight: 'Carmencita' + },{ + id: 2, + doc: data[1], + highlight: 'Le clown et ses chiens' + }]); + }); +}); diff --git a/test/issues.js b/test/issues.js index 65e14b7..38ff929 100644 --- a/test/issues.js +++ b/test/issues.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); if(FlexSearch.default) FlexSearch = FlexSearch.default; diff --git a/test/keystore.js b/test/keystore.js new file mode 100644 index 0000000..b85ead8 --- /dev/null +++ b/test/keystore.js @@ -0,0 +1,99 @@ +global.self = global; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; +import { expect } from "chai"; +let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); +if(FlexSearch.default) FlexSearch = FlexSearch.default; +if(FlexSearch.FlexSearch) FlexSearch = FlexSearch.FlexSearch; +const { Index, Document, Worker, Charset: _Charset, Encoder, Resolver } = FlexSearch; +const build_light = env && env.includes(".light"); +const build_compact = env && env.includes(".compact"); +const build_esm = !env || env.startsWith("module"); +const build_es5 = !env || env.includes("es5"); +const Charset = _Charset || (await import("../src/charset.js")).default; + +if(!build_light && !build_compact) describe("Keystore", function(){ + + it("Should have applied the keystore properly", function(){ + + const index = new Index({ + fastupdate: true, + keystore: build_es5 ? 32 : 64, + context: true + }); + + for(let i = 0; i < 100; i++){ + index.add(i, "foo bar"); + } + + expect(index.map.size).to.equal(2); + expect(index.map.get("foo")[0].length).to.equal(100); + expect(index.ctx.get("foo").get("bar")[0].length).to.equal(100); + expect(index.reg.size).to.equal(100); + + for(let i = 0; i < 100; i++){ + index.add(i, "foobar"); + } + + expect(index.map.size).to.equal(3); + index.cleanup(); + expect(index.map.size).to.equal(1); + + expect(index.map.get("foo")).to.be.undefined; + expect(index.map.get("foobar")[0].length).to.equal(100); + expect(index.ctx.get("foo")).to.be.undefined; + expect(index.reg.size).to.equal(100); + + for(let i = 0; i < 50; i++){ + index.remove(i); + } + + expect(index.map.size).to.equal(1); + expect(index.map.get("foobar")[0].length).to.equal(50); + expect(index.reg.size).to.equal(50); + + index.clear(); + + expect(index.map.size).to.equal(0); + expect(index.ctx.size).to.equal(0); + expect(index.reg.size).to.equal(0); + }); + + // todo increase memory + it("Should have extended the default limit", function(){ + + const index = new Index({ + fastupdate: true, + //encode: str => str, + keystore: 16, + context: true + }); + + // this.slow(30000); + // this.timeout(60000); + + //const encoded = ["foo", "bar"]; + index.add(0, "foo bar"); + index.add(1, "foo bar"); + index.add(2, "foo bar"); + + let foo = index.map.get("foo"); + let bar = index.ctx.get("foo").get("bar"); + foo[0].length = 2**31 - 10; + bar[0].length = 2**31 - 10; + + for(let i = foo[0].length; i <= 2**31 + 9; i++){ + index.add(i, "foo bar"); + } + + expect(index.map.get("foo")[0].length).to.equal(2**31 + 10); + expect(index.ctx.get("foo").get("bar")[0].length).to.equal(2**31 + 10); + //expect(index.reg.size).to.equal(2**31 + 1); + expect(index.search("foo bar", 3)).to.eql([0, 1, 2]); + + index.clear(); + + expect(index.map.size).to.equal(0); + expect(index.ctx.size).to.equal(0); + expect(index.reg.size).to.equal(0); + }); +}); diff --git a/test/persistent.clickhouse.js b/test/persistent.clickhouse.js new file mode 100644 index 0000000..fa045bd --- /dev/null +++ b/test/persistent.clickhouse.js @@ -0,0 +1,20 @@ +global.self = global; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; +import { expect } from "chai"; +let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); +if(FlexSearch.default) FlexSearch = FlexSearch.default; +if(FlexSearch.FlexSearch) FlexSearch = FlexSearch.FlexSearch; +const { Index, Document, Worker, Charset: _Charset, Encoder, Resolver } = FlexSearch; +const build_light = env && env.includes(".light"); +const build_compact = env && env.includes(".compact"); +const build_esm = !env || env.startsWith("module"); +const Charset = _Charset || (await import("../src/charset.js")).default; + +import Clickhouse from "flexsearch/db/clickhouse"; +import tests from "./persistent.js"; + +if(!build_light && !build_compact){ + describe("Persistent: Clickhouse", function(){ + tests(Clickhouse, "Clickhouse"); + }); +} diff --git a/test/persistent.js b/test/persistent.js index 9b174e8..897434f 100644 --- a/test/persistent.js +++ b/test/persistent.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); if(FlexSearch.default) FlexSearch = FlexSearch.default; @@ -9,3 +9,347 @@ const build_light = env && env.includes(".light"); const build_compact = env && env.includes(".compact"); const build_esm = !env || env.startsWith("module"); const Charset = _Charset || (await import("../src/charset.js")).default; + +export default function(DB, DBClass){ + + const data = [{ + "tconst": "tt0000001", + "titleType": "short", + "primaryTitle": "Carmencita", + "originalTitle": "Carmencita", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Documentary", + "Short" + ] + },{ + "tconst": "tt0000002", + "titleType": "short", + "primaryTitle": "Le clown et ses chiens", + "originalTitle": "Le clown et ses chiens", + "isAdult": 0, + "startYear": "1892", + "endYear": "", + "runtimeMinutes": "5", + "genres": [ + "Animation", + "Short" + ] + }]; + + it("Should have created the instance properly", async function(){ + + // create DB instance with namespace + const db = new DB("test-store", { + type: "integer" + }); + + expect(db).to.respondTo("mount"); + expect(db).to.respondTo("close"); + expect(db).to.hasOwnProperty("id"); + expect(db).to.hasOwnProperty("field"); + expect(db).to.hasOwnProperty("db"); + + // create a simple index which can store id-content-pairs + let index = new Index({ + tokenize: "strict" + }); + + // mount database to the index + await index.mount(db); + expect(index.db).to.equal(db); + await index.destroy(); + expect(index.db).to.equal(db); + // mount database to the index + await db.mount(index); + expect(index.db).to.equal(db); + //await index.clear(); + + // some test data + const data = [ + 'cats abcd efgh ijkl mnop qrst uvwx cute', + 'cats abcd efgh ijkl mnop dogs cute', + 'cats abcd efgh ijkl mnop cute', + 'cats abcd efgh ijkl cute', + 'cats abcd efgh cute', + 'cats abcd cute', + 'cats cute' + ]; + + // add data to the index + for(let i = 0; i < data.length; i++){ + index.add(i, data[i]); + } + + expect(index.reg.size).to.equal(7); + expect(index.map.size).not.to.equal(0); + + await index.commit(); + + expect(index.reg.size).to.equal(0); + expect(index.map.size).to.equal(0); + + let result = await index.search("cats cute"); + expect(result).to.eql([6, 5, 4, 3, 2, 1, 0]); + + result = await index.search("cute cats"); + expect(result).to.eql([6, 5, 4, 3, 2, 1, 0]); + + result = await index.search("cute dogs cats"); + expect(result).to.eql([1]); + + // todo Redis Union did not sort by term count matches yet + if(DBClass !== "Redis"){ + result = await index.search("cute dogs cats", { suggest: true }); + expect(result).to.eql([1, 6, 5, 4, 3, 2, 0]); + } + + result = await index.search("cute cat"); + expect(result.length).to.equal(0); + + await index.destroy(); + await index.db.close(); + }); + + it("Should have created the instance properly (Context Search)", async function(){ + + // create DB instance with namespace + const db = new DB("test-store", { + type: "integer" + }); + + expect(db).to.respondTo("mount"); + expect(db).to.respondTo("close"); + expect(db).to.hasOwnProperty("id"); + expect(db).to.hasOwnProperty("field"); + expect(db).to.hasOwnProperty("db"); + + // create a simple index which can store id-content-pairs + let index = new Index({ + tokenize: "strict", + //context: true + }); + + // mount database to the index + await index.mount(db); + expect(index.db).to.equal(db); + //await index.destroy(); + //expect(index.db).to.equal(db); + // mount database to the index + //await db.mount(index); + //expect(index.db).to.equal(db); + //await index.clear(); + + // some test data + const data = [ + 'cats abcd efgh ijkl mnop qrst uvwx cute', + 'cats abcd efgh ijkl mnop dogs cute', + 'cats abcd efgh ijkl mnop cute', + 'cats abcd efgh ijkl cute', + 'cats abcd efgh cute', + 'cats abcd cute', + 'cats cute' + ]; + + // add data to the index + for(let i = 0; i < data.length; i++){ + index.add(i, data[i]); + } + + expect(index.reg.size).to.equal(7); + expect(index.map.size).not.to.equal(0); + + await index.commit(); + + expect(index.reg.size).to.equal(0); + expect(index.map.size).to.equal(0); + + let result = await index.search("cats cute"); + expect(result).to.eql([6, 5, 4, 3, 2, 1, 0]); + + result = await index.search("cute cats"); + expect(result).to.eql([6, 5, 4, 3, 2, 1, 0]); + + result = await index.search("cute dogs cats"); + expect(result).to.eql([1]); + + // todo Redis Union did not sort by term count matches yet + if(DBClass !== "Redis"){ + result = await index.search("cute dogs cats", { suggest: true }); + expect(result).to.eql([1, 6, 5, 4, 3, 2, 0]); + } + + result = await index.search("cute cat"); + expect(result.length).to.equal(0); + + await index.destroy(); + await index.db.close(); + }); + + it("Documents", async function(){ + + // create DB instance with namespace + const db = new DB("my-store"); + + // create the document index + const document = new Document({ + encoder: Charset.LatinBalance, + document: { + id: "tconst", + store: true, + index: [{ + field: "primaryTitle", + tokenize: "forward" + },{ + field: "originalTitle", + tokenize: "forward" + }], + tag: [{ + field: "startYear" + },{ + field: "genres" + }] + } + }); + + // mount database to the index + await document.mount(db); + expect(document.index.get("primaryTitle").db).to.be.instanceof(db.constructor); + expect(document.index.get("originalTitle").db).to.be.instanceof(db.constructor); + expect(document.index.get("startYear").db).to.be.instanceof(db.constructor); + expect(document.index.get("genres").db).to.be.instanceof(db.constructor); + + //await document.destroy(); + //expect(document.index.get("primaryTitle").db).to.be.instanceof(db.constructor); + // mount database to the index + //await db.mount(document); + //expect(document.index.get("primaryTitle").db).to.be.instanceof(db.constructor); + //document.clear(); + + // add test data + for(let i = 0; i < data.length; i++){ + document.add(data[i]); + } + + // transfer changes in bulk + await document.commit(); + + expect(document.index.get("primaryTitle").reg.size).to.equal(0); + expect(document.index.get("primaryTitle").map.size).to.equal(0); + expect(document.index.get("originalTitle").reg.size).to.equal(0); + expect(document.index.get("originalTitle").map.size).to.equal(0); + expect(document.index.get("startYear").reg.size).to.equal(0); + expect(document.index.get("startYear").map.size).to.equal(0); + expect(document.index.get("genres").reg.size).to.equal(0); + expect(document.index.get("genres").map.size).to.equal(0); + expect(document.reg.size).to.equal(0); + expect(document.store.size).to.equal(0); + expect(document.tag.size).to.equal(2); + expect(document.tag.get("startYear").size).to.equal(0); + expect(document.tag.get("genres").size).to.equal(0); + + expect(await document.contain(data[0]["tconst"])).to.equal(true); + + let result = await document.search({ + query: "karmen" + }); + + expect(result).to.eql([ + { field: 'primaryTitle', result: [ data[0]["tconst"] ] }, + { field: 'originalTitle', result: [ data[0]["tconst"] ] } + ]); + + result = await document.search({ + query: "karmen", + tag: { + "startYear": "1894", + "genres": [ + "Documentary", + "Short" + ] + }, + }); + + expect(result).to.eql([ + { field: 'primaryTitle', result: [ data[0]["tconst"] ] }, + { field: 'originalTitle', result: [ data[0]["tconst"] ] } + ]); + + result = await document.search({ + query: "karmen", + tag: { + "startYear": "1894", + "genres": [ + "Documentary", + "Short" + ] + }, + enrich: true + }); + + expect(result).to.eql([{ + field: "primaryTitle", + result: [{ + id: data[0]["tconst"], + doc: data[0], + }] + },{ + field: "originalTitle", + result: [{ + id: data[0]["tconst"], + doc: data[0], + }] + }]); + + result = await document.search({ + query: "karmen", + tag: { + "startYear": "1894", + "genres": [ + "Documentary", + "Short" + ] + }, + suggest: true, + enrich: true + }); + + expect(result).to.eql([ + { field: 'primaryTitle', result: [{ + id: data[0]["tconst"], + doc: data[0], + }] }, + { field: 'originalTitle', result: [{ + id: data[0]["tconst"], + doc: data[0], + }] } + ]); + + result = await document.search({ + query: "karmen or clown or nothing", + suggest: true, + enrich: true, + merge: true + }); + + expect(result).to.deep.contain({ + id: 'tt0000001', + doc: data[0], + field: [ 'primaryTitle', 'originalTitle' ] + }); + + expect(result).to.deep.contain({ + id: 'tt0000002', + doc: data[1], + field: [ 'primaryTitle', 'originalTitle' ] + }); + + for(const index of document.index.values()){ + index.destroy(); + index.db.close(); + } + }); +} \ No newline at end of file diff --git a/test/persistent.mongo.js b/test/persistent.mongo.js new file mode 100644 index 0000000..17530d1 --- /dev/null +++ b/test/persistent.mongo.js @@ -0,0 +1,20 @@ +global.self = global; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; +import { expect } from "chai"; +let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); +if(FlexSearch.default) FlexSearch = FlexSearch.default; +if(FlexSearch.FlexSearch) FlexSearch = FlexSearch.FlexSearch; +const { Index, Document, Worker, Charset: _Charset, Encoder, Resolver } = FlexSearch; +const build_light = env && env.includes(".light"); +const build_compact = env && env.includes(".compact"); +const build_esm = !env || env.startsWith("module"); +const Charset = _Charset || (await import("../src/charset.js")).default; + +import Mongo from "flexsearch/db/mongodb"; +import tests from "./persistent.js"; + +if(!build_light && !build_compact){ + describe("Persistent: Mongo", function(){ + tests(Mongo, "Mongo"); + }); +} diff --git a/test/persistent.postgres.js b/test/persistent.postgres.js new file mode 100644 index 0000000..0280ec5 --- /dev/null +++ b/test/persistent.postgres.js @@ -0,0 +1,20 @@ +global.self = global; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; +import { expect } from "chai"; +let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); +if(FlexSearch.default) FlexSearch = FlexSearch.default; +if(FlexSearch.FlexSearch) FlexSearch = FlexSearch.FlexSearch; +const { Index, Document, Worker, Charset: _Charset, Encoder, Resolver } = FlexSearch; +const build_light = env && env.includes(".light"); +const build_compact = env && env.includes(".compact"); +const build_esm = !env || env.startsWith("module"); +const Charset = _Charset || (await import("../src/charset.js")).default; + +import Postgres from "flexsearch/db/postgres"; +import tests from "./persistent.js"; + +if(!build_light && !build_compact){ + describe("Persistent: Postgres", function(){ + tests(Postgres, "Postgres"); + }); +} diff --git a/test/persistent.redis.js b/test/persistent.redis.js new file mode 100644 index 0000000..7d2cd3d --- /dev/null +++ b/test/persistent.redis.js @@ -0,0 +1,20 @@ +global.self = global; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; +import { expect } from "chai"; +let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); +if(FlexSearch.default) FlexSearch = FlexSearch.default; +if(FlexSearch.FlexSearch) FlexSearch = FlexSearch.FlexSearch; +const { Index, Document, Worker, Charset: _Charset, Encoder, Resolver } = FlexSearch; +const build_light = env && env.includes(".light"); +const build_compact = env && env.includes(".compact"); +const build_esm = !env || env.startsWith("module"); +const Charset = _Charset || (await import("../src/charset.js")).default; + +import Redis from "flexsearch/db/redis"; +import tests from "./persistent.js"; + +if(!build_light && !build_compact){ + describe("Persistent: Redis", function(){ + tests(Redis, "Redis"); + }); +} diff --git a/test/persistent.sqlite.js b/test/persistent.sqlite.js new file mode 100644 index 0000000..0e187b2 --- /dev/null +++ b/test/persistent.sqlite.js @@ -0,0 +1,20 @@ +global.self = global; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; +import { expect } from "chai"; +let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); +if(FlexSearch.default) FlexSearch = FlexSearch.default; +if(FlexSearch.FlexSearch) FlexSearch = FlexSearch.FlexSearch; +const { Index, Document, Worker, Charset: _Charset, Encoder, Resolver } = FlexSearch; +const build_light = env && env.includes(".light"); +const build_compact = env && env.includes(".compact"); +const build_esm = !env || env.startsWith("module"); +const Charset = _Charset || (await import("../src/charset.js")).default; + +import SQLite from "flexsearch/db/sqlite"; +import tests from "./persistent.js"; + +if(!build_light && !build_compact){ + describe("Persistent: SQLite", function(){ + tests(SQLite, "SQLite"); + }); +} diff --git a/test/resolver.js b/test/resolver.js index 23b0f6d..60cb59d 100644 --- a/test/resolver.js +++ b/test/resolver.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); if(FlexSearch.default) FlexSearch = FlexSearch.default; @@ -428,4 +428,119 @@ if(!build_light && !build_compact) describe("Resolver", function(){ [ 0, 2, 3, 4, 5, 6 ] ]); }); + + it("Should have been applied on Documents properly", function(){ + + // some test data + const data = [{ + "tconst": "tt0000001", + "titleType": "short", + "primaryTitle": "Carmencita", + "originalTitle": "Carmencita", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Documentary", + "Short" + ] + },{ + "tconst": "tt0000002", + "titleType": "short", + "primaryTitle": "Le clown et ses chiens", + "originalTitle": "Le clown et ses chiens", + "isAdult": 0, + "startYear": "1892", + "endYear": "", + "runtimeMinutes": "5", + "genres": [ + "Animation", + "Short" + ] + }]; + + // create the document index + const index = new Document({ + encoder: Charset.LatinBalance, + document: { + id: "tconst", + store: true, + index: [{ + field: "primaryTitle", + tokenize: "forward" + },{ + field: "originalTitle", + tokenize: "forward" + }], + tag: [{ + field: "startYear" + },{ + field: "genres" + }] + } + }); + + // add test data + for(let i = 0; i < data.length; i++){ + index.add(data[i]); + } + + // perform a query + enrich results + let result = new Resolver({ + index: index, + query: "karmen", + pluck: "primaryTitle", + //enrich: true, + }).or({ + index: index, + query: "clown", + pluck: "primaryTitle", + + }).and({ + index: index, + query: "karmen", + field: "primaryTitle", + suggest: true + }).not({ + index: index, + query: "clown", + pluck: "primaryTitle", + enrich: true, + resolve: true + }); + + expect(result).to.eql([{ + id: 'tt0000001', + doc: data[0] + }]); + + result = new Resolver({ + index: index, + query: "karmen", + pluck: "primaryTitle", + //enrich: true, + }).or({ + index: index, + query: "clown", + pluck: "primaryTitle", + + }).and({ + index: index, + query: "not found", + field: "primaryTitle", + suggest: true + }).resolve({ + enrich: true, + resolve: true + }); + + expect(result).to.eql([{ + id: 'tt0000001', + doc: data[0] + },{ + id: 'tt0000002', + doc: data[1] + }]); + }); }); diff --git a/test/scoring.js b/test/scoring.js index 6562878..3f2d4d5 100644 --- a/test/scoring.js +++ b/test/scoring.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); if(FlexSearch.default) FlexSearch = FlexSearch.default; diff --git a/test/serialize.js b/test/serialize.js index 9b174e8..230121f 100644 --- a/test/serialize.js +++ b/test/serialize.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); if(FlexSearch.default) FlexSearch = FlexSearch.default; @@ -8,4 +8,254 @@ const { Index, Document, Worker, Charset: _Charset, Encoder, Resolver } = FlexSe const build_light = env && env.includes(".light"); const build_compact = env && env.includes(".compact"); const build_esm = !env || env.startsWith("module"); +const build_es5 = !env || env.includes("es5"); const Charset = _Charset || (await import("../src/charset.js")).default; + +if(!build_light) describe("Export / Import", function(){ + + it("Should have been exported properly", function(){ + + let index = new Index({ + tokenize: "forward" + }); + + index.add(0, "foo bar foobar"); + index.add(1, "bar foo foobar"); + index.add(2, "foobar foo bar"); + + expect(index.reg.size).to.equal(3); + expect(index.map.size).to.equal(9); + expect(index.search("foobar")).to.eql([2, 0, 1]); + + const payload = new Map(); + index.export(function(key, value){ + payload.set(key, value); + }); + + expect(payload).to.eql(new Map([ + ['1.reg', '[0,1,2]'], + ['1.map', '[["f",[[0,2],[1]]],["fo",[[0,2],[1]]],["foo",[[0,2],[1]]],["b",[[1],[0],[2]]],["ba",[[1],[0],[2]]],["bar",[[1],[0],[2]]],["foob",[[2],null,[0,1]]],["fooba",[[2],null,[0,1]]],["foobar",[[2],null,[0,1]]]]'] + ])); + + index = new Index({ + tokenize: "forward" + }); + + for(const [key, value] of payload){ + index.import(key, value); + } + + expect(index.reg.size).to.equal(3); + expect(index.map.size).to.equal(9); + expect(index.search("foobar")).to.eql([2, 0, 1]); + }); + + it("Should have been exported properly (Context)", function(){ + + let index = new Index({ + context: true + }); + + index.add(0, "foo bar foobar"); + index.add(1, "bar foo foobar"); + index.add(2, "foobar foo bar"); + + expect(index.reg.size).to.equal(3); + expect(index.map.size).to.equal(3); + expect(index.ctx.size).to.equal(2); + expect(index.search("foobar")).to.eql([2, 0, 1]); + + const payload = new Map(); + index.export(function(key, value){ + payload.set(key, value); + }); + + expect(payload).to.eql(new Map([ + ['1.reg', '[0,1,2]'], + ['1.map', '[["foo",[[0],[1,2]]],["bar",[[1],[0],[2]]],["foobar",[[2],null,[0,1]]]]'], + ['1.ctx', '[["foo",[["bar",[[0,1],[2]]]]],["foobar",[["bar",[null,[0]]],["foo",[[2],[1]]]]]]'] + ])); + + index = new Index({ + context: true + }); + + for(const [key, value] of payload){ + index.import(key, value); + } + + expect(index.reg.size).to.equal(3); + expect(index.map.size).to.equal(3); + expect(index.ctx.size).to.equal(2); + expect(index.search("foobar")).to.eql([2, 0, 1]); + }); + + it("Should have been serialized properly (Fast-Boot)", function(){ + + let index = new Index({ + context: true, + keystore: build_es5 ? 32 : 64 + }); + + index.add(0, "foo bar foobar"); + index.add(1, "bar foo foobar"); + index.add(2, "foobar foo bar"); + + const fn_string = index.serialize(false); + const inject = new Function("index", fn_string); + + let index2 = new Index({ + context: true + }); + + inject(index2); + + expect(index2.reg.size).to.equal(3); + expect(index2.map.size).to.equal(3); + expect(index2.ctx.size).to.equal(2); + expect(normalize_map(index2.map)).to.eql(normalize_map(index.map)); + expect(normalize_ctx(index2.ctx)).to.eql(normalize_ctx(index.ctx)); + expect(Array.from(index2.reg.entries())).to.eql(Array.from(index.reg.entries())); + expect(index2.search("foobar")).to.eql([2, 0, 1]); + + let index3 = new Index({ + context: true + }); + + expect(index3.serialize()).to.equal("function inject(index){}"); + }); +}); + +if(!build_light) describe("Document Export/Import", function(){ + + const data = [{ + "tconst": "tt0000001", + "titleType": "short", + "primaryTitle": "Carmencita", + "originalTitle": "Carmencita", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Documentary", + "Short" + ] + },{ + "tconst": "tt0000002", + "titleType": "short", + "primaryTitle": "Le clown et ses chiens", + "originalTitle": "Le clown et ses chiens", + "isAdult": 0, + "startYear": "1892", + "endYear": "", + "runtimeMinutes": "5", + "genres": [ + "Animation", + "Short" + ] + }]; + + it("Should have been exported Document-Index properly", function(){ + + const config = { + document: { + id: "tconst", + store: true, + index: [{ + field: "primaryTitle", + tokenize: "forward", + encoder: Charset.LatinBalance + },{ + field: "originalTitle", + tokenize: "forward", + encoder: Charset.LatinBalance + }], + tag: [{ + field: "startYear" + },{ + field: "genres" + }] + } + }; + + let document = new Document(config); + + for(let i = 0; i < data.length; i++){ + document.add(data[i]); + } + + let result = document.search({ + query: "karmen", + tag: { + "startYear": "1894", + "genres": [ + "Documentary", + "Short" + ] + }, + suggest: true, + enrich: true + }); + + expect(result).to.eql([ + { field: 'primaryTitle', result: [{ + id: data[0]["tconst"], + doc: data[0], + }] }, + { field: 'originalTitle', result: [{ + id: data[0]["tconst"], + doc: data[0], + }] } + ]); + + const payload = new Map(); + document.export(function(key, data){ + payload.set(key, data); + }); + + document = new Document(config); + + for(const [key, value] of payload){ + document.import(key, value); + } + + result = document.search({ + query: "karmen", + tag: { + "startYear": "1894", + "genres": [ + "Documentary", + "Short" + ] + }, + suggest: true, + enrich: true + }); + + expect(result).to.eql([ + { field: 'primaryTitle', result: [{ + id: data[0]["tconst"], + doc: data[0], + }] }, + { field: 'originalTitle', result: [{ + id: data[0]["tconst"], + doc: data[0], + }] } + ]); + }); +}); + +function normalize_map(map){ + return Array.from(map.entries()).map(item => { + item[1].forEach((res, i) => res.length || delete item[1][i]); + return item; + }); +} + +function normalize_ctx(ctx){ + return Array.from(ctx.entries()).map(item => { + item[1] = normalize_map(item[1]); + return item; + }); +} \ No newline at end of file diff --git a/test/tokenize.js b/test/tokenize.js index 4b47715..1ca3748 100644 --- a/test/tokenize.js +++ b/test/tokenize.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); if(FlexSearch.default) FlexSearch = FlexSearch.default; diff --git a/test/worker.js b/test/worker.js index ac5e30d..9b36732 100644 --- a/test/worker.js +++ b/test/worker.js @@ -1,5 +1,5 @@ global.self = global; -const env = process.argv[3]; +const env = process.argv[3] && process.argv[3].startsWith("--") ? process.argv[4] : process.argv[3]; import { expect } from "chai"; let FlexSearch = await import(env ? "../dist/" + env + ".js" : "../src/bundle.js"); if(FlexSearch.default) FlexSearch = FlexSearch.default;