diff --git a/README.md b/README.md index f50ca65..0e5b15e 100644 --- a/README.md +++ b/README.md @@ -1352,11 +1352,11 @@ const index = new Document({ }); ``` -> `Worker`-Index and `Persistent`-Index does not support the fastupdate option, because of its nature. +> `Persistent`-Index does not support the `fastupdate` option, because of its nature. -When using fastupdate, the index won't fully clear up, when removing items. A barely rest of structure will still remain. It's not a memory issue, because this rest will take less than 1% of the index size. But instead the internal performance of key lookups will lose efficiency, because of not used (empty) keys in the index. +When using `fastupdate: true`, the index won't fully clear up, when removing items. A barely rest of structure will still remain. It's not a memory issue, because this rest will take less than 1% of the index size. But instead the internal performance of key lookups will lose efficiency, because of not used (empty) keys in the index. -In most cases this is not an issue. But you can trigger a `cleanup` task, which will find those empty index slots and remove them: +In most cases this is not an issue. But you can trigger a `index.cleanup()` task, which will find those empty index slots and remove them: ```js index.cleanup(); diff --git a/dist/db/clickhouse/db.cjs b/dist/db/clickhouse/index.cjs similarity index 99% rename from dist/db/clickhouse/db.cjs rename to dist/db/clickhouse/index.cjs index a77c981..9db90ef 100644 --- a/dist/db/clickhouse/db.cjs +++ b/dist/db/clickhouse/index.cjs @@ -72,7 +72,7 @@ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_]/g, ""); } -let DB; +let Index; /** * @constructor @@ -99,7 +99,7 @@ function ClickhouseDB(name, config = {}){ if(!this.type) throw new Error("Unknown type of ID '" + config.type + "'"); //this.trx = false; this.support_tag_search = true; - this.db = DB || (DB = config.db || null); + this.db = Index || (Index = config.db || null); Object.assign(defaults, config); config.database && (defaults.config.database = config.database); this.db && delete defaults.db; @@ -117,8 +117,8 @@ ClickhouseDB.prototype.mount = function(flexsearch){ ClickhouseDB.prototype.open = async function(){ if(!this.db) { - this.db = DB || ( - DB = new clickhouse.ClickHouse(defaults) + this.db = Index || ( + Index = new clickhouse.ClickHouse(defaults) ); } @@ -200,7 +200,7 @@ ClickhouseDB.prototype.open = async function(){ ClickhouseDB.prototype.close = function(){ //DB && DB.close(); - this.db = DB = null; + this.db = Index = null; return this; }; diff --git a/dist/db/indexeddb/db.cjs b/dist/db/indexeddb/index.cjs similarity index 98% rename from dist/db/indexeddb/db.cjs rename to dist/db/indexeddb/index.cjs index 5181ac7..9797b72 100644 --- a/dist/db/indexeddb/db.cjs +++ b/dist/db/indexeddb/index.cjs @@ -45,7 +45,7 @@ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); } -const DB = create_object(); +const Index = create_object(); /** * @param {string|PersistentOptions=} name @@ -92,8 +92,8 @@ IdxDB.prototype.open = function(){ // return this.db = new Promise(function(resolve, reject){ - DB[self.id] || (DB[self.id] = []); - DB[self.id].push(self.field); + Index[self.id] || (Index[self.id] = []); + Index[self.id].push(self.field); const req = IndexedDB.open(self.id, VERSION); @@ -109,8 +109,8 @@ IdxDB.prototype.open = function(){ // IndexedDB is such a poor contribution :( for(let i = 0, ref; i < fields.length; i++){ ref = fields[i]; - for(let j = 0, field; j < DB[self.id].length; j++){ - field = DB[self.id][j]; + for(let j = 0, field; j < Index[self.id].length; j++){ + field = Index[self.id][j]; db.objectStoreNames.contains(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")) || db.createObjectStore(ref + (ref !== "reg" ? (field ? ":" + field : "") : ""));//{ autoIncrement: true /*keyPath: "id"*/ } //.createIndex("idx", "ids", { multiEntry: true, unique: false }); @@ -195,8 +195,8 @@ IdxDB.prototype.clear = function(){ for(let i = 0, ref; i < fields.length; i++){ ref = fields[i]; - for(let j = 0, field; j < DB[this.id].length; j++){ - field = DB[this.id][j]; + for(let j = 0, field; j < Index[this.id].length; j++){ + field = Index[this.id][j]; stores.push(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")); } } diff --git a/dist/db/mongodb/db.cjs b/dist/db/mongodb/index.cjs similarity index 98% rename from dist/db/mongodb/db.cjs rename to dist/db/mongodb/index.cjs index 5e35ef2..75d134c 100644 --- a/dist/db/mongodb/db.cjs +++ b/dist/db/mongodb/index.cjs @@ -37,7 +37,7 @@ function sanitize(str) { } let CLIENT; -let DB = Object.create(null); +let Index = Object.create(null); /** * @constructor @@ -58,7 +58,7 @@ function MongoDB(name, config = {}){ this.id = "flexsearch" + (name ? "-" + sanitize(name) : ""); this.field = config.field ? "-" + sanitize(config.field) : ""; this.type = config.type || ""; - this.db = config.db || DB[this.id] || CLIENT || null; + this.db = config.db || Index[this.id] || CLIENT || null; this.trx = false; this.support_tag_search = true; Object.assign(defaults, config); @@ -106,7 +106,7 @@ async function createCollection(db, ref, field){ MongoDB.prototype.open = async function(){ if(!this.db){ - if(!(this.db = DB[this.id])){ + if(!(this.db = Index[this.id])){ if(!(this.db = CLIENT)){ let url = defaults.url; @@ -122,7 +122,7 @@ MongoDB.prototype.open = async function(){ } if(this.db.db){ - this.db = DB[this.id] = this.db.db(this.id); + this.db = Index[this.id] = this.db.db(this.id); } const collections = await this.db.listCollections().toArray(); @@ -146,7 +146,7 @@ MongoDB.prototype.open = async function(){ MongoDB.prototype.close = function(){ //CLIENT && CLIENT.close(); this.db = CLIENT = null; - DB[this.id] = null; + Index[this.id] = null; return this; }; diff --git a/dist/db/postgres/db.cjs b/dist/db/postgres/index.cjs similarity index 100% rename from dist/db/postgres/db.cjs rename to dist/db/postgres/index.cjs diff --git a/dist/db/redis/db.cjs b/dist/db/redis/index.cjs similarity index 100% rename from dist/db/redis/db.cjs rename to dist/db/redis/index.cjs diff --git a/dist/db/sqlite/db.cjs b/dist/db/sqlite/index.cjs similarity index 99% rename from dist/db/sqlite/db.cjs rename to dist/db/sqlite/index.cjs index 8299af0..db48e08 100644 --- a/dist/db/sqlite/db.cjs +++ b/dist/db/sqlite/index.cjs @@ -60,7 +60,7 @@ function sanitize(str) { // global transaction to keep track of database lock const TRX = Object.create(null); -const DB = Object.create(null); +const Index = Object.create(null); /** * @constructor @@ -86,7 +86,7 @@ function SqliteDB(name, config = {}){ ); this.field = config.field ? "_" + sanitize(config.field) : ""; this.support_tag_search = true; - this.db = config.db || DB[this.id] || null; + this.db = config.db || Index[this.id] || null; this.type = config.type ? types[config.type.toLowerCase()] : "string"; if(!this.type) throw new Error("Unknown type of ID '" + config.type + "'"); } @@ -103,7 +103,7 @@ SqliteDB.prototype.open = async function(){ if(!this.db){ - if(!(this.db = DB[this.id])){ + if(!(this.db = Index[this.id])){ let filepath = this.id; if(filepath !== ":memory:"){ @@ -115,7 +115,7 @@ SqliteDB.prototype.open = async function(){ } } - this.db = DB[this.id] = new sqlite3.Database(filepath); + this.db = Index[this.id] = new sqlite3.Database(filepath); } } @@ -225,7 +225,7 @@ SqliteDB.prototype.open = async function(){ SqliteDB.prototype.close = function(){ this.db && this.db.close(); this.db = null; - DB[this.id] = null; + Index[this.id] = null; TRX[this.id] = null; return this; }; diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index a488bc3..76c6f3f 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.143 (Bundle/Debug) + * FlexSearch.js v0.8.147 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -1342,7 +1342,7 @@ U.prototype.search = function(a, c, b, e) { } } } else { - for (let G = 0, L, tb; G < l.length; G += 2) { + for (let G = 0, L, sb; G < l.length; G += 2) { L = this.tag.get(l[G]); if (!L) { if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), r) { @@ -1351,7 +1351,7 @@ U.prototype.search = function(a, c, b, e) { return m ? d : new W(d); } } - if (tb = (L = L && L.get(l[G + 1])) && L.length) { + if (sb = (L = L && L.get(l[G + 1])) && L.length) { y++, w.push(L); } else if (!r) { return m ? d : new W(d); @@ -1696,10 +1696,11 @@ t.cleanup = function() { }; 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); + return c[0] && c[0].doc || null; + }) : this.store.get(a) || null; }; t.set = function(a, c) { + "object" === typeof a && (c = a, a = ba(c, this.key)); this.store.set(a, c); return this; }; @@ -1815,22 +1816,21 @@ X.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Wa = {normalize:!1, numeric:!1, split:/\s+/}; -const Xa = {normalize:!0}; -const Ya = {normalize:!0, dedupe:!0}; -const Za = 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 $a = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), ab = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const bb = {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 cb = {X:Wa, W:Xa, Y:Ya, LatinBalance:{normalize:!0, dedupe:!0, mapper:Za}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Za, matcher:$a, replacer:ab}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Za, replacer:ab.concat([/(?!^)[aeo]/g, ""]), matcher:$a}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Wa = {normalize:!1, numeric:!1}; +const Xa = {}; +const Ya = 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 Za = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), $a = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const ab = {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 bb = {X:Wa, W:Xa, Y:Xa, LatinBalance:{dedupe:!0, mapper:Ya}, LatinAdvanced:{dedupe:!0, mapper:Ya, matcher:Za, replacer:$a}, LatinExtra:{dedupe:!0, mapper:Ya, replacer:$a.concat([/(?!^)[aeo]/g, ""]), matcher:Za}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = bb[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = bb[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = ab[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = ab[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } -}}, LatinExact:Wa, LatinDefault:Xa, LatinSimple:Ya}; -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}}}; +}}, LatinExact:Wa, LatinDefault:Xa, LatinSimple:Xa}; +const cb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; N.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { @@ -1843,7 +1843,7 @@ N.prototype.add = function(a, c, b, e) { let r = c[this.rtl ? e - 1 - p : p]; var d = r.length; if (d && (m || !n[r])) { - var f = this.score ? this.score(c, r, p, null, 0) : eb(q, e, p), g = ""; + var f = this.score ? this.score(c, r, p, null, 0) : db(q, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { @@ -1851,8 +1851,8 @@ N.prototype.add = function(a, c, b, e) { for (f = d; f > u; f--) { g = r.substring(u, f); v = this.rtl ? d - 1 - u : u; - var k = this.score ? this.score(c, r, p, g, v) : eb(q, e, p, d, v); - fb(this, n, g, k, a, b); + var k = this.score ? this.score(c, r, p, g, v) : db(q, e, p, d, v); + eb(this, n, g, k, a, b); } } break; @@ -1862,25 +1862,25 @@ N.prototype.add = function(a, c, b, e) { if (1 < d) { for (k = d - 1; 0 < k; k--) { g = r[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(c, r, p, g, k) : eb(q, e, p, d, k); - fb(this, n, g, h, a, b); + var h = this.score ? this.score(c, r, p, g, k) : db(q, e, p, d, k); + eb(this, n, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += r[this.rtl ? d - 1 - k : k], fb(this, n, g, f, a, b); + g += r[this.rtl ? d - 1 - k : k], eb(this, n, g, f, a, b); } break; } default: - if (fb(this, n, r, f, a, b), m && 1 < e && p < e - 1) { + if (eb(this, n, r, f, a, b), m && 1 < e && p < e - 1) { for (d = B(), g = this.U, f = r, k = Math.min(m + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { if ((r = c[this.rtl ? e - 1 - p - h : p + h]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(c, f, p, r, h - 1) : eb(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && r > f; - fb(this, l, v ? f : r, u, a, b, v ? r : f); + const u = this.score ? this.score(c, f, p, r, h - 1) : db(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && r > f; + eb(this, l, v ? f : r, u, a, b, v ? r : f); } } } @@ -1892,10 +1892,10 @@ N.prototype.add = function(a, c, b, e) { c = ""; } } - this.db && (c || this.commit_task.push({del:a}), this.T && gb(this)); + this.db && (c || this.commit_task.push({del:a}), this.T && fb(this)); return this; }; -function fb(a, c, b, e, d, f, g) { +function eb(a, c, b, e, d, f, g) { let k = g ? a.ctx : a.map, h; if (!c[b] || g && !(h = c[b])[g]) { if (g ? (c = h || (c[b] = B()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { @@ -1913,7 +1913,7 @@ function fb(a, c, b, e, d, f, g) { } } } -function eb(a, c, b, e, d) { +function db(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; } ;N.prototype.search = function(a, c, b) { @@ -1924,11 +1924,11 @@ function eb(a, c, b, e, d) { d = p.length; c = c || (h ? 100 : 0); if (1 === d) { - return hb.call(this, p[0], "", c, k, h, q, l); + return gb.call(this, p[0], "", c, k, h, q, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return hb.call(this, p[0], p[1], c, k, h, q, l); + return gb.call(this, p[1], p[0], c, k, h, q, l); } let r = B(), u = 0, v; 1 < d && f && (v = p[0], u = 1); @@ -1942,8 +1942,8 @@ function eb(a, c, b, e, d) { for (let y, F; u < d; u++) { if ((F = p[u]) && !r[F]) { r[F] = 1; - y = await ib(w, F, v, 0, 0, !1, !1); - if (y = jb(y, e, g, m)) { + y = await hb(w, F, v, 0, 0, !1, !1); + if (y = ib(y, e, g, m)) { e = y; break; } @@ -1951,14 +1951,14 @@ function eb(a, c, b, e, d) { } g && v && u === d - 1 && !e.length && (m = w.resolution, v = "", u = -1, r = B()); } - return kb(e, m, c, k, g, n, h); + return jb(e, m, c, k, g, n, h); }(); } for (let w, y; u < d; u++) { if ((y = p[u]) && !r[y]) { r[y] = 1; - w = ib(this, y, v, 0, 0, !1, !1); - if (w = jb(w, e, g, m)) { + w = hb(this, y, v, 0, 0, !1, !1); + if (w = ib(w, e, g, m)) { e = w; break; } @@ -1966,9 +1966,9 @@ function eb(a, c, b, e, d) { } g && v && u === d - 1 && !e.length && (m = this.resolution, v = "", u = -1, r = B()); } - return kb(e, m, c, k, g, n, h); + return jb(e, m, c, k, g, n, h); }; -function kb(a, c, b, e, d, f, g) { +function jb(a, c, b, e, d, f, g) { let k = a.length, h = a; if (1 < k) { h = Fa(a, c, b, e, d, f, g); @@ -1977,13 +1977,13 @@ function kb(a, c, b, e, d, f, g) { } return g ? h : new W(h); } -function hb(a, c, b, e, d, f, g) { - a = ib(this, a, c, b, e, d, f, g); +function gb(a, c, b, e, d, f, g) { + a = hb(this, a, c, b, e, d, f, g); return this.db ? a.then(function(k) { return d ? k || [] : new W(k); }) : a && a.length ? d ? Ia.call(this, a, b, e) : new W(a) : d ? [] : new W(); } -function jb(a, c, b, e) { +function ib(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { @@ -2004,7 +2004,7 @@ function jb(a, c, b, e) { return d; } } -function ib(a, c, b, e, d, f, g, k) { +function hb(a, c, b, e, d, f, g, k) { let h; b && (h = a.bidirectional && c > b) && (h = b, b = c, c = h); if (a.db) { @@ -2028,15 +2028,15 @@ function ib(a, c, b, e, d, f, g, k) { } } } else { - lb(this.map, a), this.depth && lb(this.ctx, a); + kb(this.map, a), this.depth && kb(this.ctx, 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 && fb(this)); this.cache && this.cache.remove(a); return this; }; -function lb(a, c) { +function kb(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -2051,7 +2051,7 @@ function lb(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = lb(e[1], c); + const d = e[0], f = kb(e[1], c); f ? b += f : a.delete(d); } } @@ -2063,12 +2063,12 @@ function lb(a, c) { } if (a) { var b = E(a) ? a : a.preset; - b && (db[b] || console.warn("Preset not found: " + b), a = Object.assign({}, db[b], a)); + b && (cb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, cb[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? cb[a.encoder] : a.encode || a.encoder || Xa; + const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? bb[a.encoder] : a.encode || a.encoder || {}; this.encoder = d.encode ? d : "object" === typeof d ? new ja(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; @@ -2106,7 +2106,7 @@ t.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function gb(a) { +function fb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2130,7 +2130,7 @@ 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) { +function lb(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -2138,7 +2138,7 @@ function mb(a) { } } else { for (const b of a.entries()) { - const e = b[0], d = mb(b[1]); + const e = b[0], d = lb(b[1]); d ? c += d : a.delete(e); } } @@ -2148,8 +2148,8 @@ 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); + lb(this.map); + this.depth && lb(this.ctx); return this; }; t.searchCache = Va; @@ -2214,10 +2214,10 @@ t.serialize = function(a = !0) { return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; la(N.prototype); -const nb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), ob = ["map", "ctx", "tag", "reg", "cfg"], Y = B(); -function pb(a, c = {}) { +const mb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), nb = ["map", "ctx", "tag", "reg", "cfg"], Y = B(); +function ob(a, c = {}) { if (!this) { - return new pb(a, c); + return new ob(a, c); } "object" === typeof a && (c = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2228,7 +2228,7 @@ function pb(a, c = {}) { this.db = null; this.h = {}; } -t = pb.prototype; +t = ob.prototype; t.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -2244,11 +2244,11 @@ t.open = function() { navigator.storage && navigator.storage.persist(); Y[a.id] || (Y[a.id] = []); Y[a.id].push(a.field); - const c = nb.open(a.id, 1); + const c = mb.open(a.id, 1); c.onupgradeneeded = function() { const b = a.db = this.result; - for (let e = 0, d; e < ob.length; e++) { - d = ob[e]; + for (let e = 0, d; e < nb.length; e++) { + d = nb[e]; for (let f = 0, g; f < Y[a.id].length; f++) { g = Y[a.id][f], b.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || b.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); } @@ -2266,13 +2266,13 @@ t.close = function() { this.db = null; }; t.destroy = function() { - const a = nb.deleteDatabase(this.id); + const a = mb.deleteDatabase(this.id); return Z(a); }; t.clear = function() { const a = []; - for (let b = 0, e; b < ob.length; b++) { - e = ob[b]; + for (let b = 0, e; b < nb.length; b++) { + e = nb[b]; for (let d = 0, f; d < Y[this.id].length; d++) { f = Y[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); } @@ -2459,7 +2459,7 @@ t.commit = async function(a, c, b) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function qb(a, c, b) { +function pb(a, c, b) { const e = a.value; let d, f = 0; for (let g = 0, k; g < e.length; g++) { @@ -2488,17 +2488,17 @@ t.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && qb(b, a); + b && pb(b, a); }; }), this.transaction("ctx", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && qb(b, a); + b && pb(b, a); }; }), this.transaction("tag", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && qb(b, a, !0); + b && pb(b, a, !0); }; }), this.transaction("reg", "readwrite", function(c) { for (let b = 0; b < a.length; b++) { @@ -2517,9 +2517,9 @@ function Z(a, c) { a = null; }); } -;const rb = {Index:N, Charset:cb, Encoder:ja, Document:U, Worker:P, Resolver:W, IndexedDB:pb, Language:{}}, sb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; -let ub; -(ub = sb.define) && ub.amd ? ub([], function() { - return rb; -}) : "object" === typeof sb.exports ? sb.exports = rb : sb.FlexSearch = rb; +;const qb = {Index:N, Charset:bb, Encoder:ja, Document:U, Worker:P, Resolver:W, IndexedDB:ob, Language:{}}, rb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; +let tb; +(tb = rb.define) && tb.amd ? tb([], function() { + return qb; +}) : "object" === typeof rb.exports ? rb.exports = qb : rb.FlexSearch = qb; }(this||self)); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index c2f500d..2eed83a 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,19 +1,19 @@ /**! - * FlexSearch.js v0.8.143 (Bundle) + * FlexSearch.js v0.8.147 (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 t;function z(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 B(){return Object.create(null)}function E(a){return"string"===typeof a} -function I(a){return"object"===typeof a}function aa(a){const c=[];for(const b of a.keys())c.push(b);return c}function ba(a,c){if(E(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,da)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:z(b&&new Set(b),null,this.filter);this.dedupe=z(a.dedupe,!1,this.dedupe);this.matcher=z((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=z((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=z((b=a.stemmer)&&new Map(b), +this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:z(b&&new Set(b),null,this.filter);this.dedupe=z(a.dedupe,!1,this.dedupe);this.matcher=z((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=z((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=z((b=a.stemmer)&&new Map(b), null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,0,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=b=z(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;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,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);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,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&&K(this);return this}; t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);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=ia?a.normalize("NFKD").replace(ia,"").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&&b.push(g)}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 K(a){a.H=null;a.B.clear();a.G.clear()};let M,ja;async function ka(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":ja=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(ja),delete self.FlexSearch):M=new N(ja);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=ja.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await ja.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 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} @@ -31,26 +31,26 @@ if("includes"===e)return function(d){for(let f=0;fb||e?k.slice(e,b+e):k;else{if(ab||e)k=k.slice(e,b+e)}else{d=[];for(let m= 0,q;me)e-=q.length;else{if(q.length>b||e)q=q.slice(e,b+e),b-=q.length,e&&(e-=q.length);d.push(q);if(!b)break}k=1c?c?a.slice(b,b+c):a.slice(b):a,e?V.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?V.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,b,e,!1,this.h),e=0));return f?this.resolve(b,e,d):this};W.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:n,suggest:m}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,n,m)}return d?this.resolve(c,b,e):this}; -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;la.length)this.result=a[0];else{if(c=ca(a))return this.result=Fa(a,c,b,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.prototype.xor=function(){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,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;la.length)this.result=a[0];else{if(c=ba(a))return this.result=Fa(a,c,b,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.prototype.xor=function(){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 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;la.length)this.result=a[0];else return this.result=Na.call(this,a,b,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} function Na(a,c,b,e,d){const f=[],g=B();let h=0;for(let k=0,l;kb||e)a=a.slice(e,e+b);d&&(a=V.call(this,a));return a}}function V(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)}; -X.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};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:!1,numeric:!1,split:/\s+/};const Xa={normalize:!0};const Ya={normalize:!0,dedupe:!0};const Za=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 $a=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ab=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const bb={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 cb={X:Wa,W:Xa,Y:Ya,LatinBalance:{normalize:!0,dedupe:!0,mapper:Za},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Za,matcher:$a,replacer:ab},LatinExtra:{normalize:!0,dedupe:!0,mapper:Za,replacer:ab.concat([/(?!^)[aeo]/g,""]),matcher:$a},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bu;f--){g=r.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(c,r,p,g,v):eb(q,e,p,d,v); -fb(this,n,g,h,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1), -e,p,h-1,k-1),v=this.bidirectional&&r>f;fb(this,l,v?f:r,u,a,b,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else c=""}this.db&&(c||this.commit_task.push({del:a}),this.T&&gb(this));return this}; -function fb(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 R(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=c);k[e]=h=c}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} -function eb(a,c,b,e,d){return b&&1b)&&(k=b,b=c,c=k);if(a.db)return a.db.get(c,b,e,d,f,g,h);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};N.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 lb(this.map,a),this.depth&&lb(this.ctx,a);c||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,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eu;f--){g=r.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(c,r,p,g,v):db(q,e,p,d,v); +eb(this,n,g,h,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1), +e,p,h-1,k-1),v=this.bidirectional&&r>f;eb(this,l,v?f:r,u,a,b,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else c=""}this.db&&(c||this.commit_task.push({del:a}),this.T&&fb(this));return this}; +function eb(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 R(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=c);k[e]=h=c}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} +function db(a,c,b,e,d){return b&&1b)&&(k=b,b=c,c=k);if(a.db)return a.db.get(c,b,e,d,f,g,h);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};N.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 kb(this.map,a),this.depth&&kb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&fb(this));this.cache&&this.cache.remove(a);return this}; +function kb(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; -function mb(a){let c=0;if(a.constructor===Array)for(let b=0,e;b=n.length){e-=n.length;continue}const m=b?e+Math.min(n.length-e,b):n.length;for(let q=e;q=f.length)return[];if(!c&&!b)return f;f=f.slice(b,b+c);return e?d.enrich(f):f})}; t.enrich=function(a){"object"!==typeof a&&(a=[a]);const c=this.db.transaction("reg","readonly").objectStore("reg"),b=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){c&&c(this.result);c=null;b(this.result)};a.onerror=a.onblocked=e;a=null})};const rb={Index:N,Charset:cb,Encoder:J,Document:U,Worker:P,Resolver:W,IndexedDB:pb,Language:{}},tb="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let ub;(ub=tb.define)&&ub.amd?ub([],function(){return rb}):"object"===typeof tb.exports?tb.exports=rb:tb.FlexSearch=rb;}(this||self)); +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 pb(a,c,b){const e=a.value;let d,f=0;for(let g=0,h;g{a.onsuccess=a.oncomplete=function(){c&&c(this.result);c=null;b(this.result)};a.onerror=a.onblocked=e;a=null})};const qb={Index:N,Charset:bb,Encoder:ia,Document:U,Worker:P,Resolver:W,IndexedDB:ob,Language:{}},sb="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let tb;(tb=sb.define)&&tb.amd?tb([],function(){return qb}):"object"===typeof sb.exports?sb.exports=qb:sb.FlexSearch=qb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index 6aa96e8..d542f4c 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.143 (Bundle/Module/Debug) + * FlexSearch.js v0.8.147 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -1341,7 +1341,7 @@ U.prototype.search = function(a, c, b, e) { } } } else { - for (let G = 0, L, qb; G < l.length; G += 2) { + for (let G = 0, L, pb; G < l.length; G += 2) { L = this.tag.get(l[G]); if (!L) { if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), r) { @@ -1350,7 +1350,7 @@ U.prototype.search = function(a, c, b, e) { return m ? d : new W(d); } } - if (qb = (L = L && L.get(l[G + 1])) && L.length) { + if (pb = (L = L && L.get(l[G + 1])) && L.length) { y++, w.push(L); } else if (!r) { return m ? d : new W(d); @@ -1695,10 +1695,11 @@ t.cleanup = function() { }; 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); + return c[0] && c[0].doc || null; + }) : this.store.get(a) || null; }; t.set = function(a, c) { + "object" === typeof a && (c = a, a = ba(c, this.key)); this.store.set(a, c); return this; }; @@ -1814,22 +1815,21 @@ X.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Wa = {normalize:!1, numeric:!1, split:/\s+/}; -const Xa = {normalize:!0}; -const Ya = {normalize:!0, dedupe:!0}; -const Za = 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 $a = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), ab = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const bb = {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 cb = {X:Wa, W:Xa, Y:Ya, LatinBalance:{normalize:!0, dedupe:!0, mapper:Za}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Za, matcher:$a, replacer:ab}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Za, replacer:ab.concat([/(?!^)[aeo]/g, ""]), matcher:$a}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Wa = {normalize:!1, numeric:!1}; +const Xa = {}; +const Ya = 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 Za = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), $a = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const ab = {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 bb = {X:Wa, W:Xa, Y:Xa, LatinBalance:{dedupe:!0, mapper:Ya}, LatinAdvanced:{dedupe:!0, mapper:Ya, matcher:Za, replacer:$a}, LatinExtra:{dedupe:!0, mapper:Ya, replacer:$a.concat([/(?!^)[aeo]/g, ""]), matcher:Za}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = bb[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = bb[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = ab[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = ab[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } -}}, LatinExact:Wa, LatinDefault:Xa, LatinSimple:Ya}; -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}}}; +}}, LatinExact:Wa, LatinDefault:Xa, LatinSimple:Xa}; +const cb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; N.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { @@ -1842,7 +1842,7 @@ N.prototype.add = function(a, c, b, e) { let r = c[this.rtl ? e - 1 - p : p]; var d = r.length; if (d && (m || !n[r])) { - var f = this.score ? this.score(c, r, p, null, 0) : eb(q, e, p), g = ""; + var f = this.score ? this.score(c, r, p, null, 0) : db(q, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { @@ -1850,8 +1850,8 @@ N.prototype.add = function(a, c, b, e) { for (f = d; f > u; f--) { g = r.substring(u, f); v = this.rtl ? d - 1 - u : u; - var k = this.score ? this.score(c, r, p, g, v) : eb(q, e, p, d, v); - fb(this, n, g, k, a, b); + var k = this.score ? this.score(c, r, p, g, v) : db(q, e, p, d, v); + eb(this, n, g, k, a, b); } } break; @@ -1861,25 +1861,25 @@ N.prototype.add = function(a, c, b, e) { if (1 < d) { for (k = d - 1; 0 < k; k--) { g = r[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(c, r, p, g, k) : eb(q, e, p, d, k); - fb(this, n, g, h, a, b); + var h = this.score ? this.score(c, r, p, g, k) : db(q, e, p, d, k); + eb(this, n, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += r[this.rtl ? d - 1 - k : k], fb(this, n, g, f, a, b); + g += r[this.rtl ? d - 1 - k : k], eb(this, n, g, f, a, b); } break; } default: - if (fb(this, n, r, f, a, b), m && 1 < e && p < e - 1) { + if (eb(this, n, r, f, a, b), m && 1 < e && p < e - 1) { for (d = B(), g = this.U, f = r, k = Math.min(m + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { if ((r = c[this.rtl ? e - 1 - p - h : p + h]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(c, f, p, r, h - 1) : eb(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && r > f; - fb(this, l, v ? f : r, u, a, b, v ? r : f); + const u = this.score ? this.score(c, f, p, r, h - 1) : db(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && r > f; + eb(this, l, v ? f : r, u, a, b, v ? r : f); } } } @@ -1891,10 +1891,10 @@ N.prototype.add = function(a, c, b, e) { c = ""; } } - this.db && (c || this.commit_task.push({del:a}), this.T && gb(this)); + this.db && (c || this.commit_task.push({del:a}), this.T && fb(this)); return this; }; -function fb(a, c, b, e, d, f, g) { +function eb(a, c, b, e, d, f, g) { let k = g ? a.ctx : a.map, h; if (!c[b] || g && !(h = c[b])[g]) { if (g ? (c = h || (c[b] = B()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { @@ -1912,7 +1912,7 @@ function fb(a, c, b, e, d, f, g) { } } } -function eb(a, c, b, e, d) { +function db(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; } ;N.prototype.search = function(a, c, b) { @@ -1923,11 +1923,11 @@ function eb(a, c, b, e, d) { d = p.length; c = c || (h ? 100 : 0); if (1 === d) { - return hb.call(this, p[0], "", c, k, h, q, l); + return gb.call(this, p[0], "", c, k, h, q, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return hb.call(this, p[0], p[1], c, k, h, q, l); + return gb.call(this, p[1], p[0], c, k, h, q, l); } let r = B(), u = 0, v; 1 < d && f && (v = p[0], u = 1); @@ -1941,8 +1941,8 @@ function eb(a, c, b, e, d) { for (let y, F; u < d; u++) { if ((F = p[u]) && !r[F]) { r[F] = 1; - y = await ib(w, F, v, 0, 0, !1, !1); - if (y = jb(y, e, g, m)) { + y = await hb(w, F, v, 0, 0, !1, !1); + if (y = ib(y, e, g, m)) { e = y; break; } @@ -1950,14 +1950,14 @@ function eb(a, c, b, e, d) { } g && v && u === d - 1 && !e.length && (m = w.resolution, v = "", u = -1, r = B()); } - return kb(e, m, c, k, g, n, h); + return jb(e, m, c, k, g, n, h); }(); } for (let w, y; u < d; u++) { if ((y = p[u]) && !r[y]) { r[y] = 1; - w = ib(this, y, v, 0, 0, !1, !1); - if (w = jb(w, e, g, m)) { + w = hb(this, y, v, 0, 0, !1, !1); + if (w = ib(w, e, g, m)) { e = w; break; } @@ -1965,9 +1965,9 @@ function eb(a, c, b, e, d) { } g && v && u === d - 1 && !e.length && (m = this.resolution, v = "", u = -1, r = B()); } - return kb(e, m, c, k, g, n, h); + return jb(e, m, c, k, g, n, h); }; -function kb(a, c, b, e, d, f, g) { +function jb(a, c, b, e, d, f, g) { let k = a.length, h = a; if (1 < k) { h = Fa(a, c, b, e, d, f, g); @@ -1976,13 +1976,13 @@ function kb(a, c, b, e, d, f, g) { } return g ? h : new W(h); } -function hb(a, c, b, e, d, f, g) { - a = ib(this, a, c, b, e, d, f, g); +function gb(a, c, b, e, d, f, g) { + a = hb(this, a, c, b, e, d, f, g); return this.db ? a.then(function(k) { return d ? k || [] : new W(k); }) : a && a.length ? d ? Ia.call(this, a, b, e) : new W(a) : d ? [] : new W(); } -function jb(a, c, b, e) { +function ib(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { @@ -2003,7 +2003,7 @@ function jb(a, c, b, e) { return d; } } -function ib(a, c, b, e, d, f, g, k) { +function hb(a, c, b, e, d, f, g, k) { let h; b && (h = a.bidirectional && c > b) && (h = b, b = c, c = h); if (a.db) { @@ -2027,15 +2027,15 @@ function ib(a, c, b, e, d, f, g, k) { } } } else { - lb(this.map, a), this.depth && lb(this.ctx, a); + kb(this.map, a), this.depth && kb(this.ctx, 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 && fb(this)); this.cache && this.cache.remove(a); return this; }; -function lb(a, c) { +function kb(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -2050,7 +2050,7 @@ function lb(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = lb(e[1], c); + const d = e[0], f = kb(e[1], c); f ? b += f : a.delete(d); } } @@ -2062,12 +2062,12 @@ function lb(a, c) { } if (a) { var b = E(a) ? a : a.preset; - b && (db[b] || console.warn("Preset not found: " + b), a = Object.assign({}, db[b], a)); + b && (cb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, cb[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? cb[a.encoder] : a.encode || a.encoder || Xa; + const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? bb[a.encoder] : a.encode || a.encoder || {}; this.encoder = d.encode ? d : "object" === typeof d ? new ja(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; @@ -2105,7 +2105,7 @@ t.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function gb(a) { +function fb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2129,7 +2129,7 @@ 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) { +function lb(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -2137,7 +2137,7 @@ function mb(a) { } } else { for (const b of a.entries()) { - const e = b[0], d = mb(b[1]); + const e = b[0], d = lb(b[1]); d ? c += d : a.delete(e); } } @@ -2147,8 +2147,8 @@ 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); + lb(this.map); + this.depth && lb(this.ctx); return this; }; t.searchCache = Va; @@ -2213,10 +2213,10 @@ t.serialize = function(a = !0) { return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; la(N.prototype); -const nb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), ob = ["map", "ctx", "tag", "reg", "cfg"], Y = B(); -function pb(a, c = {}) { +const mb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), nb = ["map", "ctx", "tag", "reg", "cfg"], Y = B(); +function ob(a, c = {}) { if (!this) { - return new pb(a, c); + return new ob(a, c); } "object" === typeof a && (c = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2227,7 +2227,7 @@ function pb(a, c = {}) { this.db = null; this.h = {}; } -t = pb.prototype; +t = ob.prototype; t.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -2243,11 +2243,11 @@ t.open = function() { navigator.storage && navigator.storage.persist(); Y[a.id] || (Y[a.id] = []); Y[a.id].push(a.field); - const c = nb.open(a.id, 1); + const c = mb.open(a.id, 1); c.onupgradeneeded = function() { const b = a.db = this.result; - for (let e = 0, d; e < ob.length; e++) { - d = ob[e]; + for (let e = 0, d; e < nb.length; e++) { + d = nb[e]; for (let f = 0, g; f < Y[a.id].length; f++) { g = Y[a.id][f], b.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || b.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); } @@ -2265,13 +2265,13 @@ t.close = function() { this.db = null; }; t.destroy = function() { - const a = nb.deleteDatabase(this.id); + const a = mb.deleteDatabase(this.id); return Z(a); }; t.clear = function() { const a = []; - for (let b = 0, e; b < ob.length; b++) { - e = ob[b]; + for (let b = 0, e; b < nb.length; b++) { + e = nb[b]; for (let d = 0, f; d < Y[this.id].length; d++) { f = Y[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); } @@ -2458,7 +2458,7 @@ t.commit = async function(a, c, b) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function rb(a, c, b) { +function qb(a, c, b) { const e = a.value; let d, f = 0; for (let g = 0, k; g < e.length; g++) { @@ -2487,17 +2487,17 @@ t.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && rb(b, a); + b && qb(b, a); }; }), this.transaction("ctx", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && rb(b, a); + b && qb(b, a); }; }), this.transaction("tag", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && rb(b, a, !0); + b && qb(b, a, !0); }; }), this.transaction("reg", "readwrite", function(c) { for (let b = 0; b < a.length; b++) { @@ -2516,6 +2516,6 @@ function Z(a, c) { a = null; }); } -;export default {Index:N, Charset:cb, Encoder:ja, Document:U, Worker:P, Resolver:W, IndexedDB:pb, Language:{}}; +;export default {Index:N, Charset:bb, Encoder:ja, Document:U, Worker:P, Resolver:W, IndexedDB:ob, Language:{}}; -export const Index=N;export const Charset=cb;export const Encoder=ja;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=pb;export const Language={}; \ No newline at end of file +export const Index=N;export const Charset=bb;export const Encoder=ja;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=ob;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 6b2f473..5367920 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,19 +1,19 @@ /**! - * FlexSearch.js v0.8.143 (Bundle/Module) + * FlexSearch.js v0.8.147 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ var t;function z(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 B(){return Object.create(null)}function E(a){return"string"===typeof a} -function I(a){return"object"===typeof a}function aa(a){const c=[];for(const b of a.keys())c.push(b);return c}function ba(a,c){if(E(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,da)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:z(b&&new Set(b),null,this.filter);this.dedupe=z(a.dedupe,!1,this.dedupe);this.matcher=z((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=z((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=z((b=a.stemmer)&&new Map(b), +this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:z(b&&new Set(b),null,this.filter);this.dedupe=z(a.dedupe,!1,this.dedupe);this.matcher=z((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=z((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=z((b=a.stemmer)&&new Map(b), null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,0,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=b=z(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;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,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);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,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&&K(this);return this}; t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);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=ia?a.normalize("NFKD").replace(ia,"").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&&b.push(g)}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 K(a){a.H=null;a.B.clear();a.G.clear()};let M,ja;async function ka(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":ja=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(ja),delete self.FlexSearch):M=new N(ja);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=ja.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await ja.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 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} @@ -31,26 +31,26 @@ if("includes"===e)return function(d){for(let f=0;fb||e?k.slice(e,b+e):k;else{if(ab||e)k=k.slice(e,b+e)}else{d=[];for(let m= 0,q;me)e-=q.length;else{if(q.length>b||e)q=q.slice(e,b+e),b-=q.length,e&&(e-=q.length);d.push(q);if(!b)break}k=1c?c?a.slice(b,b+c):a.slice(b):a,e?V.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?V.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,b,e,!1,this.h),e=0));return f?this.resolve(b,e,d):this};W.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:n,suggest:m}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,n,m)}return d?this.resolve(c,b,e):this}; -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;la.length)this.result=a[0];else{if(c=ca(a))return this.result=Fa(a,c,b,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.prototype.xor=function(){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,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;la.length)this.result=a[0];else{if(c=ba(a))return this.result=Fa(a,c,b,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.prototype.xor=function(){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 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;la.length)this.result=a[0];else return this.result=Na.call(this,a,b,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} function Na(a,c,b,e,d){const f=[],g=B();let h=0;for(let k=0,l;kb||e)a=a.slice(e,e+b);d&&(a=V.call(this,a));return a}}function V(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)}; -X.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};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:!1,numeric:!1,split:/\s+/};const Xa={normalize:!0};const Ya={normalize:!0,dedupe:!0};const Za=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 $a=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ab=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const bb={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 cb={X:Wa,W:Xa,Y:Ya,LatinBalance:{normalize:!0,dedupe:!0,mapper:Za},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Za,matcher:$a,replacer:ab},LatinExtra:{normalize:!0,dedupe:!0,mapper:Za,replacer:ab.concat([/(?!^)[aeo]/g,""]),matcher:$a},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bu;f--){g=r.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(c,r,p,g,v):eb(q,e,p,d,v); -fb(this,n,g,h,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1), -e,p,h-1,k-1),v=this.bidirectional&&r>f;fb(this,l,v?f:r,u,a,b,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else c=""}this.db&&(c||this.commit_task.push({del:a}),this.T&&gb(this));return this}; -function fb(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 R(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=c);k[e]=h=c}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} -function eb(a,c,b,e,d){return b&&1b)&&(k=b,b=c,c=k);if(a.db)return a.db.get(c,b,e,d,f,g,h);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};N.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 lb(this.map,a),this.depth&&lb(this.ctx,a);c||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,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eu;f--){g=r.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(c,r,p,g,v):db(q,e,p,d,v); +eb(this,n,g,h,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1), +e,p,h-1,k-1),v=this.bidirectional&&r>f;eb(this,l,v?f:r,u,a,b,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else c=""}this.db&&(c||this.commit_task.push({del:a}),this.T&&fb(this));return this}; +function eb(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 R(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=c);k[e]=h=c}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} +function db(a,c,b,e,d){return b&&1b)&&(k=b,b=c,c=k);if(a.db)return a.db.get(c,b,e,d,f,g,h);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};N.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 kb(this.map,a),this.depth&&kb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&fb(this));this.cache&&this.cache.remove(a);return this}; +function kb(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; -function mb(a){let c=0;if(a.constructor===Array)for(let b=0,e;b=n.length){e-=n.length;continue}const m=b?e+Math.min(n.length-e,b):n.length;for(let q=e;q=f.length)return[];if(!c&&!b)return f;f=f.slice(b,b+c);return e?d.enrich(f):f})}; t.enrich=function(a){"object"!==typeof a&&(a=[a]);const c=this.db.transaction("reg","readonly").objectStore("reg"),b=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){c&&c(this.result);c=null;b(this.result)};a.onerror=a.onblocked=e;a=null})};export default {Index:N,Charset:cb,Encoder:J,Document:U,Worker:P,Resolver:W,IndexedDB:qb,Language:{}}; -export const Index=N;export const Charset=cb;export const Encoder=J;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=qb;export const Language={}; \ No newline at end of file +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 qb(a,c,b){const e=a.value;let d,f=0;for(let g=0,h;g{a.onsuccess=a.oncomplete=function(){c&&c(this.result);c=null;b(this.result)};a.onerror=a.onblocked=e;a=null})};export default {Index:N,Charset:bb,Encoder:ia,Document:U,Worker:P,Resolver:W,IndexedDB:pb,Language:{}}; +export const Index=N;export const Charset=bb;export const Encoder=ia;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=pb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 68ac6e1..7efd114 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.143 (Bundle/Debug) + * FlexSearch.js v0.8.147 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -1038,7 +1038,7 @@ V.prototype.search = function(a, c, b, e) { if (l && F) { w = []; z = 0; - for (let G = 0, H, $a; G < l.length; G += 2) { + for (let G = 0, H, Za; G < l.length; G += 2) { H = this.tag.get(l[G]); if (!H) { if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), k) { @@ -1047,7 +1047,7 @@ V.prototype.search = function(a, c, b, e) { return n ? d : new X(d); } } - if ($a = (H = H && H.get(l[G + 1])) && H.length) { + if (Za = (H = H && H.get(l[G + 1])) && H.length) { z++, w.push(H); } else if (!k) { return n ? d : new X(d); @@ -1289,9 +1289,10 @@ x.cleanup = function() { return this; }; x.get = function(a) { - return this.store.get(a); + return this.store.get(a) || null; }; x.set = function(a, c) { + "object" === typeof a && (c = a, a = J(c, this.key)); this.store.set(a, c); return this; }; @@ -1397,22 +1398,21 @@ Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ma = {normalize:!1, numeric:!1, split:/\s+/}; -const Na = {normalize:!0}; -const Oa = {normalize:!0, dedupe:!0}; -const Pa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); -const Qa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ra = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const Sa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -var Ta = {W:Ma, V:Na, X:Oa, LatinBalance:{normalize:!0, dedupe:!0, mapper:Pa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Pa, matcher:Qa, replacer:Ra}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Pa, replacer:Ra.concat([/(?!^)[aeo]/g, ""]), matcher:Qa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Ma = {normalize:!1, numeric:!1}; +const Na = {}; +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}; +var Sa = {W:Ma, V:Na, X:Na, LatinBalance:{dedupe:!0, mapper:Oa}, LatinAdvanced:{dedupe:!0, mapper:Oa, matcher:Pa, replacer:Qa}, LatinExtra:{dedupe:!0, mapper:Oa, replacer:Qa.concat([/(?!^)[aeo]/g, ""]), matcher:Pa}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = Sa[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Sa[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; } -}}, LatinExact:Ma, LatinDefault:Na, LatinSimple:Oa}; -const Ua = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +}}, LatinExact:Ma, LatinDefault:Na, LatinSimple:Na}; +const Ta = {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)) { @@ -1425,7 +1425,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) : Va(r, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : Ua(r, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { @@ -1433,7 +1433,7 @@ O.prototype.add = function(a, c, b, e) { for (f = d; f > t; f--) { g = q.substring(t, f); u = this.rtl ? d - 1 - t : t; - var k = this.score ? this.score(c, q, p, g, u) : Va(r, e, p, d, u); + var k = this.score ? this.score(c, q, p, g, u) : Ua(r, e, p, d, u); Z(this, m, g, k, a, b); } } @@ -1444,7 +1444,7 @@ O.prototype.add = function(a, c, b, e) { 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) : Va(r, e, p, d, k); + var h = this.score ? this.score(c, q, p, g, k) : Ua(r, e, p, d, k); Z(this, m, g, h, a, b); } g = ""; @@ -1461,7 +1461,7 @@ O.prototype.add = function(a, c, b, e) { 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]) { d[q] = 1; - const t = this.score ? this.score(c, f, p, q, h - 1) : Va(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; + const t = this.score ? this.score(c, f, p, q, h - 1) : Ua(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; Z(this, l, u ? f : q, t, a, b, u ? q : f); } } @@ -1480,7 +1480,7 @@ function Z(a, c, b, e, d, f, 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 Va(a, c, b, e, d) { +function Ua(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) { @@ -1501,11 +1501,11 @@ function Va(a, c, b, e, d) { b = a.length; c = c || (k ? 100 : 0); if (1 === b) { - return g = c, (c = Wa(this, a[0], "")) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Va(this, a[0], "")) && c.length ? za.call(this, c, g, d) : []; } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return g = c, (c = Wa(this, a[0], a[1])) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Va(this, a[1], a[0])) && c.length ? za.call(this, c, g, d) : []; } k = C(); let l = 0; @@ -1517,7 +1517,7 @@ function Va(a, c, b, e, d) { for (let q, t; l < b; l++) { if ((t = a[l]) && !k[t]) { k[t] = 1; - q = Wa(this, t, m); + q = Va(this, t, m); a: { f = q; var n = e, r = g, p = h; @@ -1563,7 +1563,7 @@ function Va(a, c, b, e, d) { } return g; }; -function Wa(a, c, b) { +function Va(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); @@ -1584,14 +1584,14 @@ function Wa(a, c, b) { } } } else { - Xa(this.map, a), this.depth && Xa(this.ctx, a); + Wa(this.map, a), this.depth && Wa(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Xa(a, c) { +function Wa(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1606,7 +1606,7 @@ function Xa(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = Xa(e[1], c); + const d = e[0], f = Wa(e[1], c); f ? b += f : a.delete(d); } } @@ -1618,12 +1618,12 @@ function Xa(a, c) { } if (a) { var b = D(a) ? a : a.preset; - b && (Ua[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ua[b], a)); + b && (Ta[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ta[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Ta[a.encoder] : a.encode || a.encoder || Na; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Sa[a.encoder] : a.encode || a.encoder || {}; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; @@ -1659,7 +1659,7 @@ x.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function Ya(a) { +function Xa(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1667,7 +1667,7 @@ function Ya(a) { } } else { for (const b of a.entries()) { - const e = b[0], d = Ya(b[1]); + const e = b[0], d = Xa(b[1]); d ? c += d : a.delete(e); } } @@ -1677,8 +1677,8 @@ x.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Ya(this.map); - this.depth && Ya(this.ctx); + Xa(this.map); + this.depth && Xa(this.ctx); return this; }; x.searchCache = La; @@ -1744,9 +1744,9 @@ x.serialize = function(a = !0) { }; ia(O.prototype); C(); -const Za = {Index:O, Charset:Ta, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, ab = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; -let bb; -(bb = ab.define) && bb.amd ? bb([], function() { - return Za; -}) : "object" === typeof ab.exports ? ab.exports = Za : ab.FlexSearch = Za; +const Ya = {Index:O, Charset:Sa, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, $a = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; +let ab; +(ab = $a.define) && ab.amd ? ab([], function() { + return Ya; +}) : "object" === typeof $a.exports ? $a.exports = Ya : $a.FlexSearch = Ya; }(this||self)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 78b156e..40cc71a 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.143 (Bundle) + * FlexSearch.js v0.8.147 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -37,7 +37,7 @@ function Ea(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hthis.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:!1,numeric:!1,split:/\s+/};const Na={normalize:!0};const Oa={normalize:!0,dedupe:!0};const Pa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Qa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Ra=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Sa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Ta={W:Ma,V:Na,X:Oa,LatinBalance:{normalize:!0,dedupe:!0,mapper:Pa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Pa,matcher:Qa,replacer:Ra},LatinExtra:{normalize:!0,dedupe:!0,mapper:Pa,replacer:Ra.concat([/(?!^)[aeo]/g,""]),matcher:Qa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bt;f--){g=q.substring(t,f);u=this.rtl?d-1-t:t;var k=this.score?this.score(c,q,p,g,u):Va(r,e,p,d,u); -Z(this,m,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),e,p, -k-1,h-1),u=this.bidirectional&&q>f;Z(this,l,u?f:q,t,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 Va(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 Xa(this.map,a),this.depth&&Xa(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Xa(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;et;f--){g=q.substring(t,f);u=this.rtl?d-1-t:t;var k=this.score?this.score(c,q,p,g,u):Ua(r,e,p,d,u); +Z(this,m,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),e,p, +k-1,h-1),u=this.bidirectional&&q>f;Z(this,l,u?f:q,t,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 Ua(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 Wa(this.map,a),this.depth&&Wa(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Wa(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function Ya(a){let c=0;if(a.constructor===Array)for(let b=0,e;bb.add(a,c)):this.add(a,c)};function Xa(a){let c=0;if(a.constructor===Array)for(let b=0,e;b t; f--) { g = q.substring(t, f); u = this.rtl ? d - 1 - t : t; - var k = this.score ? this.score(c, q, p, g, u) : Va(r, e, p, d, u); + var k = this.score ? this.score(c, q, p, g, u) : Ua(r, e, p, d, u); Z(this, m, g, k, a, b); } } @@ -1443,7 +1443,7 @@ O.prototype.add = function(a, c, b, e) { 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) : Va(r, e, p, d, k); + var h = this.score ? this.score(c, q, p, g, k) : Ua(r, e, p, d, k); Z(this, m, g, h, a, b); } g = ""; @@ -1460,7 +1460,7 @@ O.prototype.add = function(a, c, b, e) { 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]) { d[q] = 1; - const t = this.score ? this.score(c, f, p, q, h - 1) : Va(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; + const t = this.score ? this.score(c, f, p, q, h - 1) : Ua(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; Z(this, l, u ? f : q, t, a, b, u ? q : f); } } @@ -1479,7 +1479,7 @@ function Z(a, c, b, e, d, f, 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 Va(a, c, b, e, d) { +function Ua(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) { @@ -1500,11 +1500,11 @@ function Va(a, c, b, e, d) { b = a.length; c = c || (k ? 100 : 0); if (1 === b) { - return g = c, (c = Wa(this, a[0], "")) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Va(this, a[0], "")) && c.length ? za.call(this, c, g, d) : []; } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return g = c, (c = Wa(this, a[0], a[1])) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Va(this, a[1], a[0])) && c.length ? za.call(this, c, g, d) : []; } k = C(); let l = 0; @@ -1516,7 +1516,7 @@ function Va(a, c, b, e, d) { for (let q, t; l < b; l++) { if ((t = a[l]) && !k[t]) { k[t] = 1; - q = Wa(this, t, m); + q = Va(this, t, m); a: { f = q; var n = e, r = g, p = h; @@ -1562,7 +1562,7 @@ function Va(a, c, b, e, d) { } return g; }; -function Wa(a, c, b) { +function Va(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); @@ -1583,14 +1583,14 @@ function Wa(a, c, b) { } } } else { - Ya(this.map, a), this.depth && Ya(this.ctx, a); + Xa(this.map, a), this.depth && Xa(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Ya(a, c) { +function Xa(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1605,7 +1605,7 @@ function Ya(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = Ya(e[1], c); + const d = e[0], f = Xa(e[1], c); f ? b += f : a.delete(d); } } @@ -1617,12 +1617,12 @@ function Ya(a, c) { } if (a) { var b = D(a) ? a : a.preset; - b && (Ua[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ua[b], a)); + b && (Ta[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ta[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Ta[a.encoder] : a.encode || a.encoder || Na; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Sa[a.encoder] : a.encode || a.encoder || {}; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; @@ -1658,7 +1658,7 @@ x.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function Za(a) { +function Ya(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1666,7 +1666,7 @@ function Za(a) { } } else { for (const b of a.entries()) { - const e = b[0], d = Za(b[1]); + const e = b[0], d = Ya(b[1]); d ? c += d : a.delete(e); } } @@ -1676,8 +1676,8 @@ x.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Za(this.map); - this.depth && Za(this.ctx); + Ya(this.map); + this.depth && Ya(this.ctx); return this; }; x.searchCache = La; @@ -1743,6 +1743,6 @@ x.serialize = function(a = !0) { }; ia(O.prototype); C(); -export default {Index:O, Charset:Ta, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +export default {Index:O, Charset:Sa, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=O;export const Charset=Ta;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=Sa;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 6a02807..bda1152 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.143 (Bundle) + * FlexSearch.js v0.8.147 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -37,7 +37,7 @@ function Ea(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hthis.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:!1,numeric:!1,split:/\s+/};const Na={normalize:!0};const Oa={normalize:!0,dedupe:!0};const Pa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Qa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Ra=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Sa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Ta={W:Ma,V:Na,X:Oa,LatinBalance:{normalize:!0,dedupe:!0,mapper:Pa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Pa,matcher:Qa,replacer:Ra},LatinExtra:{normalize:!0,dedupe:!0,mapper:Pa,replacer:Ra.concat([/(?!^)[aeo]/g,""]),matcher:Qa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bt;f--){g=q.substring(t,f);u=this.rtl?d-1-t:t;var k=this.score?this.score(c,q,p,g,u):Va(r,e,p,d,u); -Z(this,m,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),e,p, -k-1,h-1),u=this.bidirectional&&q>f;Z(this,l,u?f:q,t,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 Va(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 Ya(this.map,a),this.depth&&Ya(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Ya(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;et;f--){g=q.substring(t,f);u=this.rtl?d-1-t:t;var k=this.score?this.score(c,q,p,g,u):Ua(r,e,p,d,u); +Z(this,m,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),e,p, +k-1,h-1),u=this.bidirectional&&q>f;Z(this,l,u?f:q,t,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 Ua(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 Xa(this.map,a),this.depth&&Xa(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Xa(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function Za(a){let c=0;if(a.constructor===Array)for(let b=0,e;bb.add(a,c)):this.add(a,c)};function Ya(a){let c=0;if(a.constructor===Array)for(let b=0,e;b n; t--) { - p = l.substring(n, t), 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); + p = l.substring(n, t), q = this.rtl ? m - 1 - n : n, q = this.score ? this.score(b, l, k, p, q) : Ib(h, d, k, m, q), Jb(this, g, p, q, a, c); } } break; @@ -2775,24 +2775,24 @@ P.prototype.add = function(a, b, c, d) { case "reverse": if (1 < m) { 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) : Jb(h, d, k, m, t), Kb(this, g, p, q, a, c); + p = l[this.rtl ? m - 1 - t : t] + p, q = this.score ? this.score(b, l, k, p, t) : Ib(h, d, k, m, t), Jb(this, g, p, q, a, c); } p = ""; } case "forward": if (1 < m) { for (t = 0; t < m; t++) { - p += l[this.rtl ? m - 1 - t : t], Kb(this, g, p, n, a, c); + p += l[this.rtl ? m - 1 - t : t], Jb(this, g, p, n, a, c); } break; } default: - if (Kb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { + if (Jb(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 w = this.score ? this.score(b, n, k, l, q - 1) : Jb(p + (d / 2 > p ? 0 : 1), d, k, t - 1, q - 1), r = this.bidirectional && l > n; - Kb(this, e, r ? n : l, w, a, c, r ? l : n); + var w = this.score ? this.score(b, n, k, l, q - 1) : Ib(p + (d / 2 > p ? 0 : 1), d, k, t - 1, q - 1), r = this.bidirectional && l > n; + Jb(this, e, r ? n : l, w, a, c, r ? l : n); } } } @@ -2804,10 +2804,10 @@ P.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 && Kb(this)); return this; }; -function Kb(a, b, c, d, e, g, f) { +function Jb(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)) { @@ -2825,7 +2825,7 @@ function Kb(a, b, c, d, e, g, f) { } } } -function Jb(a, b, c, d, e) { +function Ib(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; } ;P.prototype.search = function(a, b, c) { @@ -2848,11 +2848,11 @@ function Jb(a, b, c, d, e) { var q = p.length; b = b || (g ? 100 : 0); if (1 === q) { - return Mb.call(this, p[0], "", b, e, g, k, n); + return Lb.call(this, p[0], "", b, e, g, k, n); } f = this.depth && !1 !== f; if (2 === q && f && !h) { - return Mb.call(this, p[0], p[1], b, e, g, k, n); + return Lb.call(this, p[1], p[0], b, e, g, k, n); } var t = J(), w = 0; if (1 < q && f) { @@ -2882,10 +2882,10 @@ function Jb(a, b, c, d, e) { break; } t[v] = 1; - return E(y, Nb(A, v, r, 0, 0, !1, !1), 6); + return E(y, Mb(A, v, r, 0, 0, !1, !1), 6); case 6: z = y.D; - if (z = Ob(z, d, h, m)) { + if (z = Nb(z, d, h, m)) { d = z; y.h = 4; break; @@ -2897,7 +2897,7 @@ function Jb(a, b, c, d, e) { y.h = 2; break; case 4: - return y.return(Pb(d, m, b, e, h, l, g)); + return y.return(Ob(d, m, b, e, h, l, g)); } }); }(); @@ -2905,8 +2905,8 @@ function Jb(a, b, c, d, e) { for (c = a = void 0; w < q; w++) { if ((c = p[w]) && !t[c]) { t[c] = 1; - a = Nb(this, c, r, 0, 0, !1, !1); - if (a = Ob(a, d, h, m)) { + a = Mb(this, c, r, 0, 0, !1, !1); + if (a = Nb(a, d, h, m)) { d = a; break; } @@ -2914,9 +2914,9 @@ function Jb(a, b, c, d, e) { } h && r && w === q - 1 && !d.length && (m = this.resolution, r = "", w = -1, t = J()); } - return Pb(d, m, b, e, h, l, g); + return Ob(d, m, b, e, h, l, g); }; -function Pb(a, b, c, d, e, g, f) { +function Ob(a, b, c, d, e, g, f) { var h = a.length, k = a; if (1 < h) { k = ib(a, b, c, d, e, g, f); @@ -2925,13 +2925,13 @@ function Pb(a, b, c, d, e, g, f) { } return f ? k : new Y(k); } -function Mb(a, b, c, d, e, g, f) { - a = Nb(this, a, b, c, d, e, g, f); +function Lb(a, b, c, d, e, g, f) { + a = Mb(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(); } -function Ob(a, b, c, d) { +function Nb(a, b, c, d) { var e = []; if (a && a.length) { if (a.length <= d) { @@ -2952,7 +2952,7 @@ function Ob(a, b, c, d) { return e; } } -function Nb(a, b, c, d, e, g, f, h) { +function Mb(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) { @@ -2976,15 +2976,15 @@ function Nb(a, b, c, d, e, g, f, h) { } } } else { - Qb(this.map, a), this.depth && Qb(this.ctx, a); + Pb(this.map, a), this.depth && Pb(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 && Kb(this)); this.cache && this.cache.remove(a); return this; }; -function Qb(a, b) { +function Pb(a, b) { var c = 0; if (a.constructor === Array) { for (var d = 0, e = void 0, g; d < a.length; d++) { @@ -2999,7 +2999,7 @@ function Qb(a, b) { } } else { for (d = x(a.entries()), e = d.next(); !e.done; e = d.next()) { - g = e.value, e = g[0], (g = Qb(g[1], b)) ? c += g : a.delete(e); + g = e.value, e = g[0], (g = Pb(g[1], b)) ? c += g : a.delete(e); } } return c; @@ -3010,12 +3010,12 @@ function Qb(a, b) { } 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 && (Hb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Hb[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 || Bb; + var d = !0 === c ? {depth:1} : c || {}, e = K(a.encoder) ? Gb[a.encoder] : a.encode || a.encoder || {}; this.encoder = e.encode ? e : "object" === typeof e ? new Fa(e) : {encode:e}; this.resolution = a.resolution || 9; this.tokenize = c = (c = a.tokenize) && "default" !== c && "exact" !== c && c || "strict"; @@ -3053,7 +3053,7 @@ u.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Lb(a) { +function Kb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -3079,7 +3079,7 @@ u.update = function(a, b) { return c.add(a, b); }) : this.add(a, b); }; -function Rb(a) { +function Qb(a) { var b = 0; if (a.constructor === Array) { for (var c = 0, d = void 0; c < a.length; c++) { @@ -3089,7 +3089,7 @@ function Rb(a) { 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 = Qb(e[1])) ? b += e : a.delete(d); } } return b; @@ -3098,8 +3098,8 @@ 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); + Qb(this.map); + this.depth && Qb(this.ctx); return this; }; u.searchCache = zb; @@ -3169,11 +3169,11 @@ u.serialize = function(a) { return a ? "function inject(index){" + b + c + d + "}" : b + c + d; }; Ia(P.prototype); -var Sb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Tb = ["map", "ctx", "tag", "reg", "cfg"], Ub = J(); -function Vb(a, b) { +var Rb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Sb = ["map", "ctx", "tag", "reg", "cfg"], Tb = J(); +function Ub(a, b) { b = void 0 === b ? {} : b; if (!this) { - return new Vb(a, b); + return new Ub(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -3184,7 +3184,7 @@ function Vb(a, b) { this.db = null; this.h = {}; } -u = Vb.prototype; +u = Ub.prototype; u.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -3198,14 +3198,14 @@ u.open = function() { } var a = this; navigator.storage && navigator.storage.persist(); - Ub[a.id] || (Ub[a.id] = []); - Ub[a.id].push(a.field); - var b = Sb.open(a.id, 1); + Tb[a.id] || (Tb[a.id] = []); + Tb[a.id].push(a.field); + var b = Rb.open(a.id, 1); b.onupgradeneeded = function() { - for (var c = a.db = this.result, d = 0, e; d < Tb.length; d++) { - e = Tb[d]; - for (var g = 0, f; g < Ub[a.id].length; g++) { - f = Ub[a.id][g], c.objectStoreNames.contains(e + ("reg" !== e ? f ? ":" + f : "" : "")) || c.createObjectStore(e + ("reg" !== e ? f ? ":" + f : "" : "")); + for (var c = a.db = this.result, d = 0, e; d < Sb.length; d++) { + e = Sb[d]; + for (var g = 0, f; g < Tb[a.id].length; g++) { + f = Tb[a.id][g], c.objectStoreNames.contains(e + ("reg" !== e ? f ? ":" + f : "" : "")) || c.createObjectStore(e + ("reg" !== e ? f ? ":" + f : "" : "")); } } }; @@ -3221,14 +3221,14 @@ u.close = function() { this.db = null; }; u.destroy = function() { - var a = Sb.deleteDatabase(this.id); + var a = Rb.deleteDatabase(this.id); return Z(a); }; u.clear = function() { - for (var a = [], b = 0, c; b < Tb.length; b++) { - c = Tb[b]; - for (var d = 0, e; d < Ub[this.id].length; d++) { - e = Ub[this.id][d], a.push(c + ("reg" !== c ? e ? ":" + e : "" : "")); + for (var a = [], b = 0, c; b < Sb.length; b++) { + c = Sb[b]; + for (var d = 0, e; d < Tb[this.id].length; d++) { + e = Tb[this.id][d], a.push(c + ("reg" !== c ? e ? ":" + e : "" : "")); } } b = this.db.transaction(a, "readwrite"); @@ -3475,7 +3475,7 @@ u.commit = function(a, b, c) { } }); }; -function Wb(a, b, c) { +function Vb(a, b, c) { for (var d = a.value, e, g = 0, f = 0, h; f < d.length; f++) { if (h = c ? d : d[f]) { for (var k = 0, l; k < b.length; k++) { @@ -3502,17 +3502,17 @@ u.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Wb(c, a); + c && Vb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Wb(c, a); + c && Vb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Wb(c, a, !0); + c && Vb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3531,8 +3531,8 @@ function Z(a, b) { a = null; }); } -;var Xb = {Index:P, Charset:Hb, Encoder:Fa, Document:W, Worker:Ra, Resolver:Y, IndexedDB:Vb, Language:{}}, Yb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self, ac; -(ac = Yb.define) && ac.amd ? ac([], function() { - return Xb; -}) : "object" === typeof Yb.exports ? Yb.exports = Xb : Yb.FlexSearch = Xb; +;var Wb = {Index:P, Charset:Gb, Encoder:Fa, Document:W, Worker:Ra, Resolver:Y, IndexedDB:Ub, Language:{}}, Xb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self, $b; +($b = Xb.define) && $b.amd ? $b([], function() { + return Wb; +}) : "object" === typeof Xb.exports ? Xb.exports = Wb : Xb.FlexSearch = Wb; }(this||self)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index af30cb8..812a25c 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.143 (ES5) + * FlexSearch.js v0.8.147 (ES5) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -49,10 +49,10 @@ d=[],e=this.split||""===this.split?a.split(this.split):a,g=0,f=void 0,h=void 0;g 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&&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 Ga,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),Ga=new self.FlexSearch.Index(Ha),delete self.FlexSearch):Ga=new O(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(Ga,d[0]),9)}g=d&&Ga[b].apply(Ga,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,Ga.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} +5;break}return E(h,g,7);case 7:g=h.D;h.h=5;break;case 9:f=h.D,Ga.import(d[0],f);case 5:postMessage("search"===b?{id:c,msg:g}:{id:c}),h.h=0}})};function Ja(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 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);1E9c||d)a=a.slice(d,d+c);e&&(a=W.call(this,a));return a}}function W(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)}; -Y.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};Y.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)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};var Ab={normalize:!1,numeric:!1,split:/\s+/};var Bb={normalize:!0};var Cb={normalize:!0,dedupe:!0};var Db=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 Eb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Fb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Gb={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 Hb={na:Ab,ma:Bb,oa:Cb,LatinBalance:{normalize:!0,dedupe:!0,mapper:Db},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Db,matcher:Eb,replacer:Fb},LatinExtra:{normalize:!0,dedupe:!0,mapper:Db,replacer:Fb.concat([/(?!^)[aeo]/g,""]),matcher:Eb},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 "bidirectional":case "reverse":if(1p?0:1),d,k,r-1,q-1),t=this.bidirectional&& -l>n;Kb(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&&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 S(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 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};O.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var 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)}; +Y.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};Y.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)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};var Ab={normalize:!1,numeric:!1};var Bb={};var Cb=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 Db=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Eb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Fb={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 Gb={na:Ab,ma:Bb,oa:Bb,LatinBalance:{dedupe:!0,mapper:Cb},LatinAdvanced:{dedupe:!0,mapper:Cb,matcher:Db,replacer:Eb},LatinExtra:{dedupe:!0,mapper:Cb,replacer:Eb.concat([/(?!^)[aeo]/g,""]),matcher:Db},LatinSoundex:{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):Ib(h,d,k,m,q),Jb(this,g,p, +q,a,c);break}case "bidirectional":case "reverse":if(1p?0:1),d,k,r-1,q-1),t=this.bidirectional&& +l>n;Jb(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&&Kb(this));return this}; +function Jb(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 S(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 Ib(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};O.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else Pb(this.map,a),this.depth&&Pb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Kb(this));this.cache&&this.cache.remove(a);return this}; +function Pb(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 q; g--) { e = l.substring(q, g); t = this.rtl ? c - 1 - q : q; - var h = this.score ? this.score(d, l, p, e, t) : L(C, f, p, c, t); - M(this, m, e, h, a, b); + var h = this.score ? this.score(d, l, p, e, t) : K(C, f, p, c, t); + L(this, m, e, h, a, b); } } break; @@ -298,25 +297,25 @@ K.prototype.add = function(a, d, b, f) { if (1 < c) { for (h = c - 1; 0 < h; h--) { e = l[this.rtl ? c - 1 - h : h] + e; - var k = this.score ? this.score(d, l, p, e, h) : L(C, f, p, c, h); - M(this, m, e, k, a, b); + var k = this.score ? this.score(d, l, p, e, h) : K(C, f, p, c, h); + L(this, m, e, k, a, b); } e = ""; } case "forward": if (1 < c) { for (h = 0; h < c; h++) { - e += l[this.rtl ? c - 1 - h : h], M(this, m, e, g, a, b); + e += l[this.rtl ? c - 1 - h : h], L(this, m, e, g, a, b); } break; } default: - if (M(this, m, l, g, a, b), v && 1 < f && p < f - 1) { + if (L(this, m, l, g, a, b), v && 1 < f && p < f - 1) { for (c = w(), e = this.v, g = l, h = Math.min(v + 1, this.rtl ? p + 1 : f - p), c[g] = 1, k = 1; k < h; k++) { if ((l = d[this.rtl ? f - 1 - p - k : p + k]) && !c[l]) { c[l] = 1; - const q = this.score ? this.score(d, g, p, l, k - 1) : L(e + (f / 2 > e ? 0 : 1), f, p, h - 1, k - 1), t = this.bidirectional && l > g; - M(this, n, t ? g : l, q, a, b, t ? l : g); + const q = this.score ? this.score(d, g, p, l, k - 1) : K(e + (f / 2 > e ? 0 : 1), f, p, h - 1, k - 1), t = this.bidirectional && l > g; + L(this, n, t ? g : l, q, a, b, t ? l : g); } } } @@ -328,16 +327,16 @@ K.prototype.add = function(a, d, b, f) { } return this; }; -function M(a, d, b, f, c, g, e) { +function L(a, d, b, f, c, g, e) { let h = e ? a.ctx : a.map, k; if (!d[b] || e && !(k = d[b])[e]) { e ? (d = k || (d[b] = w()), d[e] = 1, (k = h.get(e)) ? h = k : h.set(e, h = new Map())) : d[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[f] || (h[f] = []), g && h.includes(c) || (h.push(c), a.fastupdate && ((d = a.reg.get(c)) ? d.push(h) : a.reg.set(c, [h]))); } } -function L(a, d, b, f, c) { +function K(a, d, b, f, c) { return b && 1 < a ? d + (f || 0) <= a ? b + (c || 0) : (a - 1) / (d + (f || 0)) * (b + (c || 0)) + 1 | 0 : 0; } -;K.prototype.search = function(a, d, b) { +;J.prototype.search = function(a, d, b) { b || (d || "object" !== typeof a ? "object" === typeof d && (b = d, d = 0) : (b = a, a = "")); var f = [], c = 0; if (b) { @@ -355,11 +354,11 @@ function L(a, d, b, f, c) { b = a.length; d = d || (h ? 100 : 0); if (1 === b) { - return e = c, (c = N(this, a[0], "")) && c.length ? H.call(this, c, d, e) : []; + return e = c, (c = M(this, a[0], "")) && c.length ? H.call(this, c, d, e) : []; } g = this.depth && !1 !== g; if (2 === b && g && !e) { - return e = c, (c = N(this, a[0], a[1])) && c.length ? H.call(this, c, d, e) : []; + return e = c, (c = M(this, a[1], a[0])) && c.length ? H.call(this, c, d, e) : []; } h = w(); var n = 0; @@ -371,7 +370,7 @@ function L(a, d, b, f, c) { for (let l, q; n < b; n++) { if ((q = a[n]) && !h[q]) { h[q] = 1; - l = N(this, q, m); + l = M(this, q, m); a: { g = l; var v = f, C = e, p = k; @@ -472,13 +471,13 @@ function L(a, d, b, f, c) { } return d; }; -function N(a, d, b) { +function M(a, d, b) { let f; b && (f = a.bidirectional && d > b) && (f = b, b = d, d = f); a = b ? (a = a.ctx.get(b)) && a.get(d) : a.map.get(d); return a; } -;K.prototype.remove = function(a, d) { +;J.prototype.remove = function(a, d) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { @@ -493,13 +492,13 @@ function N(a, d, b) { } } } else { - O(this.map, a), this.depth && O(this.ctx, a); + N(this.map, a), this.depth && N(this.ctx, a); } d || this.reg.delete(a); } return this; }; -function O(a, d) { +function N(a, d) { let b = 0; if (a.constructor === Array) { for (let f = 0, c, g; f < a.length; f++) { @@ -514,24 +513,24 @@ function O(a, d) { } } else { for (let f of a.entries()) { - const c = f[0], g = O(f[1], d); + const c = f[0], g = N(f[1], d); g ? b += g : a.delete(c); } } return b; } -;function K(a, d) { - if (!this || this.constructor !== K) { - return new K(a); +;function J(a, d) { + if (!this || this.constructor !== J) { + return new J(a); } if (a) { var b = "string" === typeof a ? a : a.preset; - b && (J[b] || console.warn("Preset not found: " + b), a = Object.assign({}, J[b], a)); + b && (I[b] || console.warn("Preset not found: " + b), a = Object.assign({}, I[b], a)); } else { a = {}; } b = a.context; - const f = !0 === b ? {depth:1} : b || {}, c = a.encode || a.encoder || I; + const f = !0 === b ? {depth:1} : b || {}, c = a.encode || a.encoder || {}; this.encoder = c.encode ? c : "object" === typeof c ? new F(c) : {encode:c}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; @@ -546,7 +545,7 @@ function O(a, d) { this.v = f.resolution || 3; this.rtl = c.rtl || a.rtl || !1; } -r = K.prototype; +r = J.prototype; r.clear = function() { this.map.clear(); this.ctx.clear(); @@ -563,7 +562,7 @@ r.update = function(a, d) { const b = this, f = this.remove(a); return f && f.then ? f.then(() => b.add(a, d)) : this.add(a, d); }; -function P(a) { +function O(a) { let d = 0; if (a.constructor === Array) { for (let b = 0, f; b < a.length; b++) { @@ -571,7 +570,7 @@ function P(a) { } } else { for (const b of a.entries()) { - const f = b[0], c = P(b[1]); + const f = b[0], c = O(b[1]); c ? d += c : a.delete(f); } } @@ -581,14 +580,14 @@ r.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - P(this.map); - this.depth && P(this.ctx); + O(this.map); + this.depth && O(this.ctx); return this; }; w(); -const Q = {Index:K, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, R = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; -let S; -(S = R.define) && S.amd ? S([], function() { - return Q; -}) : "object" === typeof R.exports ? R.exports = Q : R.FlexSearch = Q; +const P = {Index:J, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Q = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; +let R; +(R = Q.define) && R.amd ? R([], function() { + return P; +}) : "object" === typeof Q.exports ? Q.exports = P : Q.FlexSearch = P; }(this||self)); diff --git a/dist/flexsearch.light.min.js b/dist/flexsearch.light.min.js index 262aacc..fb81e3f 100644 --- a/dist/flexsearch.light.min.js +++ b/dist/flexsearch.light.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.143 (Light) + * FlexSearch.js v0.8.147 (Light) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -15,12 +15,12 @@ r.addReplacer=function(a,d){if("string"===typeof a)return this.addMatcher(a,d);t 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)),c!==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(c=0;e&&cthis.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,d,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>d?d?a.slice(b,b+d):a.slice(b):a;let f=[];for(let c=0,g,e;c=e){b-=e;continue}bd&&(g=g.slice(0,d),e=d);if(!f.length&&e>=d)return g;f.push(g);d-=e;if(!d)break}return f=1q;g--){e=l.substring(q,g);t=this.rtl?c-1-q:q;var h=this.score?this.score(d,l,p,e,t):L(C,f,p,c,t);M(this, -m,e,h,a,b)}break}case "bidirectional":case "reverse":if(1e?0:1),f,p,h-1,k-1), -t=this.bidirectional&&l>g;M(this,n,t?g:l,q,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function M(a,d,b,f,c,g,e){let h=e?a.ctx:a.map,k;if(!d[b]||e&&!(k=d[b])[e])e?(d=k||(d[b]=w()),d[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):d[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(c)||(h.push(c),a.fastupdate&&((d=a.reg.get(c))?d.push(h):a.reg.set(c,[h])))}function L(a,d,b,f,c){return b&&1this.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,d,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>d?d?a.slice(b,b+d):a.slice(b):a;let f=[];for(let c=0,g,e;c=e){b-=e;continue}bd&&(g=g.slice(0,d),e=d);if(!f.length&&e>=d)return g;f.push(g);d-=e;if(!d)break}return f=1q;g--){e=l.substring(q,g);t=this.rtl?c-1-q:q;var h=this.score?this.score(d,l,p,e,t):K(C,f,p,c,t);L(this, +m,e,h,a,b)}break}case "bidirectional":case "reverse":if(1e?0:1),f,p,h-1,k-1), +t=this.bidirectional&&l>g;L(this,n,t?g:l,q,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function L(a,d,b,f,c,g,e){let h=e?a.ctx:a.map,k;if(!d[b]||e&&!(k=d[b])[e])e?(d=k||(d[b]=w()),d[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):d[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(c)||(h.push(c),a.fastupdate&&((d=a.reg.get(c))?d.push(h):a.reg.set(c,[h])))}function K(a,d,b,f,c){return b&&1d||c?e.slice(c,d+c):e;e=a}else{if(ad||c)e=e.slice(c,d+c)}m=e}else if(1===f){d=H.call(null,a[0], -d,c);break a}d=m}return d};function N(a,d,b){let f;b&&(f=a.bidirectional&&d>b)&&(f=b,b=d,d=f);a=b?(a=a.ctx.get(b))&&a.get(d):a.map.get(d);return a};K.prototype.remove=function(a,d){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let f=0,c;fc.length)c.pop();else{const g=c.indexOf(a);g===b.length-1?c.pop():c.splice(g,1)}}else O(this.map,a),this.depth&&O(this.ctx,a);d||this.reg.delete(a)}return this}; -function O(a,d){let b=0;if(a.constructor===Array)for(let f=0,c,g;fb.add(a,d)):this.add(a,d)}; -function P(a){let d=0;if(a.constructor===Array)for(let b=0,f;bb)&&(f=b,b=d,d=f);a=b?(a=a.ctx.get(b))&&a.get(d):a.map.get(d);return a};J.prototype.remove=function(a,d){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let f=0,c;fc.length)c.pop();else{const g=c.indexOf(a);g===b.length-1?c.pop():c.splice(g,1)}}else N(this.map,a),this.depth&&N(this.ctx,a);d||this.reg.delete(a)}return this}; +function N(a,d){let b=0;if(a.constructor===Array)for(let f=0,c,g;fb.add(a,d)):this.add(a,d)}; +function O(a){let d=0;if(a.constructor===Array)for(let b=0,f;b q; g--) { e = l.substring(q, g); t = this.rtl ? c - 1 - q : q; - var h = this.score ? this.score(d, l, p, e, t) : L(C, f, p, c, t); - M(this, m, e, h, a, b); + var h = this.score ? this.score(d, l, p, e, t) : K(C, f, p, c, t); + L(this, m, e, h, a, b); } } break; @@ -297,25 +296,25 @@ K.prototype.add = function(a, d, b, f) { if (1 < c) { for (h = c - 1; 0 < h; h--) { e = l[this.rtl ? c - 1 - h : h] + e; - var k = this.score ? this.score(d, l, p, e, h) : L(C, f, p, c, h); - M(this, m, e, k, a, b); + var k = this.score ? this.score(d, l, p, e, h) : K(C, f, p, c, h); + L(this, m, e, k, a, b); } e = ""; } case "forward": if (1 < c) { for (h = 0; h < c; h++) { - e += l[this.rtl ? c - 1 - h : h], M(this, m, e, g, a, b); + e += l[this.rtl ? c - 1 - h : h], L(this, m, e, g, a, b); } break; } default: - if (M(this, m, l, g, a, b), v && 1 < f && p < f - 1) { + if (L(this, m, l, g, a, b), v && 1 < f && p < f - 1) { for (c = w(), e = this.v, g = l, h = Math.min(v + 1, this.rtl ? p + 1 : f - p), c[g] = 1, k = 1; k < h; k++) { if ((l = d[this.rtl ? f - 1 - p - k : p + k]) && !c[l]) { c[l] = 1; - const q = this.score ? this.score(d, g, p, l, k - 1) : L(e + (f / 2 > e ? 0 : 1), f, p, h - 1, k - 1), t = this.bidirectional && l > g; - M(this, n, t ? g : l, q, a, b, t ? l : g); + const q = this.score ? this.score(d, g, p, l, k - 1) : K(e + (f / 2 > e ? 0 : 1), f, p, h - 1, k - 1), t = this.bidirectional && l > g; + L(this, n, t ? g : l, q, a, b, t ? l : g); } } } @@ -327,16 +326,16 @@ K.prototype.add = function(a, d, b, f) { } return this; }; -function M(a, d, b, f, c, g, e) { +function L(a, d, b, f, c, g, e) { let h = e ? a.ctx : a.map, k; if (!d[b] || e && !(k = d[b])[e]) { e ? (d = k || (d[b] = w()), d[e] = 1, (k = h.get(e)) ? h = k : h.set(e, h = new Map())) : d[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[f] || (h[f] = []), g && h.includes(c) || (h.push(c), a.fastupdate && ((d = a.reg.get(c)) ? d.push(h) : a.reg.set(c, [h]))); } } -function L(a, d, b, f, c) { +function K(a, d, b, f, c) { return b && 1 < a ? d + (f || 0) <= a ? b + (c || 0) : (a - 1) / (d + (f || 0)) * (b + (c || 0)) + 1 | 0 : 0; } -;K.prototype.search = function(a, d, b) { +;J.prototype.search = function(a, d, b) { b || (d || "object" !== typeof a ? "object" === typeof d && (b = d, d = 0) : (b = a, a = "")); var f = [], c = 0; if (b) { @@ -354,11 +353,11 @@ function L(a, d, b, f, c) { b = a.length; d = d || (h ? 100 : 0); if (1 === b) { - return e = c, (c = N(this, a[0], "")) && c.length ? H.call(this, c, d, e) : []; + return e = c, (c = M(this, a[0], "")) && c.length ? H.call(this, c, d, e) : []; } g = this.depth && !1 !== g; if (2 === b && g && !e) { - return e = c, (c = N(this, a[0], a[1])) && c.length ? H.call(this, c, d, e) : []; + return e = c, (c = M(this, a[1], a[0])) && c.length ? H.call(this, c, d, e) : []; } h = w(); var n = 0; @@ -370,7 +369,7 @@ function L(a, d, b, f, c) { for (let l, q; n < b; n++) { if ((q = a[n]) && !h[q]) { h[q] = 1; - l = N(this, q, m); + l = M(this, q, m); a: { g = l; var v = f, C = e, p = k; @@ -471,13 +470,13 @@ function L(a, d, b, f, c) { } return d; }; -function N(a, d, b) { +function M(a, d, b) { let f; b && (f = a.bidirectional && d > b) && (f = b, b = d, d = f); a = b ? (a = a.ctx.get(b)) && a.get(d) : a.map.get(d); return a; } -;K.prototype.remove = function(a, d) { +;J.prototype.remove = function(a, d) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { @@ -492,13 +491,13 @@ function N(a, d, b) { } } } else { - O(this.map, a), this.depth && O(this.ctx, a); + N(this.map, a), this.depth && N(this.ctx, a); } d || this.reg.delete(a); } return this; }; -function O(a, d) { +function N(a, d) { let b = 0; if (a.constructor === Array) { for (let f = 0, c, g; f < a.length; f++) { @@ -513,24 +512,24 @@ function O(a, d) { } } else { for (let f of a.entries()) { - const c = f[0], g = O(f[1], d); + const c = f[0], g = N(f[1], d); g ? b += g : a.delete(c); } } return b; } -;function K(a, d) { - if (!this || this.constructor !== K) { - return new K(a); +;function J(a, d) { + if (!this || this.constructor !== J) { + return new J(a); } if (a) { var b = "string" === typeof a ? a : a.preset; - b && (J[b] || console.warn("Preset not found: " + b), a = Object.assign({}, J[b], a)); + b && (I[b] || console.warn("Preset not found: " + b), a = Object.assign({}, I[b], a)); } else { a = {}; } b = a.context; - const f = !0 === b ? {depth:1} : b || {}, c = a.encode || a.encoder || I; + const f = !0 === b ? {depth:1} : b || {}, c = a.encode || a.encoder || {}; this.encoder = c.encode ? c : "object" === typeof c ? new F(c) : {encode:c}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; @@ -545,7 +544,7 @@ function O(a, d) { this.v = f.resolution || 3; this.rtl = c.rtl || a.rtl || !1; } -r = K.prototype; +r = J.prototype; r.clear = function() { this.map.clear(); this.ctx.clear(); @@ -562,7 +561,7 @@ r.update = function(a, d) { const b = this, f = this.remove(a); return f && f.then ? f.then(() => b.add(a, d)) : this.add(a, d); }; -function P(a) { +function O(a) { let d = 0; if (a.constructor === Array) { for (let b = 0, f; b < a.length; b++) { @@ -570,7 +569,7 @@ function P(a) { } } else { for (const b of a.entries()) { - const f = b[0], c = P(b[1]); + const f = b[0], c = O(b[1]); c ? d += c : a.delete(f); } } @@ -580,11 +579,11 @@ r.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - P(this.map); - this.depth && P(this.ctx); + O(this.map); + this.depth && O(this.ctx); return this; }; w(); -export default {Index:K, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +export default {Index:J, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=K;export const Charset=null;export const Encoder=F;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=J;export const Charset=null;export const Encoder=F;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js index 2567537..cb0057a 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.143 (Bundle) + * FlexSearch.js v0.8.147 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -15,13 +15,13 @@ r.addReplacer=function(a,d){if("string"===typeof a)return this.addMatcher(a,d);t 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)),c!==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(c=0;e&&cthis.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,d,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>d?d?a.slice(b,b+d):a.slice(b):a;let f=[];for(let c=0,g,e;c=e){b-=e;continue}bd&&(g=g.slice(0,d),e=d);if(!f.length&&e>=d)return g;f.push(g);d-=e;if(!d)break}return f=1q;g--){e=l.substring(q,g);t=this.rtl?c-1-q:q;var h=this.score?this.score(d,l,p,e,t):L(C,f,p,c,t);M(this, -m,e,h,a,b)}break}case "bidirectional":case "reverse":if(1e?0:1),f,p,h-1,k-1), -t=this.bidirectional&&l>g;M(this,n,t?g:l,q,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function M(a,d,b,f,c,g,e){let h=e?a.ctx:a.map,k;if(!d[b]||e&&!(k=d[b])[e])e?(d=k||(d[b]=w()),d[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):d[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(c)||(h.push(c),a.fastupdate&&((d=a.reg.get(c))?d.push(h):a.reg.set(c,[h])))}function L(a,d,b,f,c){return b&&1this.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,d,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>d?d?a.slice(b,b+d):a.slice(b):a;let f=[];for(let c=0,g,e;c=e){b-=e;continue}bd&&(g=g.slice(0,d),e=d);if(!f.length&&e>=d)return g;f.push(g);d-=e;if(!d)break}return f=1q;g--){e=l.substring(q,g);t=this.rtl?c-1-q:q;var h=this.score?this.score(d,l,p,e,t):K(C,f,p,c,t);L(this, +m,e,h,a,b)}break}case "bidirectional":case "reverse":if(1e?0:1),f,p,h-1,k-1), +t=this.bidirectional&&l>g;L(this,n,t?g:l,q,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function L(a,d,b,f,c,g,e){let h=e?a.ctx:a.map,k;if(!d[b]||e&&!(k=d[b])[e])e?(d=k||(d[b]=w()),d[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):d[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(c)||(h.push(c),a.fastupdate&&((d=a.reg.get(c))?d.push(h):a.reg.set(c,[h])))}function K(a,d,b,f,c){return b&&1d||c?e.slice(c,d+c):e;e=a}else{if(ad||c)e=e.slice(c,d+c)}m=e}else if(1===f){d=H.call(null,a[0], -d,c);break a}d=m}return d};function N(a,d,b){let f;b&&(f=a.bidirectional&&d>b)&&(f=b,b=d,d=f);a=b?(a=a.ctx.get(b))&&a.get(d):a.map.get(d);return a};K.prototype.remove=function(a,d){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let f=0,c;fc.length)c.pop();else{const g=c.indexOf(a);g===b.length-1?c.pop():c.splice(g,1)}}else O(this.map,a),this.depth&&O(this.ctx,a);d||this.reg.delete(a)}return this}; -function O(a,d){let b=0;if(a.constructor===Array)for(let f=0,c,g;fb.add(a,d)):this.add(a,d)}; -function P(a){let d=0;if(a.constructor===Array)for(let b=0,f;bb)&&(f=b,b=d,d=f);a=b?(a=a.ctx.get(b))&&a.get(d):a.map.get(d);return a};J.prototype.remove=function(a,d){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let f=0,c;fc.length)c.pop();else{const g=c.indexOf(a);g===b.length-1?c.pop():c.splice(g,1)}}else N(this.map,a),this.depth&&N(this.ctx,a);d||this.reg.delete(a)}return this}; +function N(a,d){let b=0;if(a.constructor===Array)for(let f=0,c,g;fb.add(a,d)):this.add(a,d)}; +function O(a){let d=0;if(a.constructor===Array)for(let b=0,f;b MAXIMUM_QUERY_VARS){ - + // next = data.slice(MAXIMUM_QUERY_VARS); // data = data.slice(0, MAXIMUM_QUERY_VARS); // } // let insert = pgp.helpers.insert(data, stmt); diff --git a/dist/module-debug/db/redis/db.js b/dist/module-debug/db/redis/index.js similarity index 100% rename from dist/module-debug/db/redis/db.js rename to dist/module-debug/db/redis/index.js diff --git a/dist/module-debug/db/sqlite/db.js b/dist/module-debug/db/sqlite/index.js similarity index 99% rename from dist/module-debug/db/sqlite/db.js rename to dist/module-debug/db/sqlite/index.js index 35df78b..82728eb 100644 --- a/dist/module-debug/db/sqlite/db.js +++ b/dist/module-debug/db/sqlite/index.js @@ -36,7 +36,7 @@ function sanitize(str) { // global transaction to keep track of database lock const TRX = Object.create(null), - DB = Object.create(null); + Index = Object.create(null); /** @@ -59,7 +59,7 @@ export default function SqliteDB(name, config = {}) { this.id = config.path || (":memory:" === name ? name : "flexsearch" + (name ? "-" + sanitize(name) : "") + ".sqlite"); this.field = config.field ? "_" + sanitize(config.field) : ""; this.support_tag_search = /* tag? */ /* stringify */ /* stringify */ /* single param */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; - this.db = config.db || DB[this.id] || null; + this.db = config.db || Index[this.id] || null; this.type = config.type ? types[config.type.toLowerCase()] : "string"; if (!this.type) throw new Error("Unknown type of ID '" + config.type + "'"); } @@ -77,7 +77,7 @@ SqliteDB.prototype.open = async function () { if (!this.db) { - if (!(this.db = DB[this.id])) { + if (!(this.db = Index[this.id])) { let filepath = this.id; if (":memory:" !== filepath) { @@ -89,7 +89,7 @@ SqliteDB.prototype.open = async function () { } } - this.db = DB[this.id] = new sqlite3.Database(filepath); + this.db = Index[this.id] = new sqlite3.Database(filepath); } } @@ -197,7 +197,7 @@ SqliteDB.prototype.open = async function () { SqliteDB.prototype.close = function () { this.db && this.db.close(); this.db = null; - DB[this.id] = null; + Index[this.id] = null; TRX[this.id] = null; return this; }; diff --git a/dist/module-debug/document.js b/dist/module-debug/document.js index b7b4404..423d173 100644 --- a/dist/module-debug/document.js +++ b/dist/module-debug/document.js @@ -458,20 +458,25 @@ Document.prototype.get = function (id) { if (this.db) { return this.index.get(this.field[0]).db.enrich(id).then(function (result) { - return result[0] && result[0].doc; + return result[0] && result[0].doc || null; }); } - return this.store.get(id); + return this.store.get(id) || null; }; /** - * @param {number|string} id + * @param {number|string|Object} id * @param {Object} data * @return {Document} */ Document.prototype.set = function (id, data) { + if ("object" == typeof id) { + data = id; + id = parse_simple(data, this.key); + } + this.store.set(id, data); return this; }; diff --git a/dist/module-debug/encoder.js b/dist/module-debug/encoder.js index 017399a..b08389b 100644 --- a/dist/module-debug/encoder.js +++ b/dist/module-debug/encoder.js @@ -1,6 +1,6 @@ import { merge_option } from "./common.js"; -import normalize_polyfill from "./charset/normalize.js"; +import normalize_polyfill from "./charset/polyfill.js"; import { EncoderOptions } from "./type.js"; /* @@ -510,6 +510,11 @@ Encoder.prototype.encode = function (str) { return final; }; +export function fallback_encoder(str) { + + return str.normalize("NFKD").replace(normalize, "").toLowerCase().trim().split(/\s+/); +} + // Encoder.prototype.compress = function(str) { // // //return str; diff --git a/dist/module-debug/index.js b/dist/module-debug/index.js index 63fa421..e5e3f02 100644 --- a/dist/module-debug/index.js +++ b/dist/module-debug/index.js @@ -7,13 +7,13 @@ */ import { IndexOptions, ContextOptions, EncoderOptions } from "./type.js"; -import Encoder from "./encoder.js"; +import Encoder, { fallback_encoder } from "./encoder.js"; import Cache, { searchCache } from "./cache.js"; import Charset from "./charset.js"; import { KeystoreMap, KeystoreSet } from "./keystore.js"; import { is_array, is_string } from "./common.js"; import { exportIndex, importIndex, serialize } from "./serialize.js"; -import default_encoder from "./charset/latin/default.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"; @@ -39,7 +39,7 @@ export default function Index(options, _register) { let tmp = options.context; /** @type ContextOptions */ 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; + encoder = is_string(options.encoder) ? Charset[options.encoder] : options.encode || options.encoder || {} /*default_encoder*/; /** @type Encoder */ this.encoder = encoder.encode ? encoder : "object" == typeof encoder ? new Encoder( /** @type {EncoderOptions} */encoder) : { encode: encoder }; diff --git a/dist/module-debug/index/search.js b/dist/module-debug/index/search.js index 75d25a3..e6ba8b8 100644 --- a/dist/module-debug/index/search.js +++ b/dist/module-debug/index/search.js @@ -57,8 +57,7 @@ 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; @@ -91,8 +90,8 @@ Index.prototype.search = function (query, limit, options) { // fast path single context if (2 === length && context && !suggest) { - return single_term_query.call(this, query_terms[0], // term - query_terms[1], // ctx + return single_term_query.call(this, query_terms[1], // term + query_terms[0], // ctx limit, offset, resolve, enrich, tag); } diff --git a/dist/module-min/bundle.js b/dist/module-min/bundle.js index 281f055..26f07c1 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/db.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.encoder,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,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="undefined"==typeof self?"undefined"==typeof global?self:global: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.encoder,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,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="undefined"==typeof self?"undefined"==typeof global?self:global: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/charset.js b/dist/module-min/charset.js index 39214a8..3d423d8 100644 --- a/dist/module-min/charset.js +++ b/dist/module-min/charset.js @@ -1 +1 @@ -import charset_latin_exact from"./charset/latin/exact.js";import charset_latin_default from"./charset/latin/default.js";import charset_latin_simple from"./charset/latin/simple.js";import charset_latin_balance from"./charset/latin/balance.js";import charset_latin_advanced from"./charset/latin/advanced.js";import charset_latin_extra from"./charset/latin/extra.js";import charset_latin_soundex from"./charset/latin/soundex.js";export const Exact=charset_latin_exact;export const Default=charset_latin_default;export const Normalize=charset_latin_simple;export const LatinBalance=charset_latin_balance;export const LatinAdvanced=charset_latin_advanced;export const LatinExtra=charset_latin_extra;export const LatinSoundex=charset_latin_soundex;export const LatinExact=charset_latin_exact;export const LatinDefault=charset_latin_default;export const LatinSimple=charset_latin_simple;export default{Exact:charset_latin_exact,Default:charset_latin_default,Normalize:charset_latin_simple,LatinBalance:charset_latin_balance,LatinAdvanced:charset_latin_advanced,LatinExtra:charset_latin_extra,LatinSoundex:charset_latin_soundex,LatinExact:charset_latin_exact,LatinDefault:charset_latin_default,LatinSimple:charset_latin_simple}; \ No newline at end of file +import charset_latin_exact from"./charset/latin/exact.js";import charset_latin_normalize from"./charset/latin/normalize.js";import charset_latin_balance from"./charset/latin/balance.js";import charset_latin_advanced from"./charset/latin/advanced.js";import charset_latin_extra from"./charset/latin/extra.js";import charset_latin_soundex from"./charset/latin/soundex.js";export const Exact=charset_latin_exact;export const Default=charset_latin_normalize;export const Normalize=charset_latin_normalize;export const LatinBalance=charset_latin_balance;export const LatinAdvanced=charset_latin_advanced;export const LatinExtra=charset_latin_extra;export const LatinSoundex=charset_latin_soundex;export const LatinExact=charset_latin_exact;export const LatinDefault=charset_latin_normalize;export const LatinSimple=charset_latin_normalize;export default{Exact:charset_latin_exact,Default:charset_latin_normalize,Normalize:charset_latin_normalize,LatinBalance:charset_latin_balance,LatinAdvanced:charset_latin_advanced,LatinExtra:charset_latin_extra,LatinSoundex:charset_latin_soundex,LatinExact:charset_latin_exact,LatinDefault:charset_latin_normalize,LatinSimple:charset_latin_normalize}; \ No newline at end of file diff --git a/dist/module-min/charset/latin/advanced.js b/dist/module-min/charset/latin/advanced.js index 59a7fa6..0296417 100644 --- a/dist/module-min/charset/latin/advanced.js +++ b/dist/module-min/charset/latin/advanced.js @@ -1 +1 @@ -import{EncoderOptions}from"../../type.js";import{soundex}from"./balance.js";export const matcher=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]);export const replacer=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const options={normalize:!0,dedupe:!0,mapper:soundex,matcher:matcher,replacer:replacer};export default options; \ No newline at end of file +import{EncoderOptions}from"../../type.js";import{soundex}from"./balance.js";export const matcher=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]);export const replacer=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const options={dedupe:!0,mapper:soundex,matcher:matcher,replacer:replacer};export default options; \ No newline at end of file diff --git a/dist/module-min/charset/latin/balance.js b/dist/module-min/charset/latin/balance.js index 0236992..ad5d1db 100644 --- a/dist/module-min/charset/latin/balance.js +++ b/dist/module-min/charset/latin/balance.js @@ -1 +1 @@ -import{EncoderOptions}from"../../type.js";export const soundex=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 options={normalize:!0,dedupe:!0,mapper:soundex};export default options; \ No newline at end of file +import{EncoderOptions}from"../../type.js";export const soundex=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 options={dedupe:!0,mapper:soundex};export default options; \ No newline at end of file diff --git a/dist/module-min/charset/latin/default.js b/dist/module-min/charset/latin/default.js deleted file mode 100644 index 5b7192e..0000000 --- a/dist/module-min/charset/latin/default.js +++ /dev/null @@ -1 +0,0 @@ -import{EncoderOptions}from"../../type.js";const options={normalize:!0};export default options; \ No newline at end of file diff --git a/dist/module-min/charset/latin/exact.js b/dist/module-min/charset/latin/exact.js index e674552..46a2217 100644 --- a/dist/module-min/charset/latin/exact.js +++ b/dist/module-min/charset/latin/exact.js @@ -1 +1 @@ -import{EncoderOptions}from"../../type.js";const options={normalize:!1,numeric:!1,split:/\s+/};export default options; \ No newline at end of file +import{EncoderOptions}from"../../type.js";const options={normalize:!1,numeric:!1};export default options; \ No newline at end of file diff --git a/dist/module-min/charset/latin/extra.js b/dist/module-min/charset/latin/extra.js index 2f1e13d..8c3b3fe 100644 --- a/dist/module-min/charset/latin/extra.js +++ b/dist/module-min/charset/latin/extra.js @@ -1 +1 @@ -import{EncoderOptions}from"../../type.js";import{soundex}from"./balance.js";import{matcher,replacer}from"./advanced.js";export const compact=[/(?!^)[aeo]/g,""];const options={normalize:!0,dedupe:!0,mapper:soundex,replacer:replacer.concat(compact),matcher:matcher};export default options; \ No newline at end of file +import{EncoderOptions}from"../../type.js";import{soundex}from"./balance.js";import{matcher,replacer}from"./advanced.js";export const compact=[/(?!^)[aeo]/g,""];const options={dedupe:!0,mapper:soundex,replacer:replacer.concat(compact),matcher:matcher};export default options; \ No newline at end of file diff --git a/dist/module-min/charset/latin/normalize.js b/dist/module-min/charset/latin/normalize.js new file mode 100644 index 0000000..07081f7 --- /dev/null +++ b/dist/module-min/charset/latin/normalize.js @@ -0,0 +1 @@ +import{EncoderOptions}from"../../type.js";const options={};export default options; \ No newline at end of file diff --git a/dist/module-min/charset/latin/simple.js b/dist/module-min/charset/latin/simple.js deleted file mode 100644 index 9692634..0000000 --- a/dist/module-min/charset/latin/simple.js +++ /dev/null @@ -1 +0,0 @@ -import{EncoderOptions}from"../../type.js";const options={normalize:!0,dedupe:!0};export default options; \ No newline at end of file diff --git a/dist/module-min/charset/latin/soundex.js b/dist/module-min/charset/latin/soundex.js index fec07c5..fe355ea 100644 --- a/dist/module-min/charset/latin/soundex.js +++ b/dist/module-min/charset/latin/soundex.js @@ -1 +1 @@ -import{EncoderOptions}from"../../type.js";const options={normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){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{a.onsuccess=a.oncomplete=function(){b&&b(this.result),b=null,c(this.result)},a.onerror=a.onblocked=d,a=null})} \ No newline at end of file diff --git a/dist/module-min/db/indexeddb/index.js b/dist/module-min/db/indexeddb/index.js new file mode 100644 index 0000000..a435512 --- /dev/null +++ b/dist/module-min/db/indexeddb/index.js @@ -0,0 +1 @@ +import{PersistentOptions,SearchResults,EnrichedSearchResults}from"../../type.js";const VERSION=1,IndexedDB="undefined"!=typeof window&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),IDBTransaction="undefined"!=typeof window&&(window.IDBTransaction||window.webkitIDBTransaction||window.msIDBTransaction),IDBKeyRange="undefined"!=typeof window&&(window.IDBKeyRange||window.webkitIDBKeyRange||window.msIDBKeyRange),fields=["map","ctx","tag","reg","cfg"];import StorageInterface from"../interface.js";import{create_object,toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}const Index=create_object();export default function IdxDB(a,b={}){return this?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(){if(this.db)return this.db;let a=this;navigator.storage&&navigator.storage.persist(),Index[a.id]||(Index[a.id]=[]),Index[a.id].push(a.field);const b=IndexedDB.open(a.id,VERSION);return b.onupgradeneeded=function(){const b=a.db=this.result;for(let c,d=0;d=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b{a.onsuccess=a.oncomplete=function(){b&&b(this.result),b=null,c(this.result)},a.onerror=a.onblocked=d,a=null})} \ No newline at end of file diff --git a/dist/module-min/db/mongodb/db.js b/dist/module-min/db/mongodb/db.js deleted file mode 100644 index ce3915a..0000000 --- a/dist/module-min/db/mongodb/db.js +++ /dev/null @@ -1 +0,0 @@ -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}const m={_id:1};f||(m.res=1),g&&(m.doc=1);const n=[{$match:{$or:k}},{$group:{_id:"$id",count:{$sum:1},res:e?{$sum:"$res"}:{$sum:"$res"}}}];if(e||n.push({$match:{count:b.length-1}}),g&&(m.doc="$doc.doc",n.push({$lookup:{from:"reg",localField:"_id",foreignField:"id",as:"doc"}},{$unwind:{path:"$doc",preserveNullAndEmptyArrays:!0}})),h){const a={};for(let b=0,c=1;bl;k.push({ctx:d?j:l,key:d?l:j}),l=j}const m={_id:1};f||(m.res=1),g&&(m.doc=1);const n=[{$match:{$or:k}},{$group:{_id:"$id",count:{$sum:1},res:e?{$sum:"$res"}:{$sum:"$res"}}}];if(e||n.push({$match:{count:b.length-1}}),g&&(m.doc="$doc.doc",n.push({$lookup:{from:"reg",localField:"_id",foreignField:"id",as:"doc"}},{$unwind:{path:"$doc",preserveNullAndEmptyArrays:!0}})),h){const a={};for(let b=0,c=1;b"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),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 +import{merge_option}from"./common.js";import normalize_polyfill from"./charset/polyfill.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),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};export function fallback_encoder(a){return a.normalize("NFKD").replace(normalize,"").toLowerCase().trim().split(/\s+/)}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 cba1dee..d092445 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=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict",this.depth="strict"===c&&d.depth||0,this.bidirectional=!1!==d.bidirectional,this.fastupdate=!!a.fastupdate,this.score=a.score||null,!1,c=a.keystore||0,c&&(this.keystore=c),this.map=c&&!0?new KeystoreMap(c):new Map,this.ctx=c&&!0?new KeystoreMap(c):new Map,this.reg=b||(this.fastupdate?c&&!0?new KeystoreMap(c):new Map:c&&!0?new KeystoreSet(c):new Set),this.resolution_ctx=d.resolution||3,this.rtl=e.rtl||a.rtl||!1,this.cache=(c=a.cache||null)&&new Cache(c),this.resolve=!1!==a.resolve,(c=a.db)&&(this.db=this.mount(c)),this.commit_auto=!1!==a.commit,this.commit_task=[],this.commit_timer=null,this.priority=a.priority||4}Index.prototype.mount=function(a){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),a.mount(this)},Index.prototype.commit=function(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;db,i&&(i=b,b=a,a=i)),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?this.db.get(a,b,c,d,e,f,g):(b?(h=this.ctx.get(b),h=h&&h.get(a)):h=this.map.get(a),h)}; \ No newline at end of file +import{SearchOptions,SearchResults,EnrichedSearchResults,IntermediateSearchResults}from"../type.js";import{create_object,is_object,sort_by_length_down}from"../common.js";import Index from"../index.js";import default_compress from"../compress.js";import Resolver from"../resolver.js";import{intersect}from"../intersect.js";import resolve_default from"../resolve/default.js";Index.prototype.search=function(a,b,c){c||(!b&&is_object(a)?(c=a,a=""):is_object(b)&&(c=b,b=0));let d,e,f,g,h,i,j,k,l=[],m=0;c?(a=c.query||a,b=c.limit||b,m=c.offset||0,e=c.context,f=c.suggest,g=!1!==c.resolve,k=g&&c.enrich,i=c.boost,j=c.resolution,h=this.db&&c.tag):g=this.resolve;let n=this.encoder.encode(a);if(d=n.length,b=b||(g?100:0),1===d)return single_term_query.call(this,n[0],"",b,m,g,k,h);if(e=this.depth&&!1!==e,2===d&&e&&!f)return single_term_query.call(this,n[1],n[0],b,m,g,k,h);let o,p=create_object(),q=0;if(1b,i&&(i=b,b=a,a=i)),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?this.db.get(a,b,c,d,e,f,g):(b?(h=this.ctx.get(b),h=h&&h.get(a)):h=this.map.get(a),h)}; \ No newline at end of file diff --git a/dist/module/bundle.js b/dist/module/bundle.js index 9364100..95e5e38 100644 --- a/dist/module/bundle.js +++ b/dist/module/bundle.js @@ -6,7 +6,7 @@ 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/db.js"; +import IdxDB from "./db/indexeddb/index.js"; import Charset from "./charset.js"; import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; diff --git a/dist/module/charset.js b/dist/module/charset.js index 1b9b560..3f4c1ec 100644 --- a/dist/module/charset.js +++ b/dist/module/charset.js @@ -1,15 +1,14 @@ import charset_latin_exact from "./charset/latin/exact.js"; -import charset_latin_default from "./charset/latin/default.js"; -import charset_latin_simple from "./charset/latin/simple.js"; +import charset_latin_normalize from "./charset/latin/normalize.js"; import charset_latin_balance from "./charset/latin/balance.js"; import charset_latin_advanced from "./charset/latin/advanced.js"; import charset_latin_extra from "./charset/latin/extra.js"; import charset_latin_soundex from "./charset/latin/soundex.js"; -// all charset +// universal charset export const Exact = charset_latin_exact; -export const Default = charset_latin_default; -export const Normalize = charset_latin_simple; +export const Default = charset_latin_normalize; +export const Normalize = charset_latin_normalize; // latin charset export const LatinBalance = charset_latin_balance; export const LatinAdvanced = charset_latin_advanced; @@ -17,14 +16,14 @@ export const LatinExtra = charset_latin_extra; export const LatinSoundex = charset_latin_soundex; // deprecated export const LatinExact = charset_latin_exact; -export const LatinDefault = charset_latin_default; -export const LatinSimple = charset_latin_simple; +export const LatinDefault = charset_latin_normalize; +export const LatinSimple = charset_latin_normalize; export default { - // all charset + // universal charset Exact: charset_latin_exact, - Default: charset_latin_default, - Normalize: charset_latin_simple, + Default: charset_latin_normalize, + Normalize: charset_latin_normalize, // latin charset LatinBalance: charset_latin_balance, LatinAdvanced: charset_latin_advanced, @@ -32,6 +31,6 @@ export default { LatinSoundex: charset_latin_soundex, // deprecated LatinExact: charset_latin_exact, - LatinDefault: charset_latin_default, - LatinSimple: charset_latin_simple + LatinDefault: charset_latin_normalize, + LatinSimple: charset_latin_normalize }; \ No newline at end of file diff --git a/dist/module/charset/latin/advanced.js b/dist/module/charset/latin/advanced.js index a6d187d..5d4003c 100644 --- a/dist/module/charset/latin/advanced.js +++ b/dist/module/charset/latin/advanced.js @@ -17,7 +17,7 @@ export const replacer = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /** @type EncoderOptions */ const options = { - normalize: !0, + //normalize: true, dedupe: !0, mapper: soundex, matcher: matcher, diff --git a/dist/module/charset/latin/balance.js b/dist/module/charset/latin/balance.js index dae9967..bae3dea 100644 --- a/dist/module/charset/latin/balance.js +++ b/dist/module/charset/latin/balance.js @@ -30,7 +30,7 @@ export const soundex = new Map([["b", "p"], /** @type EncoderOptions */ const options = { - normalize: !0, + //normalize: true, dedupe: !0, mapper: soundex }; diff --git a/dist/module/charset/latin/exact.js b/dist/module/charset/latin/exact.js index 9fa871f..e51f713 100644 --- a/dist/module/charset/latin/exact.js +++ b/dist/module/charset/latin/exact.js @@ -3,8 +3,8 @@ import { EncoderOptions } from "../../type.js"; /** @type EncoderOptions */ const options = { normalize: !1, - numeric: !1, - split: /\s+/ + numeric: !1 + //split: /\s+/ //normalize: false, //dedupe: false }; diff --git a/dist/module/charset/latin/extra.js b/dist/module/charset/latin/extra.js index 02f7ae2..10a41b9 100644 --- a/dist/module/charset/latin/extra.js +++ b/dist/module/charset/latin/extra.js @@ -7,7 +7,7 @@ export const compact = [/(?!^)[aeo]/g, "" // before soundex: aeoy, old: aioy /** @type EncoderOptions */ const options = { - normalize: !0, + //normalize: true, dedupe: !0, mapper: soundex, replacer: replacer.concat(compact), diff --git a/dist/module/charset/latin/default.js b/dist/module/charset/latin/normalize.js similarity index 90% rename from dist/module/charset/latin/default.js rename to dist/module/charset/latin/normalize.js index 4ba0cad..e9557b2 100644 --- a/dist/module/charset/latin/default.js +++ b/dist/module/charset/latin/normalize.js @@ -2,7 +2,7 @@ import { EncoderOptions } from "../../type.js"; /** @type EncoderOptions */ const options = { - normalize: !0 + //normalize: true // normalize: function(str){ // return str.toLowerCase(); // }, diff --git a/dist/module/charset/latin/simple.js b/dist/module/charset/latin/simple.js deleted file mode 100644 index be96c47..0000000 --- a/dist/module/charset/latin/simple.js +++ /dev/null @@ -1,8 +0,0 @@ -import { EncoderOptions } from "../../type.js"; - -/** @type EncoderOptions */ -const options = { - normalize: !0, - dedupe: !0 -}; -export default options; \ No newline at end of file diff --git a/dist/module/charset/latin/soundex.js b/dist/module/charset/latin/soundex.js index c1ef7a2..c15547f 100644 --- a/dist/module/charset/latin/soundex.js +++ b/dist/module/charset/latin/soundex.js @@ -2,7 +2,7 @@ import { EncoderOptions } from "../../type.js"; /** @type {EncoderOptions} */ const options = { - normalize: !0, + //normalize: true, dedupe: !1, include: { letter: !0 diff --git a/dist/module/charset/normalize.js b/dist/module/charset/polyfill.js similarity index 100% rename from dist/module/charset/normalize.js rename to dist/module/charset/polyfill.js diff --git a/dist/module/db/clickhouse/db.js b/dist/module/db/clickhouse/index.js similarity index 99% rename from dist/module/db/clickhouse/db.js rename to dist/module/db/clickhouse/index.js index a160e17..f0fd081 100644 --- a/dist/module/db/clickhouse/db.js +++ b/dist/module/db/clickhouse/index.js @@ -47,7 +47,7 @@ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_]/g, ""); } -let DB; +let Index; /** * @constructor @@ -74,7 +74,7 @@ export default function ClickhouseDB(name, config = {}) { if (!this.type) throw new Error("Unknown type of ID '" + config.type + "'"); //this.trx = false; this.support_tag_search = !0; - this.db = DB || (DB = config.db || null); + this.db = Index || (Index = config.db || null); Object.assign(defaults, config); config.database && (defaults.config.database = config.database); this.db && delete defaults.db; @@ -93,7 +93,7 @@ ClickhouseDB.prototype.mount = function (flexsearch) { ClickhouseDB.prototype.open = async function () { if (!this.db) { - this.db = DB || (DB = new ClickHouse(defaults)); + this.db = Index || (Index = new ClickHouse(defaults)); } const exists = await this.db.query(` @@ -174,7 +174,7 @@ ClickhouseDB.prototype.open = async function () { ClickhouseDB.prototype.close = function () { //DB && DB.close(); - this.db = DB = null; + this.db = Index = null; return this; }; diff --git a/dist/module/db/indexeddb/db.js b/dist/module/db/indexeddb/index.js similarity index 98% rename from dist/module/db/indexeddb/db.js rename to dist/module/db/indexeddb/index.js index f57047c..1f4f651 100644 --- a/dist/module/db/indexeddb/db.js +++ b/dist/module/db/indexeddb/index.js @@ -18,7 +18,7 @@ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); } -const DB = create_object(); +const Index = create_object(); /** * @param {string|PersistentOptions=} name @@ -65,8 +65,8 @@ IdxDB.prototype.open = function () { // return this.db = new Promise(function(resolve, reject){ - DB[self.id] || (DB[self.id] = []); - DB[self.id].push(self.field); + Index[self.id] || (Index[self.id] = []); + Index[self.id].push(self.field); const req = IndexedDB.open(self.id, VERSION); @@ -82,8 +82,8 @@ IdxDB.prototype.open = function () { // IndexedDB is such a poor contribution :( for (let i = 0, ref; i < fields.length; i++) { ref = fields[i]; - for (let j = 0, field; j < DB[self.id].length; j++) { - field = DB[self.id][j]; + for (let j = 0, field; j < Index[self.id].length; j++) { + field = Index[self.id][j]; db.objectStoreNames.contains(ref + ("reg" !== ref ? field ? ":" + field : "" : "")) || db.createObjectStore(ref + ("reg" !== ref ? field ? ":" + field : "" : "")); //{ autoIncrement: true /*keyPath: "id"*/ } //.createIndex("idx", "ids", { multiEntry: true, unique: false }); } @@ -167,8 +167,8 @@ IdxDB.prototype.clear = function () { for (let i = 0, ref; i < fields.length; i++) { ref = fields[i]; - for (let j = 0, field; j < DB[this.id].length; j++) { - field = DB[this.id][j]; + for (let j = 0, field; j < Index[this.id].length; j++) { + field = Index[this.id][j]; stores.push(ref + ("reg" !== ref ? field ? ":" + field : "" : "")); } } diff --git a/dist/module/db/mongodb/db.js b/dist/module/db/mongodb/index.js similarity index 98% rename from dist/module/db/mongodb/db.js rename to dist/module/db/mongodb/index.js index 1ab13f0..f4ac562 100644 --- a/dist/module/db/mongodb/db.js +++ b/dist/module/db/mongodb/index.js @@ -16,7 +16,7 @@ function sanitize(str) { } let CLIENT, - DB = Object.create(null); + Index = Object.create(null); /** @@ -38,7 +38,7 @@ export default function MongoDB(name, config = {}) { this.id = "flexsearch" + (name ? "-" + sanitize(name) : ""); this.field = config.field ? "-" + sanitize(config.field) : ""; this.type = config.type || ""; - this.db = config.db || DB[this.id] || CLIENT || null; + this.db = config.db || Index[this.id] || CLIENT || null; this.trx = !1; this.support_tag_search = /* tag? */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; Object.assign(defaults, config); @@ -87,7 +87,7 @@ async function createCollection(db, ref, field) { MongoDB.prototype.open = async function () { if (!this.db) { - if (!(this.db = DB[this.id])) { + if (!(this.db = Index[this.id])) { if (!(this.db = CLIENT)) { let url = defaults.url; @@ -101,7 +101,7 @@ MongoDB.prototype.open = async function () { } if (this.db.db) { - this.db = DB[this.id] = this.db.db(this.id); + this.db = Index[this.id] = this.db.db(this.id); } const collections = await this.db.listCollections().toArray(); @@ -126,7 +126,7 @@ MongoDB.prototype.open = async function () { MongoDB.prototype.close = function () { //CLIENT && CLIENT.close(); this.db = CLIENT = null; - DB[this.id] = null; + Index[this.id] = null; return this; }; diff --git a/dist/module-debug/db/postgres/db.js b/dist/module/db/postgres/index.js similarity index 99% rename from dist/module-debug/db/postgres/db.js rename to dist/module/db/postgres/index.js index 8c96b4b..f4713df 100644 --- a/dist/module-debug/db/postgres/db.js +++ b/dist/module/db/postgres/index.js @@ -61,9 +61,7 @@ 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); @@ -408,7 +406,8 @@ 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 + ")"; @@ -608,7 +607,7 @@ PostgresDB.prototype.commit = async function (flexsearch, _replace, _append) { // while(data.length){ // let next; // if(data.length > MAXIMUM_QUERY_VARS){ - + // next = data.slice(MAXIMUM_QUERY_VARS); // data = data.slice(0, MAXIMUM_QUERY_VARS); // } // let insert = pgp.helpers.insert(data, stmt); diff --git a/dist/module/db/redis/db.js b/dist/module/db/redis/index.js similarity index 100% rename from dist/module/db/redis/db.js rename to dist/module/db/redis/index.js diff --git a/dist/module/db/sqlite/db.js b/dist/module/db/sqlite/index.js similarity index 99% rename from dist/module/db/sqlite/db.js rename to dist/module/db/sqlite/index.js index 35df78b..82728eb 100644 --- a/dist/module/db/sqlite/db.js +++ b/dist/module/db/sqlite/index.js @@ -36,7 +36,7 @@ function sanitize(str) { // global transaction to keep track of database lock const TRX = Object.create(null), - DB = Object.create(null); + Index = Object.create(null); /** @@ -59,7 +59,7 @@ export default function SqliteDB(name, config = {}) { this.id = config.path || (":memory:" === name ? name : "flexsearch" + (name ? "-" + sanitize(name) : "") + ".sqlite"); this.field = config.field ? "_" + sanitize(config.field) : ""; this.support_tag_search = /* tag? */ /* stringify */ /* stringify */ /* single param */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; - this.db = config.db || DB[this.id] || null; + this.db = config.db || Index[this.id] || null; this.type = config.type ? types[config.type.toLowerCase()] : "string"; if (!this.type) throw new Error("Unknown type of ID '" + config.type + "'"); } @@ -77,7 +77,7 @@ SqliteDB.prototype.open = async function () { if (!this.db) { - if (!(this.db = DB[this.id])) { + if (!(this.db = Index[this.id])) { let filepath = this.id; if (":memory:" !== filepath) { @@ -89,7 +89,7 @@ SqliteDB.prototype.open = async function () { } } - this.db = DB[this.id] = new sqlite3.Database(filepath); + this.db = Index[this.id] = new sqlite3.Database(filepath); } } @@ -197,7 +197,7 @@ SqliteDB.prototype.open = async function () { SqliteDB.prototype.close = function () { this.db && this.db.close(); this.db = null; - DB[this.id] = null; + Index[this.id] = null; TRX[this.id] = null; return this; }; diff --git a/dist/module/document.js b/dist/module/document.js index 34c134c..00ab69c 100644 --- a/dist/module/document.js +++ b/dist/module/document.js @@ -454,20 +454,25 @@ Document.prototype.get = function (id) { if (this.db) { return this.index.get(this.field[0]).db.enrich(id).then(function (result) { - return result[0] && result[0].doc; + return result[0] && result[0].doc || null; }); } - return this.store.get(id); + return this.store.get(id) || null; }; /** - * @param {number|string} id + * @param {number|string|Object} id * @param {Object} data * @return {Document} */ Document.prototype.set = function (id, data) { + if ("object" == typeof id) { + data = id; + id = parse_simple(data, this.key); + } + this.store.set(id, data); return this; }; diff --git a/dist/module/encoder.js b/dist/module/encoder.js index 0d18ae0..ec7c94c 100644 --- a/dist/module/encoder.js +++ b/dist/module/encoder.js @@ -1,6 +1,6 @@ import { merge_option } from "./common.js"; -import normalize_polyfill from "./charset/normalize.js"; +import normalize_polyfill from "./charset/polyfill.js"; import { EncoderOptions } from "./type.js"; /* @@ -508,6 +508,11 @@ Encoder.prototype.encode = function (str) { return final; }; +export function fallback_encoder(str) { + + return str.normalize("NFKD").replace(normalize, "").toLowerCase().trim().split(/\s+/); +} + // Encoder.prototype.compress = function(str) { // // //return str; diff --git a/dist/module/index.js b/dist/module/index.js index 7c3c6be..de9ca8c 100644 --- a/dist/module/index.js +++ b/dist/module/index.js @@ -7,13 +7,13 @@ */ import { IndexOptions, ContextOptions, EncoderOptions } from "./type.js"; -import Encoder from "./encoder.js"; +import Encoder, { fallback_encoder } from "./encoder.js"; import Cache, { searchCache } from "./cache.js"; import Charset from "./charset.js"; import { KeystoreMap, KeystoreSet } from "./keystore.js"; import { is_array, is_string } from "./common.js"; import { exportIndex, importIndex, serialize } from "./serialize.js"; -import default_encoder from "./charset/latin/default.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"; @@ -39,7 +39,7 @@ export default function Index(options, _register) { let tmp = options.context; /** @type ContextOptions */ 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; + encoder = is_string(options.encoder) ? Charset[options.encoder] : options.encode || options.encoder || {} /*default_encoder*/; /** @type Encoder */ this.encoder = encoder.encode ? encoder : "object" == typeof encoder ? new Encoder( /** @type {EncoderOptions} */encoder) : { encode: encoder }; diff --git a/dist/module/index/search.js b/dist/module/index/search.js index 75d25a3..e6ba8b8 100644 --- a/dist/module/index/search.js +++ b/dist/module/index/search.js @@ -57,8 +57,7 @@ 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; @@ -91,8 +90,8 @@ Index.prototype.search = function (query, limit, options) { // fast path single context if (2 === length && context && !suggest) { - return single_term_query.call(this, query_terms[0], // term - query_terms[1], // ctx + return single_term_query.call(this, query_terms[1], // term + query_terms[0], // ctx limit, offset, resolve, enrich, tag); } diff --git a/doc/encoder.md b/doc/encoder.md index ec97871..7b53ab1 100644 --- a/doc/encoder.md +++ b/doc/encoder.md @@ -292,7 +292,7 @@ const index = new Index({ Stop-word filter is like a blacklist of words to be filtered out from indexing at all (e.g. "and", "to" or "be"). This is also very useful when using Context Search Set(["and", "to", "be"])
- function(str) => bool custom function
+ function(str) => bool custom function

encoder.addFilter("and") @@ -301,7 +301,7 @@ const index = new Index({ stemmer Stemmer will normalize several linguistic mutations of the same word (e.g. "run" and "running", or "property" and "properties"). This is also very useful when using Context Search - Map([["ing", ""], ["ies", "y"]])
+ Map([["ing", ""], ["ies", "y"]])

encoder.addStemmer("ing", "") @@ -310,7 +310,7 @@ const index = new Index({ mapper Mapper will replace a single char (e.g. "é" into "e") - Map([["é", "e"], ["ß", "ss"]])
+ Map([["é", "e"], ["ß", "ss"]])

encoder.addMapper("é", "e") @@ -319,7 +319,7 @@ const index = new Index({ matcher Matcher will do same as Mapper but instead of single chars it will replace char sequences - Map([["and", "&"], ["usd", "$"]])
+ Map([["and", "&"], ["usd", "$"]])

encoder.addMatcher("and", "&") @@ -328,7 +328,7 @@ const index = new Index({ replacer Replacer takes custom regular expressions and couldn't get optimized in the same way as Mapper or Matcher. You should take this as the last option when no other replacement can do the same. - [/[^a-z0-9]/g, "", /([^aeo])h(.)/g, "$1$2"])
+ [/[^a-z0-9]/g, "", /([^aeo])h(.)/g, "$1$2"])

encoder.addReplacer(/[^a-z0-9]/g, "") @@ -363,7 +363,7 @@ const index = new Index({ You can't extend to the built-in tokenizer "exact", "forward", "bidirectional" or "full". If nothing of them are applicable for your task you should tokenize everything inside your custom encoder function. -If you get some good results please feel free to share your encoder. +If you get some good results please feel free creating a pull request to share your encoder to the community. ### Encoder Processing Workflow @@ -381,7 +381,7 @@ If you get some good results please feel free to share your encoder. This workflow schema might help you to understand each step in the iteration:

- + ## Right-To-Left Support diff --git a/package-lock.json b/package-lock.json index f61cb45..9ef7d07 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.143", + "version": "0.8.147", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.143", + "version": "0.8.147", "funding": [ { "type": "github", diff --git a/package.json b/package.json index b8d7f4b..34ed0a4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.143", + "version": "0.8.147", "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", @@ -41,8 +41,8 @@ "require": "./dist/lang/*.min.js" }, "./db/*": { - "import": "./dist/module/db/*/db.js", - "require": "./dist/db/*/db.cjs" + "import": "./dist/module/db/*/index.js", + "require": "./dist/db/*/index.cjs" }, "./debug": { "import": "./dist/flexsearch.bundle.module.debug.js", @@ -73,7 +73,7 @@ "build:es5": "node task/build RELEASE=es5 DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false LANGUAGE_OUT=ECMASCRIPT5_STRICT", "build:es5:debug": "node task/build RELEASE=es5 DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT LANGUAGE_OUT=ECMASCRIPT5_STRICT", "build:lang": "node task/build RELEASE=lang", - "build:db": "npx rollup tmp/db/indexeddb/db.js --file dist/db/indexeddb/db.cjs --format cjs && npx rollup tmp/db/postgres/db.js --file dist/db/postgres/db.cjs --format cjs && npx rollup tmp/db/sqlite/db.js --file dist/db/sqlite/db.cjs --format cjs && npx rollup tmp/db/mongodb/db.js --file dist/db/mongodb/db.cjs --format cjs && npx rollup tmp/db/redis/db.js --file dist/db/redis/db.cjs --format cjs && npx rollup tmp/db/clickhouse/db.js --file dist/db/clickhouse/db.cjs --format cjs", + "build:db": "npx rollup tmp/db/indexeddb/index.js --file dist/db/indexeddb/index.cjs --format cjs && npx rollup tmp/db/postgres/index.js --file dist/db/postgres/index.cjs --format cjs && npx rollup tmp/db/sqlite/index.js --file dist/db/sqlite/index.cjs --format cjs && npx rollup tmp/db/mongodb/index.js --file dist/db/mongodb/index.cjs --format cjs && npx rollup tmp/db/redis/index.js --file dist/db/redis/index.cjs --format cjs && npx rollup tmp/db/clickhouse/index.js --file dist/db/clickhouse/index.cjs --format cjs", "build:module": "node task/babel && exit 0", "build:module:debug": "node task/babel DEBUG=true && exit 0", "build:module:min": "node task/babel RELEASE=min && exit 0", diff --git a/src/bundle.js b/src/bundle.js index 0cdd059..7f72476 100644 --- a/src/bundle.js +++ b/src/bundle.js @@ -31,7 +31,7 @@ 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/db.js"; +import IdxDB from "./db/indexeddb/index.js"; import Charset from "./charset.js"; import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; diff --git a/src/charset.js b/src/charset.js index 8b84572..e036fa8 100644 --- a/src/charset.js +++ b/src/charset.js @@ -1,15 +1,14 @@ import charset_latin_exact from "./charset/latin/exact.js"; -import charset_latin_default from "./charset/latin/default.js"; -import charset_latin_simple from "./charset/latin/simple.js"; +import charset_latin_normalize from "./charset/latin/normalize.js"; import charset_latin_balance from "./charset/latin/balance.js"; import charset_latin_advanced from "./charset/latin/advanced.js"; import charset_latin_extra from "./charset/latin/extra.js"; import charset_latin_soundex from "./charset/latin/soundex.js"; -// all charset +// universal charset export const Exact = charset_latin_exact; -export const Default = charset_latin_default; -export const Normalize = charset_latin_simple; +export const Default = charset_latin_normalize; +export const Normalize = charset_latin_normalize; // latin charset export const LatinBalance = charset_latin_balance; export const LatinAdvanced = charset_latin_advanced; @@ -17,14 +16,14 @@ export const LatinExtra = charset_latin_extra; export const LatinSoundex = charset_latin_soundex; // deprecated export const LatinExact = charset_latin_exact; -export const LatinDefault = charset_latin_default; -export const LatinSimple = charset_latin_simple; +export const LatinDefault = charset_latin_normalize; +export const LatinSimple = charset_latin_normalize; export default { - // all charset + // universal charset Exact: charset_latin_exact, - Default: charset_latin_default, - Normalize: charset_latin_simple, + Default: charset_latin_normalize, + Normalize: charset_latin_normalize, // latin charset LatinBalance: charset_latin_balance, LatinAdvanced: charset_latin_advanced, @@ -32,6 +31,6 @@ export default { LatinSoundex: charset_latin_soundex, // deprecated LatinExact: charset_latin_exact, - LatinDefault: charset_latin_default, - LatinSimple: charset_latin_simple, + LatinDefault: charset_latin_normalize, + LatinSimple: charset_latin_normalize }; diff --git a/src/charset/latin/advanced.js b/src/charset/latin/advanced.js index 145a9ea..9abb73b 100644 --- a/src/charset/latin/advanced.js +++ b/src/charset/latin/advanced.js @@ -25,7 +25,7 @@ export const replacer = [ /** @type EncoderOptions */ const options = { - normalize: true, + //normalize: true, dedupe: true, mapper: soundex, matcher: matcher, diff --git a/src/charset/latin/balance.js b/src/charset/latin/balance.js index c6e24b6..7d42731 100644 --- a/src/charset/latin/balance.js +++ b/src/charset/latin/balance.js @@ -40,7 +40,7 @@ export const soundex = new Map([ /** @type EncoderOptions */ const options = { - normalize: true, + //normalize: true, dedupe: true, mapper: soundex }; diff --git a/src/charset/latin/exact.js b/src/charset/latin/exact.js index 5f7adb2..d9fa4fc 100644 --- a/src/charset/latin/exact.js +++ b/src/charset/latin/exact.js @@ -3,8 +3,8 @@ import { EncoderOptions } from "../../type.js"; /** @type EncoderOptions */ const options = { normalize: false, - numeric: false, - split: /\s+/ + numeric: false + //split: /\s+/ //normalize: false, //dedupe: false }; diff --git a/src/charset/latin/extra.js b/src/charset/latin/extra.js index 5014c03..31512c9 100644 --- a/src/charset/latin/extra.js +++ b/src/charset/latin/extra.js @@ -8,7 +8,7 @@ export const compact = [ /** @type EncoderOptions */ const options = { - normalize: true, + //normalize: true, dedupe: true, mapper: soundex, replacer: replacer.concat(compact), diff --git a/src/charset/latin/default.js b/src/charset/latin/normalize.js similarity index 90% rename from src/charset/latin/default.js rename to src/charset/latin/normalize.js index 3fd6dd9..ea36514 100644 --- a/src/charset/latin/default.js +++ b/src/charset/latin/normalize.js @@ -2,7 +2,7 @@ import { EncoderOptions } from "../../type.js"; /** @type EncoderOptions */ const options = { - normalize: true + //normalize: true // normalize: function(str){ // return str.toLowerCase(); // }, diff --git a/src/charset/latin/simple.js b/src/charset/latin/simple.js deleted file mode 100644 index 92e463f..0000000 --- a/src/charset/latin/simple.js +++ /dev/null @@ -1,8 +0,0 @@ -import { EncoderOptions } from "../../type.js"; - -/** @type EncoderOptions */ -const options = { - normalize: true, - dedupe: true -}; -export default options; diff --git a/src/charset/latin/soundex.js b/src/charset/latin/soundex.js index 8de08be..610a7ab 100644 --- a/src/charset/latin/soundex.js +++ b/src/charset/latin/soundex.js @@ -2,7 +2,7 @@ import { EncoderOptions } from "../../type.js"; /** @type {EncoderOptions} */ const options = { - normalize: true, + //normalize: true, dedupe: false, include: { letter: true diff --git a/src/charset/normalize.js b/src/charset/polyfill.js similarity index 100% rename from src/charset/normalize.js rename to src/charset/polyfill.js diff --git a/src/db/clickhouse/db.js b/src/db/clickhouse/index.js similarity index 99% rename from src/db/clickhouse/db.js rename to src/db/clickhouse/index.js index 80b0640..8c913e9 100644 --- a/src/db/clickhouse/db.js +++ b/src/db/clickhouse/index.js @@ -47,7 +47,7 @@ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_]/g, ""); } -let DB; +let Index; /** * @constructor @@ -74,7 +74,7 @@ export default function ClickhouseDB(name, config = {}){ if(!this.type) throw new Error("Unknown type of ID '" + config.type + "'"); //this.trx = false; this.support_tag_search = true; - this.db = DB || (DB = config.db || null); + this.db = Index || (Index = config.db || null); Object.assign(defaults, config); config.database && (defaults.config.database = config.database); this.db && delete defaults.db; @@ -93,8 +93,8 @@ ClickhouseDB.prototype.mount = function(flexsearch){ ClickhouseDB.prototype.open = async function(){ if(!this.db) { - this.db = DB || ( - DB = new ClickHouse(defaults) + this.db = Index || ( + Index = new ClickHouse(defaults) ); } @@ -176,7 +176,7 @@ ClickhouseDB.prototype.open = async function(){ ClickhouseDB.prototype.close = function(){ //DB && DB.close(); - this.db = DB = null; + this.db = Index = null; return this; }; diff --git a/src/db/clickhouse/package.json b/src/db/clickhouse/package.json index da81e64..0a25556 100644 --- a/src/db/clickhouse/package.json +++ b/src/db/clickhouse/package.json @@ -3,7 +3,7 @@ "preferGlobal": false, "name": "flexsearch-clickhouse", "version": "0.1.0", - "main": "db.js", + "main": "index.js", "dependencies": { "clickhouse": "^2.6.0" } diff --git a/src/db/indexeddb/db.js b/src/db/indexeddb/index.js similarity index 98% rename from src/db/indexeddb/db.js rename to src/db/indexeddb/index.js index 8c73606..6842441 100644 --- a/src/db/indexeddb/db.js +++ b/src/db/indexeddb/index.js @@ -40,7 +40,7 @@ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); } -const DB = create_object(); +const Index = create_object(); /** * @param {string|PersistentOptions=} name @@ -88,8 +88,8 @@ IdxDB.prototype.open = function(){ // return this.db = new Promise(function(resolve, reject){ - DB[self.id] || (DB[self.id] = []); - DB[self.id].push(self.field); + Index[self.id] || (Index[self.id] = []); + Index[self.id].push(self.field); const req = IndexedDB.open(self.id, VERSION); @@ -105,8 +105,8 @@ IdxDB.prototype.open = function(){ // IndexedDB is such a poor contribution :( for(let i = 0, ref; i < fields.length; i++){ ref = fields[i]; - for(let j = 0, field; j < DB[self.id].length; j++){ - field = DB[self.id][j]; + for(let j = 0, field; j < Index[self.id].length; j++){ + field = Index[self.id][j]; db.objectStoreNames.contains(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")) || db.createObjectStore(ref + (ref !== "reg" ? (field ? ":" + field : "") : ""));//{ autoIncrement: true /*keyPath: "id"*/ } //.createIndex("idx", "ids", { multiEntry: true, unique: false }); @@ -191,8 +191,8 @@ IdxDB.prototype.clear = function(){ for(let i = 0, ref; i < fields.length; i++){ ref = fields[i]; - for(let j = 0, field; j < DB[this.id].length; j++){ - field = DB[this.id][j]; + for(let j = 0, field; j < Index[this.id].length; j++){ + field = Index[this.id][j]; stores.push(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")); } } diff --git a/src/db/mongodb/db.js b/src/db/mongodb/index.js similarity index 98% rename from src/db/mongodb/db.js rename to src/db/mongodb/index.js index dbdbb3f..39d41c9 100644 --- a/src/db/mongodb/db.js +++ b/src/db/mongodb/index.js @@ -15,7 +15,7 @@ function sanitize(str) { } let CLIENT; -let DB = Object.create(null); +let Index = Object.create(null); /** * @constructor @@ -36,7 +36,7 @@ export default function MongoDB(name, config = {}){ this.id = "flexsearch" + (name ? "-" + sanitize(name) : ""); this.field = config.field ? "-" + sanitize(config.field) : ""; this.type = config.type || ""; - this.db = config.db || DB[this.id] || CLIENT || null; + this.db = config.db || Index[this.id] || CLIENT || null; this.trx = false; this.support_tag_search = true; Object.assign(defaults, config); @@ -85,7 +85,7 @@ async function createCollection(db, ref, field){ MongoDB.prototype.open = async function(){ if(!this.db){ - if(!(this.db = DB[this.id])){ + if(!(this.db = Index[this.id])){ if(!(this.db = CLIENT)){ let url = defaults.url; @@ -101,7 +101,7 @@ MongoDB.prototype.open = async function(){ } if(this.db.db){ - this.db = DB[this.id] = this.db.db(this.id); + this.db = Index[this.id] = this.db.db(this.id); } const collections = await this.db.listCollections().toArray(); @@ -125,7 +125,7 @@ MongoDB.prototype.open = async function(){ MongoDB.prototype.close = function(){ //CLIENT && CLIENT.close(); this.db = CLIENT = null; - DB[this.id] = null; + Index[this.id] = null; return this; }; diff --git a/src/db/mongodb/package.json b/src/db/mongodb/package.json index 3842248..7b8a20d 100644 --- a/src/db/mongodb/package.json +++ b/src/db/mongodb/package.json @@ -3,7 +3,7 @@ "preferGlobal": false, "name": "flexsearch-mongodb", "version": "0.1.0", - "main": "db.js", + "main": "index.js", "dependencies": { "mongodb": "^6.13.0" } diff --git a/src/db/postgres/db.js b/src/db/postgres/index.js similarity index 100% rename from src/db/postgres/db.js rename to src/db/postgres/index.js diff --git a/src/db/postgres/package.json b/src/db/postgres/package.json index 6680183..77492ee 100644 --- a/src/db/postgres/package.json +++ b/src/db/postgres/package.json @@ -3,7 +3,7 @@ "preferGlobal": false, "name": "flexsearch-postgres", "version": "0.1.0", - "main": "db.js", + "main": "index.js", "dependencies": { "pg-promise": "^11.10.2" } diff --git a/src/db/redis/db.js b/src/db/redis/index.js similarity index 100% rename from src/db/redis/db.js rename to src/db/redis/index.js diff --git a/src/db/redis/package.json b/src/db/redis/package.json index 6b5cadb..1ae1c71 100644 --- a/src/db/redis/package.json +++ b/src/db/redis/package.json @@ -3,7 +3,7 @@ "preferGlobal": false, "name": "flexsearch-redis", "version": "0.1.0", - "main": "db.js", + "main": "index.js", "dependencies": { "redis": "^4.7.0" } diff --git a/src/db/sqlite/db.js b/src/db/sqlite/index.js similarity index 99% rename from src/db/sqlite/db.js rename to src/db/sqlite/index.js index 70a09f0..9f83589 100644 --- a/src/db/sqlite/db.js +++ b/src/db/sqlite/index.js @@ -35,7 +35,7 @@ function sanitize(str) { // global transaction to keep track of database lock const TRX = Object.create(null); -const DB = Object.create(null); +const Index = Object.create(null); /** * @constructor @@ -61,7 +61,7 @@ export default function SqliteDB(name, config = {}){ ); this.field = config.field ? "_" + sanitize(config.field) : ""; this.support_tag_search = true; - this.db = config.db || DB[this.id] || null; + this.db = config.db || Index[this.id] || null; this.type = config.type ? types[config.type.toLowerCase()] : "string"; if(!this.type) throw new Error("Unknown type of ID '" + config.type + "'"); }; @@ -79,7 +79,7 @@ SqliteDB.prototype.open = async function(){ if(!this.db){ - if(!(this.db = DB[this.id])){ + if(!(this.db = Index[this.id])){ let filepath = this.id; if(filepath !== ":memory:"){ @@ -91,7 +91,7 @@ SqliteDB.prototype.open = async function(){ } } - this.db = DB[this.id] = new sqlite3.Database(filepath); + this.db = Index[this.id] = new sqlite3.Database(filepath); } } @@ -201,7 +201,7 @@ SqliteDB.prototype.open = async function(){ SqliteDB.prototype.close = function(){ this.db && this.db.close(); this.db = null; - DB[this.id] = null; + Index[this.id] = null; TRX[this.id] = null; return this; }; diff --git a/src/db/sqlite/package.json b/src/db/sqlite/package.json index e1d276d..7364563 100644 --- a/src/db/sqlite/package.json +++ b/src/db/sqlite/package.json @@ -3,7 +3,7 @@ "preferGlobal": false, "name": "flexsearch-sqlite", "version": "0.1.0", - "main": "db.js", + "main": "index.js", "dependencies": { "sqlite3": "^5.1.7" } diff --git a/src/document.js b/src/document.js index e3f535c..b298167 100644 --- a/src/document.js +++ b/src/document.js @@ -522,7 +522,7 @@ if(SUPPORT_STORE){ */ Document.prototype.set = function(id, data){ - if(is_object(id)){ + if(typeof id === "object"){ data = id; id = parse_simple(data, this.key); } diff --git a/src/encoder.js b/src/encoder.js index 217db51..6338d31 100644 --- a/src/encoder.js +++ b/src/encoder.js @@ -6,7 +6,7 @@ import { } from "./config.js"; // <-- COMPILER BLOCK import { merge_option } from "./common.js"; -import normalize_polyfill from "./charset/normalize.js"; +import normalize_polyfill from "./charset/polyfill.js"; import { EncoderOptions } from "./type.js"; /* @@ -556,6 +556,11 @@ Encoder.prototype.encode = function(str){ return final; }; +export function fallback_encoder(str){ + + return str.normalize("NFKD").replace(normalize, "").toLowerCase().trim().split(/\s+/); +} + // Encoder.prototype.compress = function(str) { // // //return str; diff --git a/src/index.js b/src/index.js index 797311c..76c73b8 100644 --- a/src/index.js +++ b/src/index.js @@ -23,13 +23,14 @@ import { // <-- COMPILER BLOCK import { IndexOptions, ContextOptions, EncoderOptions } from "./type.js"; -import Encoder from "./encoder.js"; +import Encoder, { fallback_encoder } from "./encoder.js"; import Cache, { searchCache } from "./cache.js"; import Charset from "./charset.js"; import { KeystoreMap, KeystoreSet } from "./keystore.js"; import { is_array, is_string } from "./common.js"; import { exportIndex, importIndex, serialize } from "./serialize.js"; -import default_encoder from "./charset/latin/default.js"; +import { remove_index } from "./index/remove.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"; @@ -65,13 +66,10 @@ export default function Index(options, _register){ ? { depth: 1 } : tmp || {} ); - const encoder = SUPPORT_CHARSET && is_string(options.encoder) ? Charset[options.encoder] : options.encode || options.encoder || ( - SUPPORT_ENCODER ? default_encoder : function(str){ - return str.toLowerCase().trim().split(/\s+/); - } + SUPPORT_ENCODER ? {} /*default_encoder*/ : fallback_encoder ); /** @type Encoder */ this.encoder = encoder.encode @@ -221,31 +219,31 @@ Index.prototype.update = function(id, content){ : this.add(id, content); }; -/** - * @param map - * @return {number} - */ - -function cleanup_index(map){ - - let count = 0; - - if(is_array(map)){ - for(let i = 0, arr; i < map.length; i++){ - (arr = map[i]) && - (count += arr.length); - } - } - else for(const item of map.entries()){ - const key = item[0]; - const value = item[1]; - const tmp = cleanup_index(value); - tmp ? count += tmp - : map.delete(key); - } - - return count; -} +// /** +// * @param map +// * @return {number} +// */ +// +// function cleanup_index(map){ +// +// let count = 0; +// +// if(is_array(map)){ +// for(let i = 0, arr; i < map.length; i++){ +// (arr = map[i]) && +// (count += arr.length); +// } +// } +// else for(const item of map.entries()){ +// const key = item[0]; +// const value = item[1]; +// const tmp = cleanup_index(value); +// tmp ? count += tmp +// : map.delete(key); +// } +// +// return count; +// } Index.prototype.cleanup = function(){ @@ -254,9 +252,11 @@ Index.prototype.cleanup = function(){ return this; } - cleanup_index(this.map); + remove_index(this.map); + //cleanup_index(this.map); this.depth && - cleanup_index(this.ctx); + //cleanup_index(this.ctx); + remove_index(this.ctx); return this; }; diff --git a/src/index/remove.js b/src/index/remove.js index 905f76a..7c2c354 100644 --- a/src/index/remove.js +++ b/src/index/remove.js @@ -111,35 +111,43 @@ Index.prototype.remove = function(id, _skip_deletion){ }; /** + * When called without passing ID it just will clean up * @param {!Map|Array>} map - * @param {!number|string} id + * @param {!number|string=} id * @return {number} */ -function remove_index(map, id){ +export function remove_index(map, id){ // a check counter of filled resolution slots // to prevent removing the field let count = 0; + let cleanup = typeof id === "undefined"; if(is_array(map)){ for(let x = 0, arr, index; x < map.length; x++){ if((arr = map[x]) && arr.length){ - index = arr.indexOf(id); - if(index >= 0){ - if(arr.length > 1){ - arr.splice(index, 1); - count++; - } - else{ - // remove resolution slot - delete map[x]; - } - // the index key:[res, id] is unique - break; + if(cleanup){ + //count += arr.length; + count++; } else{ - count++; + index = arr.indexOf(id); + if(index >= 0){ + if(arr.length > 1){ + arr.splice(index, 1); + count++; + } + else{ + // remove resolution slot + delete map[x]; + } + // the index key:[res, id] is unique + break; + } + else{ + count++; + } } } } diff --git a/src/index/search.js b/src/index/search.js index 7283502..d340839 100644 --- a/src/index/search.js +++ b/src/index/search.js @@ -88,8 +88,7 @@ Index.prototype.search = function(query, limit, options){ // fast path single term if(length === 1){ - return single_term_query.call( - this, + return single_term_query.call(this, query_terms[0], // term "", // ctx limit, @@ -107,10 +106,9 @@ Index.prototype.search = function(query, limit, options){ // fast path single context if(length === 2 && context && !suggest){ - return single_term_query.call( - this, - query_terms[0], // term - query_terms[1], // ctx + return single_term_query.call(this, + query_terms[1], // term + query_terms[0], // ctx limit, offset, resolve, diff --git a/src/intersect.js b/src/intersect.js index 9af00e3..bc7db6e 100644 --- a/src/intersect.js +++ b/src/intersect.js @@ -83,11 +83,10 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res // 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; + return offset + ? tmp.slice(offset) + : tmp; } } } @@ -207,7 +206,7 @@ export function union(arrays, limit, offset, resolve, boost){ // adjust score to reduce resolution of suggestions // todo: instead of applying the resolve task directly it could // be added to the chain and resolved later, that will keep - // the original score but also can't resolve early because of + // the original score but also can't resolve early when // nothing was found let score = (k + (i < arr_len - 1 ? boost || 0 : 0)) / (i + 1) | 0; let arr = result[score] || (result[score] = []); diff --git a/test/context.js b/test/context.js index eb8dc48..a8dad3f 100644 --- a/test/context.js +++ b/test/context.js @@ -12,7 +12,7 @@ const Charset = _Charset || (await import("../src/charset.js")).default; describe("Context", function(){ - it("Should have been added properly to the context", function(){ + it("Should have been added properly to the context (bidirectional enabled)", function(){ let index = new Index({ tokenize: "strict", @@ -26,13 +26,20 @@ describe("Context", function(){ expect(index.reg.size).to.equal(1); expect(index.search("zero one")).to.include(0); expect(index.search("zero two")).to.include(0); + // breaks the context chain: expect(index.search("zero three").length).to.equal(0); + expect(index.search("zero three", { suggest: true })).to.include(0); + // breaks the context chain: expect(index.search("three seven").length).to.equal(0); + expect(index.search("three seven", { suggest: true })).to.include(0); expect(index.search("three five seven")).to.include(0); + // bidirectional: expect(index.search("eight six four")).to.include(0); expect(index.search("seven five three")).to.include(0); expect(index.search("three foobar seven").length).to.equal(0); + expect(index.search("three foobar seven", { suggest: true })).to.include(0); expect(index.search("seven foobar three").length).to.equal(0); + expect(index.search("seven foobar three", { suggest: true })).to.include(0); expect(index.search("eight ten")).to.include(0); expect(index.search("ten nine seven eight six five three four two zero one")).to.include(0); @@ -42,6 +49,7 @@ describe("Context", function(){ expect(index.search("1 5")).to.include(1); expect(index.search("2 4 1")).to.include(1); + // disable bidirectional index = new Index({ tokenize: "strict", context: { @@ -53,4 +61,41 @@ describe("Context", function(){ index.add(0, "zero one two three four five six seven eight nine ten"); expect(index.search("ten nine seven eight six five three four two zero one").length).to.equal(0); }); + + it("Should have been added properly to the context when bidirectional was disabled", function(){ + + let index = new Index({ + tokenize: "strict", + context: { + depth: 2, + bidirectional: false + } + }); + + index.add(1, "1 2 3 4 5 6 7 8 9"); + expect(index.search("3 1").length).to.equal(0); + expect(index.search("4 3 2").length).to.equal(0); + }); + + it("Should have been added properly when dupes will break the context chain", function(){ + + const index = new Index({ + context: { + depth: 2 + } + }); + + index.add(1, "1 2 3 4 5 6 7 8 1 2 9"); + + expect(index.search("1 9")).to.include(1); + expect(index.search("1 2 9")).to.include(1); + expect(index.search("9 1 2")).to.include(1); + + // todo shuffled chain: + //expect(index.search("1 3 9")).to.include(1); + expect(index.search("3 1 9")).to.include(1); + expect(index.search("9 1 3")).to.include(1); + // todo shuffled chain: + //expect(index.search("9 3 1")).to.include(1); + }); }); diff --git a/test/encoder.js b/test/encoder.js index 99c3a58..694aa00 100644 --- a/test/encoder.js +++ b/test/encoder.js @@ -43,7 +43,7 @@ describe("Encoder: Charset", function(){ const index = new Index({ encoder: Charset.Exact }); expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql( - ["Björn-Phillipp", "Mayer"] + ["Björn", "Phillipp", "Mayer"] ); }); diff --git a/test/persistent.js b/test/persistent.js index 897434f..e12ccdc 100644 --- a/test/persistent.js +++ b/test/persistent.js @@ -227,15 +227,31 @@ export default function(DB, DBClass){ // mount database to the index //await db.mount(document); //expect(document.index.get("primaryTitle").db).to.be.instanceof(db.constructor); - //document.clear(); + //await document.clear(); // add test data for(let i = 0; i < data.length; i++){ document.add(data[i]); } + expect(document.index.get("primaryTitle").reg.size).to.equal(2); + expect(document.index.get("primaryTitle").map.size).to.equal(25); + expect(document.index.get("originalTitle").reg.size).to.equal(2); + expect(document.index.get("originalTitle").map.size).to.equal(25); + // tag pseudo indexes (persistent only) + expect(document.index.get("startYear").reg.size).to.equal(2); + expect(document.index.get("startYear").map.size).to.equal(0); + expect(document.index.get("genres").reg.size).to.equal(2); + expect(document.index.get("genres").map.size).to.equal(0); + expect(document.reg.size).to.equal(2); + expect(document.store.size).to.equal(2); + expect(document.tag.size).to.equal(2); + expect(document.tag.get("startYear").size).to.equal(2); + expect(document.tag.get("genres").size).to.equal(3); + // transfer changes in bulk await document.commit(); + //await new Promise(resolve => setTimeout(resolve, 200)); expect(document.index.get("primaryTitle").reg.size).to.equal(0); expect(document.index.get("primaryTitle").map.size).to.equal(0); diff --git a/test/scoring.js b/test/scoring.js index 3f2d4d5..8dfa20d 100644 --- a/test/scoring.js +++ b/test/scoring.js @@ -42,8 +42,8 @@ describe("Scoring", function(){ expect(index.search("1")).to.eql([0]); expect(index.search("one")).to.eql([1, 2]); - expect(index.search("one two")).to.eql([2]); // 1: no bi-directional - expect(index.search("four one")).to.eql([1]); // 2: no bi-directional + expect(index.search("one two")).to.eql([1]); // 2 => no bi-directional + expect(index.search("four one")).to.eql([2]); // 1 => no bi-directional index = new Index({ tokenize: "strict",