From 471830ef0f36c291e74ad0af2992252b36736100 Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Wed, 26 Mar 2025 09:40:20 +0100 Subject: [PATCH] fix indexeddb #479 --- README.md | 14 +- dist/db/clickhouse/index.cjs | 28 +- dist/db/indexeddb/index.js | 122 +- dist/db/mongodb/index.cjs | 50 +- dist/db/sqlite/index.cjs | 4 +- dist/flexsearch.bundle.debug.js | 121 +- dist/flexsearch.bundle.min.js | 106 +- dist/flexsearch.bundle.module.debug.js | 121 +- dist/flexsearch.bundle.module.min.js | 106 +- dist/flexsearch.compact.debug.js | 2 +- dist/flexsearch.compact.min.js | 2 +- dist/flexsearch.compact.module.debug.js | 2 +- dist/flexsearch.compact.module.min.js | 2 +- dist/flexsearch.es5.debug.js | 1115 ++++++++--------- dist/flexsearch.es5.min.js | 46 +- dist/flexsearch.light.debug.js | 2 +- dist/flexsearch.light.min.js | 2 +- dist/flexsearch.light.module.debug.js | 2 +- dist/flexsearch.light.module.min.js | 2 +- dist/module-debug/db/clickhouse/index.js | 18 +- dist/module-debug/db/indexeddb/index.js | 178 +-- dist/module-debug/db/mongodb/index.js | 37 +- dist/module-debug/db/postgres/index.js | 5 +- dist/module-debug/db/sqlite/index.js | 4 +- dist/module-debug/document.js | 2 +- dist/module-min/db/clickhouse/index.js | 6 +- dist/module-min/db/indexeddb/index.js | 2 +- dist/module-min/db/mongodb/index.js | 2 +- dist/module-min/db/sqlite/index.js | 2 +- dist/module-min/document.js | 2 +- dist/module/db/clickhouse/index.js | 18 +- dist/module/db/indexeddb/index.js | 178 +-- dist/module/db/mongodb/index.js | 37 +- dist/module/db/postgres/index.js | 5 +- dist/module/db/sqlite/index.js | 4 +- dist/module/document.js | 2 +- .../package.json | 2 +- .../package.json | 2 +- package-lock.json | 4 +- package.json | 2 +- src/db/clickhouse/index.js | 28 +- src/db/indexeddb/index.js | 122 +- src/db/mongodb/index.js | 50 +- src/db/sqlite/index.js | 4 +- src/document.js | 2 +- src/document/search.js | 2 +- 46 files changed, 1311 insertions(+), 1258 deletions(-) diff --git a/README.md b/README.md index 9baab2c..55d64d9 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ FlexSearch v0.8: [Overview and Migration Guide](doc/0.8.0.md) - + @@ -553,7 +553,7 @@ Or import FlexSearch members separately by: ```html @@ -569,7 +569,7 @@ Use non-bundled modules: import Charset from "./dist/module/charset.js"; import Resolver from "./dist/module/resolver.js"; import Worker from "./dist/module/worker.js"; - import IdxDB from "./dist/module/db/indexeddb/index.js"; + import IndexedDB from "./dist/module/db/indexeddb/index.js"; const index = new Index(/* ... */); ``` @@ -611,11 +611,15 @@ const index = new FlexSearch.Index(/* ... */); Or require FlexSearch members separately by: ```js -const { Index, Document, Encoder, Charset, Resolver, Worker, IdxDB } = require("flexsearch"); +const { Index, Document, Encoder, Charset, Resolver, Worker, IndexedDB } = require("flexsearch"); const index = new Index(/* ... */); ``` -When you are using ESM in Node.js then just use the Modules explained one section above. +When using ESM instead of CommonJS: +```js +import { Index, Document, Encoder, Charset, Resolver, Worker, IndexedDB } from "flexsearch"; +const index = new FlexSearch.Index(/* ... */); +``` Language packs are accessible via: diff --git a/dist/db/clickhouse/index.cjs b/dist/db/clickhouse/index.cjs index 81e9a05..e0f86a3 100644 --- a/dist/db/clickhouse/index.cjs +++ b/dist/db/clickhouse/index.cjs @@ -362,13 +362,13 @@ ClickhouseDB.prototype.enrich = async function(ids){ ClickhouseDB.prototype.has = async function(id){ const result = await this.db.query(` - SELECT 1 as exist + SELECT 1 FROM ${this.id}.reg WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}} LIMIT 1`, { params: { id }} ).toPromise(); - return !!(result && result[0] && result[0].exist); + return !!(result && result[0] && result[0]["1"]); }; ClickhouseDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ @@ -554,6 +554,8 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ return; } + const promises = []; + if(flexsearch.map.size){ let data = []; for(const item of flexsearch.map){ @@ -575,9 +577,9 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.insert( + promises.push(this.db.insert( `INSERT INTO ${ this.id }.map${ this.field } (key, res, id)`, data - ).toPromise(); + ).toPromise()); } } @@ -606,9 +608,9 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.insert( + promises.push(this.db.insert( `INSERT INTO ${ this.id }.ctx${ this.field } (ctx, key, res, id)`, data - ).toPromise(); + ).toPromise()); } } @@ -623,9 +625,9 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.insert( + promises.push(this.db.insert( `INSERT INTO ${this.id}.tag${ this.field } (tag, id)`, data - ).toPromise(); + ).toPromise()); } } @@ -637,9 +639,9 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ data.push({ id, doc: doc && JSON.stringify(doc) }); } if(data.length){ - await this.db.insert( + promises.push(this.db.insert( `INSERT INTO ${this.id}.reg (id, doc)`, data - ).toPromise(); + ).toPromise()); } } else if(!flexsearch.bypass){ @@ -648,9 +650,9 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ data[i] = { id: data[i] }; } if(data.length){ - await this.db.insert( + promises.push(this.db.insert( `INSERT INTO ${this.id}.reg (id)`, data - ).toPromise(); + ).toPromise()); } } @@ -673,6 +675,8 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ // }) // }]).toPromise(); + await Promise.all(promises); + flexsearch.map.clear(); flexsearch.ctx.clear(); flexsearch.tag && diff --git a/dist/db/indexeddb/index.js b/dist/db/indexeddb/index.js index 1076298..af63e6d 100644 --- a/dist/db/indexeddb/index.js +++ b/dist/db/indexeddb/index.js @@ -82,17 +82,20 @@ IdxDB.prototype.mount = function(flexsearch){ IdxDB.prototype.open = function(){ + if(this.db) return this.db; let self = this; navigator.storage && navigator.storage.persist(); - return this.db || (this.db = new Promise(function(resolve, reject){ + // return this.db = new Promise(function(resolve, reject){ DB[self.id] || (DB[self.id] = []); DB[self.id].push(self.field); const req = IndexedDB.open(self.id, VERSION); + + /** @this {IDBOpenDBRequest} */ req.onupgradeneeded = function(event){ const db = self.db = this.result; @@ -122,28 +125,36 @@ IdxDB.prototype.open = function(){ // } }; - req.onblocked = function(event) { - // this event shouldn't trigger if we handle onversionchange correctly - // it means that there's another open connection to the same database - // and it wasn't closed after db.onversionchange triggered for it - console.error("blocked", event); - reject(); - }; - - req.onerror = function(event){ - console.error(this.error, event); - reject(); - }; - - req.onsuccess = function(event){ - self.db = this.result; //event.target.result; + return self.db = promisfy(req, function(result){ + self.db = result; //event.target.result; self.db.onversionchange = function(){ //database is outdated self.close(); }; - resolve(self); - }; - })); + }); + + // req.onblocked = function(event) { + // // this event shouldn't trigger if we handle onversionchange correctly + // // it means that there's another open connection to the same database + // // and it wasn't closed after db.onversionchange triggered for it + // console.error("blocked", event); + // reject(); + // }; + // + // req.onerror = function(event){ + // console.error(this.error, event); + // reject(); + // }; + // + // req.onsuccess = function(event){ + // self.db = this.result; //event.target.result; + // self.db.onversionchange = function(){ + // //database is outdated + // self.close(); + // }; + // resolve(self); + // }; + // }); }; IdxDB.prototype.close = function(){ @@ -338,31 +349,37 @@ IdxDB.prototype.transaction = function(ref, modifier, task){ */ let store = this.trx[key + ":" + modifier]; if(store) return task.call(this, store); - let transaction = this.db.transaction(key, modifier); /** * @type {IDBObjectStore} */ this.trx[key + ":" + modifier] = store = transaction.objectStore(key); + const promise = task.call(this, store); + this.trx[key + ":" + modifier] = null; - return new Promise((resolve, reject) => { - transaction.onerror = (err) => { - transaction.abort(); - transaction = store = null; - reject(err); - //db.close; - }; - transaction.oncomplete = (res) => { - transaction = store = null; - resolve(res || true); - //db.close; - }; - const promise = task.call(this, store); - // transactions can just be used within the same event loop - // the indexeddb is such a stupid tool :( - this.trx[key + ":" + modifier] = null; + return promisfy(transaction).finally(function(){ + transaction = store = null; return promise; }); + + // return new Promise((resolve, reject) => { + // transaction.onerror = (err) => { + // transaction.abort(); + // transaction = store = null; + // reject(err); + // //db.close; + // }; + // transaction.oncomplete = (res) => { + // transaction = store = null; + // resolve(res || true); + // //db.close; + // }; + // const promise = task.call(this, store); + // // transactions can just be used within the same event loop + // // the indexeddb is such a stupid tool :( + // this.trx[key + ":" + modifier] = null; + // return promise; + // }); }; IdxDB.prototype.commit = async function(flexsearch, _replace, _append){ @@ -587,7 +604,6 @@ function handle(cursor, ids, _tag){ const arr = cursor.value; let changed; - let parse; let count = 0; for(let x = 0, result; x < arr.length; x++){ @@ -595,11 +611,7 @@ function handle(cursor, ids, _tag){ if((result = _tag ? arr : arr[x])){ for(let i = 0, pos, id; i < ids.length; i++){ id = ids[i]; - pos = result.indexOf(parse ? parseInt(id, 10) : id); - if(pos < 0 && !parse && typeof id === "string" && !isNaN(id)){ - pos = result.indexOf(parseInt(id, 10)); - pos && (parse = 1); - } + pos = result.indexOf(id); if(pos >= 0){ changed = 1; if(result.length > 1){ @@ -618,12 +630,10 @@ function handle(cursor, ids, _tag){ } if(!count){ - cursor.delete(); //store.delete(cursor.key); } else if(changed){ - //await new Promise(resolve => { cursor.update(arr);//.onsuccess = resolve; //}); @@ -638,31 +648,33 @@ function handle(cursor, ids, _tag){ */ IdxDB.prototype.remove = function(ids){ + const self = this; + if(typeof ids !== "object"){ ids = [ids]; } return /** @type {!Promise} */(Promise.all([ - this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ + self.transaction("map", "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids); }; }), - this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ + self.transaction("ctx", "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids); }; }), - this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ + self.transaction("tag", "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids, /* tag? */ true); }; }), // let filtered = []; - this.transaction("reg", "readwrite", function(store){ + self.transaction("reg", "readwrite", function(store){ for(let i = 0; i < ids.length; i++){ store.delete(ids[i]); } @@ -688,21 +700,21 @@ IdxDB.prototype.remove = function(ids){ }; /** - * @param {IDBRequest} req + * @param {IDBRequest|IDBOpenDBRequest} req * @param {Function=} callback * @return {!Promise} */ function promisfy(req, callback){ return new Promise((resolve, reject) => { - /** @this {IDBRequest} */ - req.onsuccess = function(){ + // oncomplete is used for transaction + /** @this {IDBRequest|IDBOpenDBRequest} */ + req.onsuccess = req.oncomplete = function(){ + callback && callback(this.result); + callback = null; resolve(this.result); }; - req.oncomplete = function(){ - resolve(); - }; - req.onerror = reject; + req.onerror = req.onblocked = reject; req = null; }); } diff --git a/dist/db/mongodb/index.cjs b/dist/db/mongodb/index.cjs index c6eb4a6..4de97ed 100644 --- a/dist/db/mongodb/index.cjs +++ b/dist/db/mongodb/index.cjs @@ -580,6 +580,8 @@ MongoDB.prototype.commit = async function(flexsearch, _replace, _append){ return; } + const promises = []; + if(flexsearch.map.size){ let data = []; for(const item of flexsearch.map){ @@ -599,8 +601,9 @@ MongoDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.collection("map" + this.field).insertMany(data); - flexsearch.map.clear(); + promises.push( + this.db.collection("map" + this.field).insertMany(data) + ); } } @@ -627,26 +630,26 @@ MongoDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.collection("ctx" + this.field).insertMany(data); - flexsearch.ctx.clear(); + promises.push( + this.db.collection("ctx" + this.field).insertMany(data) + ); } } if(flexsearch.tag){ let data = []; - if(flexsearch.tag){ - for(const item of flexsearch.tag){ - const tag = item[0]; - const ids = item[1]; - if(!ids.length) continue; - for(let j = 0; j < ids.length; j++){ - data.push({ tag, id: ids[j] }); - } + for(const item of flexsearch.tag){ + const tag = item[0]; + const ids = item[1]; + if(!ids.length) continue; + for(let j = 0; j < ids.length; j++){ + data.push({ tag, id: ids[j] }); } } if(data.length){ - await this.db.collection("tag" + this.field).insertMany(data); - flexsearch.tag.clear(); + promises.push( + this.db.collection("tag" + this.field).insertMany(data) + ); } } @@ -664,13 +667,22 @@ MongoDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.collection("reg").insertMany(data); - flexsearch.store && - flexsearch.store.clear(); - flexsearch.document || - flexsearch.reg.clear(); + promises.push( + this.db.collection("reg").insertMany(data) + ); } + await Promise.all(promises); + + flexsearch.map.clear(); + flexsearch.ctx.clear(); + flexsearch.tag && + flexsearch.tag.clear(); + flexsearch.store && + flexsearch.store.clear(); + flexsearch.document || + flexsearch.reg.clear(); + // TODO // await this.db.collection("cfg" + this.field).insertOne({ // "encode": typeof flexsearch.encode === "string" ? flexsearch.encode : "", diff --git a/dist/db/sqlite/index.cjs b/dist/db/sqlite/index.cjs index 863e446..8299af0 100644 --- a/dist/db/sqlite/index.cjs +++ b/dist/db/sqlite/index.cjs @@ -592,10 +592,10 @@ SqliteDB.prototype.info = function(){ // todo }; -SqliteDB.prototype.transaction = function(task, callback){ +SqliteDB.prototype.transaction = async function(task, callback){ if(TRX[this.id]){ - return task.call(this); + return await task.call(this); } const db = this.db; diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 45b7226..9f6c4b3 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.138 (Bundle/Debug) + * FlexSearch.js v0.8.140 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -1603,7 +1603,7 @@ t.mount = function(a) { t.commit = async function(a, c) { const b = []; for (const e of this.index.values()) { - b.push(e.commit(e, a, c)); + b.push(e.commit(a, c)); } await Promise.all(b); this.reg.clear(); @@ -2251,37 +2251,29 @@ t.mount = function(a) { return this.open(); }; t.open = function() { + if (this.db) { + return this.db; + } let a = this; navigator.storage && navigator.storage.persist(); - return this.db || (this.db = new Promise(function(c, b) { - Y[a.id] || (Y[a.id] = []); - Y[a.id].push(a.field); - const e = pb.open(a.id, 1); - e.onupgradeneeded = function() { - const d = a.db = this.result; - for (let f = 0, g; f < qb.length; f++) { - g = qb[f]; - for (let k = 0, h; k < Y[a.id].length; k++) { - h = Y[a.id][k], d.objectStoreNames.contains(g + ("reg" !== g ? h ? ":" + h : "" : "")) || d.createObjectStore(g + ("reg" !== g ? h ? ":" + h : "" : "")); - } + Y[a.id] || (Y[a.id] = []); + Y[a.id].push(a.field); + const c = pb.open(a.id, 1); + c.onupgradeneeded = function() { + const b = a.db = this.result; + for (let e = 0, d; e < qb.length; e++) { + d = qb[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 : "" : "")); } + } + }; + return a.db = Z(c, function(b) { + a.db = b; + a.db.onversionchange = function() { + a.close(); }; - e.onblocked = function(d) { - console.error("blocked", d); - b(); - }; - e.onerror = function(d) { - console.error(this.error, d); - b(); - }; - e.onsuccess = function() { - a.db = this.result; - a.db.onversionchange = function() { - a.close(); - }; - c(a); - }; - })); + }); }; t.close = function() { this.db && this.db.close(); @@ -2375,26 +2367,18 @@ t.search = null; t.info = function() { }; t.transaction = function(a, c, b) { - const e = a + ("reg" !== a ? this.field ? ":" + this.field : "" : ""); - let d = this.h[e + ":" + c]; - if (d) { - return b.call(this, d); + a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; + let e = this.h[a + ":" + c]; + if (e) { + return b.call(this, e); } - let f = this.db.transaction(e, c); - this.h[e + ":" + c] = d = f.objectStore(e); - return new Promise((g, k) => { - f.onerror = l => { - f.abort(); - f = d = null; - k(l); - }; - f.oncomplete = l => { - f = d = null; - g(l || !0); - }; - const h = b.call(this, d); - this.h[e + ":" + c] = null; - return h; + let d = this.db.transaction(a, c); + this.h[a + ":" + c] = e = d.objectStore(a); + const f = b.call(this, e); + this.h[a + ":" + c] = null; + return Z(d).finally(function() { + d = e = null; + return f; }); }; t.commit = async function(a, c, b) { @@ -2491,41 +2475,41 @@ t.commit = async function(a, c, b) { }; function tb(a, c, b) { const e = a.value; - let d, f, g = 0; - for (let k = 0, h; k < e.length; k++) { - if (h = b ? e : e[k]) { - for (let l = 0, n, m; l < c.length; l++) { - if (m = c[l], n = h.indexOf(f ? parseInt(m, 10) : m), 0 > n && !f && "string" === typeof m && !isNaN(m) && (n = h.indexOf(parseInt(m, 10))) && (f = 1), 0 <= n) { - if (d = 1, 1 < h.length) { - h.splice(n, 1); + let d, f = 0; + for (let g = 0, k; g < e.length; g++) { + if (k = b ? e : e[g]) { + for (let h = 0, l, n; h < c.length; h++) { + if (n = c[h], l = k.indexOf(n), 0 <= l) { + if (d = 1, 1 < k.length) { + k.splice(l, 1); } else { - e[k] = []; + e[g] = []; break; } } } - g += h.length; + f += k.length; } if (b) { break; } } - g ? d && a.update(e) : a.delete(); + f ? d && a.update(e) : a.delete(); a.continue(); } t.remove = function(a) { "object" !== typeof a && (a = [a]); - return Promise.all([this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { + return Promise.all([this.transaction("map", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; b && tb(b, a); }; - }), this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { + }), this.transaction("ctx", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; b && tb(b, a); }; - }), this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { + }), this.transaction("tag", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; b && tb(b, a, !0); @@ -2536,15 +2520,14 @@ t.remove = function(a) { } })]); }; -function Z(a) { - return new Promise((c, b) => { - a.onsuccess = function() { - c(this.result); +function Z(a, c) { + return new Promise((b, e) => { + a.onsuccess = a.oncomplete = function() { + c && c(this.result); + c = null; + b(this.result); }; - a.oncomplete = function() { - c(); - }; - a.onerror = b; + a.onerror = a.onblocked = e; a = null; }); } diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index ead5583..b824493 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,11 +1,11 @@ /**! - * FlexSearch.js v0.8.138 (Bundle) + * FlexSearch.js v0.8.140 (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(k){return a(b(k))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function B(){return Object.create(null)}function E(a){return"string"===typeof a} +(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var t;function 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&&ba.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=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),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(h)));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,ka;async function la(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":ka=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(ka),delete self.FlexSearch):M=new N(ka);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=ka.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await ka.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 ma(a){na.call(a,"add");na.call(a,"append");na.call(a,"search");na.call(a,"update");na.call(a,"remove")}let oa,pa,qa;function ra(){oa=qa=0} +[],e=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;fthis.stemmer.get(k)),d!==g&&this.filter&& +g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.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,ka;async function la(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":ka=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(ka),delete self.FlexSearch):M=new N(ka);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=ka.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await ka.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 ma(a){na.call(a,"add");na.call(a,"append");na.call(a,"search");na.call(a,"update");na.call(a,"remove")}let oa,pa,qa;function ra(){oa=qa=0} function na(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);oa?qa||(qa=Date.now()-pa>=this.priority*this.priority*3):(oa=setTimeout(ra,0),pa=Date.now());if(qa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let O=0; -function P(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,n=l&&d.h[l];n&&(n(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++O]=function(){h(d);1E9=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const k=c.length;if(k&&(d=d.length?d.concat(c):c,b-=k,e&&(a.length-=k),!b))break;c=0}return d} -function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if("length"===e)return c.length;if("push"===e)return function(d){c.index[c.index.length-1].push(d);c.length++};if("pop"===e)return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,k,h;g=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const h=c.length;if(h&&(d=d.length?d.concat(c):c,b-=h,e&&(a.length-=h),!b))break;c=0}return d} +function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if("length"===e)return c.length;if("push"===e)return function(d){c.index[c.index.length-1].push(d);c.length++};if("pop"===e)return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;gb||e?h.slice(e,b+e):h;else{if(ab||e)h=h.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}h=1c?c?a.slice(b,b+c):a.slice(b):a,e?V.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?V.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ha(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:k,offset:h,enrich:l,resolve:n,suggest:m}=Ka(this,"and",arguments);return Ma.call(this,f,g,k,h,l,n,m)}return d?this.resolve(c,b,e):this}; -function Ma(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=ca(a))return this.result=Ga(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}=Ka(this,"xor",arguments);return Na.call(this,a,c,b,e,d,f,g)}; -function Na(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=Oa.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 Oa(a,c,b,e,d){const f=[],g=B();let k=0;for(let h=0,l;hb||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=Ha(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}=Ka(this,"and",arguments);return Ma.call(this,f,g,h,k,l,n,m)}return d?this.resolve(c,b,e):this}; +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{if(c=ca(a))return this.result=Ga(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}=Ka(this,"xor",arguments);return Na.call(this,a,c,b,e,d,f,g)}; +function Na(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=Oa.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 Oa(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 Xa={normalize:function(a){return a.toLowerCase()}};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};const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;const db=/[\x00-\x7F]+/g;var eb={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Xa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ya},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ya,matcher:Za,replacer:$a},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ya,replacer:$a.concat([/(?!^)[aeo]/g,""]),matcher:Za},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 k=this.score?this.score(c,r,p,g,v):gb(q,e,p,d,v); -hb(this,n,g,k,a,b)}break}case "reverse":if(1g?0:1),e,p,k-1,h-1),v=this.bidirectional&& +g||"w"===g||!(g=ab[g])||g===d||(e+=g,d=g,4!==e.length));f++);a[b]=e}}},ArabicDefault:{normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(bb," ")}},CjkDefault:{normalize:!1,dedupe:!0,split:"",prepare:function(a){return(""+a).replace(cb,"")}},CyrillicDefault:{normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(db," ")}}};const fb={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))return this.update(a,c);c=this.encoder.encode(c);if(e=c.length){const l=B(),n=B(),m=this.depth,q=this.resolution;for(let p=0;pu;f--){g=r.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(c,r,p,g,v):gb(q,e,p,d,v); +hb(this,n,g,h,a,b)}break}case "reverse":if(1g?0:1),e,p,h-1,k-1),v=this.bidirectional&& r>f;hb(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&&ib(this));return this}; -function hb(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)){if(k.length===2**31-1){c=new R(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=c);h[e]=k=c}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} -function gb(a,c,b,e,d){return b&&1b)&&(h=b,b=c,c=h);if(a.db)return a.db.get(c,b,e,d,f,g,k);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 nb(this.map,a),this.depth&&nb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&ib(this));this.cache&&this.cache.remove(a);return this}; +function hb(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 gb(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 nb(this.map,a),this.depth&&nb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&ib(this));this.cache&&this.cache.remove(a);return this}; function nb(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;e=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.open=function(){if(this.db)return this.db;let a=this;navigator.storage&&navigator.storage.persist();Y[a.id]||(Y[a.id]=[]);Y[a.id].push(a.field);const c=pb.open(a.id,1);c.onupgradeneeded=function(){const b=a.db=this.result;for(let e=0,d;e=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{f.onerror=l=>{f.abort();f=d=null;k(l)};f.oncomplete=l=>{f=d=null;g(l||!0)};const h=b.call(this,d);this.h[e+":"+c]=null;return h})}; -t.commit=async function(a,c,b){if(c)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dn&&!f&&"string"===typeof m&&!isNaN(m)&&(n=h.indexOf(parseInt(m,10)))&&(f=1),0<=n)if(d=1,1{a.onsuccess=function(){c(this.result)};a.oncomplete=function(){c()};a.onerror=b;a=null})};const ub={Index:N,Charset:eb,Encoder:J,Document:U,Worker:P,Resolver:W,IndexedDB:sb,Language:{}},vb="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let wb;(wb=vb.define)&&wb.amd?wb([],function(){return ub}):"object"===typeof vb.exports?vb.exports=ub:vb.FlexSearch=ub;}(this||self)); +t.transaction=function(a,c,b){a+="reg"!==a?this.field?":"+this.field:"":"";let e=this.h[a+":"+c];if(e)return b.call(this,e);let d=this.db.transaction(a,c);this.h[a+":"+c]=e=d.objectStore(a);const f=b.call(this,e);this.h[a+":"+c]=null;return Z(d).finally(function(){d=e=null;return f})}; +t.commit=async function(a,c,b){if(c)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;d{a.onsuccess=a.oncomplete=function(){c&&c(this.result);c=null;b(this.result)};a.onerror=a.onblocked=e;a=null})};const ub={Index:N,Charset:eb,Encoder:J,Document:U,Worker:P,Resolver:W,IndexedDB:sb,Language:{}},vb="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let wb;(wb=vb.define)&&wb.amd?wb([],function(){return ub}):"object"===typeof vb.exports?vb.exports=ub:vb.FlexSearch=ub;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index aef68ff..36dcc4b 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.138 (Bundle/Module/Debug) + * FlexSearch.js v0.8.140 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -1602,7 +1602,7 @@ t.mount = function(a) { t.commit = async function(a, c) { const b = []; for (const e of this.index.values()) { - b.push(e.commit(e, a, c)); + b.push(e.commit(a, c)); } await Promise.all(b); this.reg.clear(); @@ -2250,37 +2250,29 @@ t.mount = function(a) { return this.open(); }; t.open = function() { + if (this.db) { + return this.db; + } let a = this; navigator.storage && navigator.storage.persist(); - return this.db || (this.db = new Promise(function(c, b) { - Y[a.id] || (Y[a.id] = []); - Y[a.id].push(a.field); - const e = qb.open(a.id, 1); - e.onupgradeneeded = function() { - const d = a.db = this.result; - for (let f = 0, g; f < rb.length; f++) { - g = rb[f]; - for (let k = 0, h; k < Y[a.id].length; k++) { - h = Y[a.id][k], d.objectStoreNames.contains(g + ("reg" !== g ? h ? ":" + h : "" : "")) || d.createObjectStore(g + ("reg" !== g ? h ? ":" + h : "" : "")); - } + Y[a.id] || (Y[a.id] = []); + Y[a.id].push(a.field); + const c = qb.open(a.id, 1); + c.onupgradeneeded = function() { + const b = a.db = this.result; + for (let e = 0, d; e < rb.length; e++) { + d = rb[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 : "" : "")); } + } + }; + return a.db = Z(c, function(b) { + a.db = b; + a.db.onversionchange = function() { + a.close(); }; - e.onblocked = function(d) { - console.error("blocked", d); - b(); - }; - e.onerror = function(d) { - console.error(this.error, d); - b(); - }; - e.onsuccess = function() { - a.db = this.result; - a.db.onversionchange = function() { - a.close(); - }; - c(a); - }; - })); + }); }; t.close = function() { this.db && this.db.close(); @@ -2374,26 +2366,18 @@ t.search = null; t.info = function() { }; t.transaction = function(a, c, b) { - const e = a + ("reg" !== a ? this.field ? ":" + this.field : "" : ""); - let d = this.h[e + ":" + c]; - if (d) { - return b.call(this, d); + a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; + let e = this.h[a + ":" + c]; + if (e) { + return b.call(this, e); } - let f = this.db.transaction(e, c); - this.h[e + ":" + c] = d = f.objectStore(e); - return new Promise((g, k) => { - f.onerror = l => { - f.abort(); - f = d = null; - k(l); - }; - f.oncomplete = l => { - f = d = null; - g(l || !0); - }; - const h = b.call(this, d); - this.h[e + ":" + c] = null; - return h; + let d = this.db.transaction(a, c); + this.h[a + ":" + c] = e = d.objectStore(a); + const f = b.call(this, e); + this.h[a + ":" + c] = null; + return Z(d).finally(function() { + d = e = null; + return f; }); }; t.commit = async function(a, c, b) { @@ -2490,41 +2474,41 @@ t.commit = async function(a, c, b) { }; function tb(a, c, b) { const e = a.value; - let d, f, g = 0; - for (let k = 0, h; k < e.length; k++) { - if (h = b ? e : e[k]) { - for (let l = 0, n, m; l < c.length; l++) { - if (m = c[l], n = h.indexOf(f ? parseInt(m, 10) : m), 0 > n && !f && "string" === typeof m && !isNaN(m) && (n = h.indexOf(parseInt(m, 10))) && (f = 1), 0 <= n) { - if (d = 1, 1 < h.length) { - h.splice(n, 1); + let d, f = 0; + for (let g = 0, k; g < e.length; g++) { + if (k = b ? e : e[g]) { + for (let h = 0, l, n; h < c.length; h++) { + if (n = c[h], l = k.indexOf(n), 0 <= l) { + if (d = 1, 1 < k.length) { + k.splice(l, 1); } else { - e[k] = []; + e[g] = []; break; } } } - g += h.length; + f += k.length; } if (b) { break; } } - g ? d && a.update(e) : a.delete(); + f ? d && a.update(e) : a.delete(); a.continue(); } t.remove = function(a) { "object" !== typeof a && (a = [a]); - return Promise.all([this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { + return Promise.all([this.transaction("map", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; b && tb(b, a); }; - }), this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { + }), this.transaction("ctx", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; b && tb(b, a); }; - }), this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { + }), this.transaction("tag", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; b && tb(b, a, !0); @@ -2535,15 +2519,14 @@ t.remove = function(a) { } })]); }; -function Z(a) { - return new Promise((c, b) => { - a.onsuccess = function() { - c(this.result); +function Z(a, c) { + return new Promise((b, e) => { + a.onsuccess = a.oncomplete = function() { + c && c(this.result); + c = null; + b(this.result); }; - a.oncomplete = function() { - c(); - }; - a.onerror = b; + a.onerror = a.onblocked = e; a = null; }); } diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index 89dd8a5..1eb9c09 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,11 +1,11 @@ /**! - * FlexSearch.js v0.8.138 (Bundle/Module) + * FlexSearch.js v0.8.140 (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(k){return a(b(k))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function B(){return Object.create(null)}function E(a){return"string"===typeof a} +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&&ba.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=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),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(h)));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,ka;async function la(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":ka=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(ka),delete self.FlexSearch):M=new N(ka);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=ka.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await ka.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 ma(a){na.call(a,"add");na.call(a,"append");na.call(a,"search");na.call(a,"update");na.call(a,"remove")}let oa,pa,qa;function ra(){oa=qa=0} +[],e=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;fthis.stemmer.get(k)),d!==g&&this.filter&& +g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.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,ka;async function la(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":ka=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(ka),delete self.FlexSearch):M=new N(ka);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=ka.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await ka.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 ma(a){na.call(a,"add");na.call(a,"append");na.call(a,"search");na.call(a,"update");na.call(a,"remove")}let oa,pa,qa;function ra(){oa=qa=0} function na(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);oa?qa||(qa=Date.now()-pa>=this.priority*this.priority*3):(oa=setTimeout(ra,0),pa=Date.now());if(qa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let O=0; -function P(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,n=l&&d.h[l];n&&(n(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++O]=function(){h(d);1E9=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const k=c.length;if(k&&(d=d.length?d.concat(c):c,b-=k,e&&(a.length-=k),!b))break;c=0}return d} -function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if("length"===e)return c.length;if("push"===e)return function(d){c.index[c.index.length-1].push(d);c.length++};if("pop"===e)return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,k,h;g=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const h=c.length;if(h&&(d=d.length?d.concat(c):c,b-=h,e&&(a.length-=h),!b))break;c=0}return d} +function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if("length"===e)return c.length;if("push"===e)return function(d){c.index[c.index.length-1].push(d);c.length++};if("pop"===e)return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;gb||e?h.slice(e,b+e):h;else{if(ab||e)h=h.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}h=1c?c?a.slice(b,b+c):a.slice(b):a,e?V.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?V.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ha(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:k,offset:h,enrich:l,resolve:n,suggest:m}=Ka(this,"and",arguments);return Ma.call(this,f,g,k,h,l,n,m)}return d?this.resolve(c,b,e):this}; -function Ma(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=ca(a))return this.result=Ga(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}=Ka(this,"xor",arguments);return Na.call(this,a,c,b,e,d,f,g)}; -function Na(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=Oa.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 Oa(a,c,b,e,d){const f=[],g=B();let k=0;for(let h=0,l;hb||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=Ha(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}=Ka(this,"and",arguments);return Ma.call(this,f,g,h,k,l,n,m)}return d?this.resolve(c,b,e):this}; +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{if(c=ca(a))return this.result=Ga(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}=Ka(this,"xor",arguments);return Na.call(this,a,c,b,e,d,f,g)}; +function Na(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=Oa.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 Oa(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 Xa={normalize:function(a){return a.toLowerCase()}};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};const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;const db=/[\x00-\x7F]+/g;var eb={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Xa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ya},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ya,matcher:Za,replacer:$a},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ya,replacer:$a.concat([/(?!^)[aeo]/g,""]),matcher:Za},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 k=this.score?this.score(c,r,p,g,v):gb(q,e,p,d,v); -hb(this,n,g,k,a,b)}break}case "reverse":if(1g?0:1),e,p,k-1,h-1),v=this.bidirectional&& +g||"w"===g||!(g=ab[g])||g===d||(e+=g,d=g,4!==e.length));f++);a[b]=e}}},ArabicDefault:{normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(bb," ")}},CjkDefault:{normalize:!1,dedupe:!0,split:"",prepare:function(a){return(""+a).replace(cb,"")}},CyrillicDefault:{normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(db," ")}}};const fb={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))return this.update(a,c);c=this.encoder.encode(c);if(e=c.length){const l=B(),n=B(),m=this.depth,q=this.resolution;for(let p=0;pu;f--){g=r.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(c,r,p,g,v):gb(q,e,p,d,v); +hb(this,n,g,h,a,b)}break}case "reverse":if(1g?0:1),e,p,h-1,k-1),v=this.bidirectional&& r>f;hb(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&&ib(this));return this}; -function hb(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)){if(k.length===2**31-1){c=new R(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=c);h[e]=k=c}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} -function gb(a,c,b,e,d){return b&&1b)&&(h=b,b=c,c=h);if(a.db)return a.db.get(c,b,e,d,f,g,k);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 nb(this.map,a),this.depth&&nb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&ib(this));this.cache&&this.cache.remove(a);return this}; +function hb(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 gb(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 nb(this.map,a),this.depth&&nb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&ib(this));this.cache&&this.cache.remove(a);return this}; function nb(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;e=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.open=function(){if(this.db)return this.db;let a=this;navigator.storage&&navigator.storage.persist();Y[a.id]||(Y[a.id]=[]);Y[a.id].push(a.field);const c=qb.open(a.id,1);c.onupgradeneeded=function(){const b=a.db=this.result;for(let e=0,d;e=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{f.onerror=l=>{f.abort();f=d=null;k(l)};f.oncomplete=l=>{f=d=null;g(l||!0)};const h=b.call(this,d);this.h[e+":"+c]=null;return h})}; -t.commit=async function(a,c,b){if(c)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dn&&!f&&"string"===typeof m&&!isNaN(m)&&(n=h.indexOf(parseInt(m,10)))&&(f=1),0<=n)if(d=1,1{a.onsuccess=function(){c(this.result)};a.oncomplete=function(){c()};a.onerror=b;a=null})};export default {Index:N,Charset:eb,Encoder:J,Document:U,Worker:P,Resolver:W,IndexedDB:sb,Language:{}}; +t.transaction=function(a,c,b){a+="reg"!==a?this.field?":"+this.field:"":"";let e=this.h[a+":"+c];if(e)return b.call(this,e);let d=this.db.transaction(a,c);this.h[a+":"+c]=e=d.objectStore(a);const f=b.call(this,e);this.h[a+":"+c]=null;return Z(d).finally(function(){d=e=null;return f})}; +t.commit=async function(a,c,b){if(c)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;d{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:eb,Encoder:J,Document:U,Worker:P,Resolver:W,IndexedDB:sb,Language:{}}; export const Index=N;export const Charset=eb;export const Encoder=J;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=sb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index a5c5508..f0bbd25 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.138 (Bundle/Debug) + * FlexSearch.js v0.8.140 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index b351195..b3a31d7 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.138 (Bundle) + * FlexSearch.js v0.8.140 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH diff --git a/dist/flexsearch.compact.module.debug.js b/dist/flexsearch.compact.module.debug.js index 743f5a4..ce6e0b0 100644 --- a/dist/flexsearch.compact.module.debug.js +++ b/dist/flexsearch.compact.module.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.138 (Bundle/Debug) + * FlexSearch.js v0.8.140 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index 0470ca3..42e0e65 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.138 (Bundle) + * FlexSearch.js v0.8.140 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH diff --git a/dist/flexsearch.es5.debug.js b/dist/flexsearch.es5.debug.js index 005192e..3578a5d 100644 --- a/dist/flexsearch.es5.debug.js +++ b/dist/flexsearch.es5.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.138 (ES5/Debug) + * FlexSearch.js v0.8.140 (ES5/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -253,19 +253,19 @@ C("Promise", function(a) { this.B = void 0; this.h = []; this.H = !1; - var k = this.C(); + var h = this.C(); try { - f(k.resolve, k.reject); - } catch (h) { - k.reject(h); + f(h.resolve, h.reject); + } catch (k) { + h.reject(k); } } function c() { this.h = null; } function d(f) { - return f instanceof b ? f : new b(function(k) { - k(f); + return f instanceof b ? f : new b(function(h) { + h(f); }); } if (a) { @@ -274,9 +274,9 @@ C("Promise", function(a) { c.prototype.A = function(f) { if (null == this.h) { this.h = []; - var k = this; + var h = this; this.B(function() { - k.D(); + h.D(); }); } this.h.push(f); @@ -289,11 +289,11 @@ C("Promise", function(a) { for (; this.h && this.h.length;) { var f = this.h; this.h = []; - for (var k = 0; k < f.length; ++k) { - var h = f[k]; - f[k] = null; + for (var h = 0; h < f.length; ++h) { + var k = f[h]; + f[h] = null; try { - h(); + k(); } catch (l) { this.C(l); } @@ -309,10 +309,10 @@ C("Promise", function(a) { b.prototype.C = function() { function f(l) { return function(m) { - h || (h = !0, l.call(k, m)); + k || (k = !0, l.call(h, m)); }; } - var k = this, h = !1; + var h = this, k = !1; return {resolve:f(this.fa), reject:f(this.D)}; }; b.prototype.fa = function(f) { @@ -325,28 +325,28 @@ C("Promise", function(a) { a: { switch(typeof f) { case "object": - var k = null != f; + var h = null != f; break a; case "function": - k = !0; + h = !0; break a; default: - k = !1; + h = !1; } } - k ? this.ea(f) : this.G(f); + h ? this.ea(f) : this.G(f); } } }; b.prototype.ea = function(f) { - var k = void 0; + var h = void 0; try { - k = f.then; - } catch (h) { - this.D(h); + h = f.then; + } catch (k) { + this.D(k); return; } - "function" == typeof k ? this.ia(k, f) : this.G(f); + "function" == typeof h ? this.ia(h, f) : this.G(f); }; b.prototype.D = function(f) { this.M(2, f); @@ -354,12 +354,12 @@ C("Promise", function(a) { b.prototype.G = function(f) { this.M(1, f); }; - b.prototype.M = function(f, k) { + b.prototype.M = function(f, h) { if (0 != this.A) { - throw Error("Cannot settle(" + f + ", " + k + "): Promise already settled in state" + this.A); + throw Error("Cannot settle(" + f + ", " + h + "): Promise already settled in state" + this.A); } this.A = f; - this.B = k; + this.B = h; 2 === this.A && this.ga(); this.N(); }; @@ -367,8 +367,8 @@ C("Promise", function(a) { var f = this; e(function() { if (f.T()) { - var k = B.console; - "undefined" !== typeof k && k.error(f.B); + var h = B.console; + "undefined" !== typeof h && h.error(f.B); } }, 1); }; @@ -376,14 +376,14 @@ C("Promise", function(a) { if (this.H) { return !1; } - var f = B.CustomEvent, k = B.Event, h = B.dispatchEvent; - if ("undefined" === typeof h) { + var f = B.CustomEvent, h = B.Event, k = B.dispatchEvent; + if ("undefined" === typeof k) { return !0; } - "function" === typeof f ? f = new f("unhandledrejection", {cancelable:!0}) : "function" === typeof k ? f = new k("unhandledrejection", {cancelable:!0}) : (f = B.document.createEvent("CustomEvent"), f.initCustomEvent("unhandledrejection", !1, !0, f)); + "function" === typeof f ? f = new f("unhandledrejection", {cancelable:!0}) : "function" === typeof h ? f = new h("unhandledrejection", {cancelable:!0}) : (f = B.document.createEvent("CustomEvent"), f.initCustomEvent("unhandledrejection", !1, !0, f)); f.promise = this; f.reason = this.B; - return h(f); + return k(f); }; b.prototype.N = function() { if (null != this.h) { @@ -395,19 +395,19 @@ C("Promise", function(a) { }; var g = new c(); b.prototype.ha = function(f) { - var k = this.C(); - f.U(k.resolve, k.reject); - }; - b.prototype.ia = function(f, k) { var h = this.C(); + f.U(h.resolve, h.reject); + }; + b.prototype.ia = function(f, h) { + var k = this.C(); try { - f.call(k, h.resolve, h.reject); + f.call(h, k.resolve, k.reject); } catch (l) { - h.reject(l); + k.reject(l); } }; - b.prototype.then = function(f, k) { - function h(p, q) { + b.prototype.then = function(f, h) { + function k(p, q) { return "function" == typeof p ? function(t) { try { l(p(t)); @@ -420,45 +420,45 @@ C("Promise", function(a) { l = p; m = q; }); - this.U(h(f, l), h(k, m)); + this.U(k(f, l), k(h, m)); return n; }; b.prototype.catch = function(f) { return this.then(void 0, f); }; - b.prototype.U = function(f, k) { - function h() { + b.prototype.U = function(f, h) { + function k() { switch(l.A) { case 1: f(l.B); break; case 2: - k(l.B); + h(l.B); break; default: throw Error("Unexpected state: " + l.A); } } var l = this; - null == this.h ? g.A(h) : this.h.push(h); + null == this.h ? g.A(k) : this.h.push(k); this.H = !0; }; b.resolve = d; b.reject = function(f) { - return new b(function(k, h) { - h(f); + return new b(function(h, k) { + k(f); }); }; b.race = function(f) { - return new b(function(k, h) { + return new b(function(h, k) { for (var l = x(f), m = l.next(); !m.done; m = l.next()) { - d(m.value).U(k, h); + d(m.value).U(h, k); } }); }; b.all = function(f) { - var k = x(f), h = k.next(); - return h.done ? d([]) : new b(function(l, m) { + var h = x(f), k = h.next(); + return k.done ? d([]) : new b(function(l, m) { function n(t) { return function(w) { p[t] = w; @@ -468,8 +468,8 @@ C("Promise", function(a) { } var p = [], q = 0; do { - p.push(void 0), q++, d(h.value).U(n(p.length - 1), m), h = k.next(); - } while (!h.done); + p.push(void 0), q++, d(k.value).U(n(p.length - 1), m), k = h.next(); + } while (!k.done); }); }; return b; @@ -507,30 +507,30 @@ function F(a, b) { return Object.prototype.hasOwnProperty.call(a, b); } C("WeakMap", function(a) { - function b(h) { - this.h = (k += Math.random() + 1).toString(); - if (h) { - h = x(h); - for (var l; !(l = h.next()).done;) { + function b(k) { + this.h = (h += Math.random() + 1).toString(); + if (k) { + k = x(k); + for (var l; !(l = k.next()).done;) { l = l.value, this.set(l[0], l[1]); } } } function c() { } - function d(h) { - var l = typeof h; - return "object" === l && null !== h || "function" === l; + function d(k) { + var l = typeof k; + return "object" === l && null !== k || "function" === l; } - function e(h) { - if (!F(h, f)) { + function e(k) { + if (!F(k, f)) { var l = new c(); - ba(h, f, {value:l}); + ba(k, f, {value:l}); } } - function g(h) { - var l = Object[h]; - l && (Object[h] = function(m) { + function g(k) { + var l = Object[k]; + l && (Object[k] = function(m) { if (m instanceof c) { return m; } @@ -543,13 +543,13 @@ C("WeakMap", function(a) { return !1; } try { - var h = Object.seal({}), l = Object.seal({}), m = new a([[h, 2], [l, 3]]); - if (2 != m.get(h) || 3 != m.get(l)) { + var k = Object.seal({}), l = Object.seal({}), m = new a([[k, 2], [l, 3]]); + if (2 != m.get(k) || 3 != m.get(l)) { return !1; } - m.delete(h); + m.delete(k); m.set(l, 4); - return !m.has(h) && 4 == m.get(l); + return !m.has(k) && 4 == m.get(l); } catch (n) { return !1; } @@ -560,71 +560,71 @@ C("WeakMap", function(a) { g("freeze"); g("preventExtensions"); g("seal"); - var k = 0; - b.prototype.set = function(h, l) { - if (!d(h)) { + var h = 0; + b.prototype.set = function(k, l) { + if (!d(k)) { throw Error("Invalid WeakMap key"); } - e(h); - if (!F(h, f)) { - throw Error("WeakMap key fail: " + h); + e(k); + if (!F(k, f)) { + throw Error("WeakMap key fail: " + k); } - h[f][this.h] = l; + k[f][this.h] = l; return this; }; - b.prototype.get = function(h) { - return d(h) && F(h, f) ? h[f][this.h] : void 0; + b.prototype.get = function(k) { + return d(k) && F(k, f) ? k[f][this.h] : void 0; }; - b.prototype.has = function(h) { - return d(h) && F(h, f) && F(h[f], this.h); + b.prototype.has = function(k) { + return d(k) && F(k, f) && F(k[f], this.h); }; - b.prototype.delete = function(h) { - return d(h) && F(h, f) && F(h[f], this.h) ? delete h[f][this.h] : !1; + b.prototype.delete = function(k) { + return d(k) && F(k, f) && F(k[f], this.h) ? delete k[f][this.h] : !1; }; return b; }); C("Map", function(a) { function b() { - var k = {}; - return k.K = k.next = k.head = k; + var h = {}; + return h.K = h.next = h.head = h; } - function c(k, h) { - var l = k[1]; + function c(h, k) { + var l = h[1]; return ua(function() { if (l) { - for (; l.head != k[1];) { + for (; l.head != h[1];) { l = l.K; } for (; l.next != l.head;) { - return l = l.next, {done:!1, value:h(l)}; + return l = l.next, {done:!1, value:k(l)}; } l = null; } return {done:!0, value:void 0}; }); } - function d(k, h) { - var l = h && typeof h; - "object" == l || "function" == l ? g.has(h) ? l = g.get(h) : (l = "" + ++f, g.set(h, l)) : l = "p_" + h; - var m = k[0][l]; - if (m && F(k[0], l)) { - for (k = 0; k < m.length; k++) { - var n = m[k]; - if (h !== h && n.key !== n.key || h === n.key) { - return {id:l, list:m, index:k, F:n}; + function d(h, k) { + var l = k && typeof k; + "object" == l || "function" == l ? g.has(k) ? l = g.get(k) : (l = "" + ++f, g.set(k, l)) : l = "p_" + k; + var m = h[0][l]; + if (m && F(h[0], l)) { + for (h = 0; h < m.length; h++) { + var n = m[h]; + if (k !== k && n.key !== n.key || k === n.key) { + return {id:l, list:m, index:h, F:n}; } } } return {id:l, list:m, index:-1, F:void 0}; } - function e(k) { + function e(h) { this[0] = {}; this[1] = b(); this.size = 0; - if (k) { - k = x(k); - for (var h; !(h = k.next()).done;) { - h = h.value, this.set(h[0], h[1]); + if (h) { + h = x(h); + for (var k; !(k = h.next()).done;) { + k = k.value, this.set(k[0], k[1]); } } } @@ -633,12 +633,12 @@ C("Map", function(a) { return !1; } try { - var k = Object.seal({x:4}), h = new a(x([[k, "s"]])); - if ("s" != h.get(k) || 1 != h.size || h.get({x:4}) || h.set({x:4}, "t") != h || 2 != h.size) { + var h = Object.seal({x:4}), k = new a(x([[h, "s"]])); + if ("s" != k.get(h) || 1 != k.size || k.get({x:4}) || k.set({x:4}, "t") != k || 2 != k.size) { return !1; } - var l = h.entries(), m = l.next(); - if (m.done || m.value[0] != k || "s" != m.value[1]) { + var l = k.entries(), m = l.next(); + if (m.done || m.value[0] != h || "s" != m.value[1]) { return !1; } m = l.next(); @@ -650,46 +650,46 @@ C("Map", function(a) { return a; } var g = new WeakMap(); - e.prototype.set = function(k, h) { - k = 0 === k ? 0 : k; - var l = d(this, k); + e.prototype.set = function(h, k) { + h = 0 === h ? 0 : h; + var l = d(this, h); l.list || (l.list = this[0][l.id] = []); - l.F ? l.F.value = h : (l.F = {next:this[1], K:this[1].K, head:this[1], key:k, value:h}, l.list.push(l.F), this[1].K.next = l.F, this[1].K = l.F, this.size++); + l.F ? l.F.value = k : (l.F = {next:this[1], K:this[1].K, head:this[1], key:h, value:k}, l.list.push(l.F), this[1].K.next = l.F, this[1].K = l.F, this.size++); return this; }; - e.prototype.delete = function(k) { - k = d(this, k); - return k.F && k.list ? (k.list.splice(k.index, 1), k.list.length || delete this[0][k.id], k.F.K.next = k.F.next, k.F.next.K = k.F.K, k.F.head = null, this.size--, !0) : !1; + e.prototype.delete = function(h) { + h = d(this, h); + return h.F && h.list ? (h.list.splice(h.index, 1), h.list.length || delete this[0][h.id], h.F.K.next = h.F.next, h.F.next.K = h.F.K, h.F.head = null, this.size--, !0) : !1; }; e.prototype.clear = function() { this[0] = {}; this[1] = this[1].K = b(); this.size = 0; }; - e.prototype.has = function(k) { - return !!d(this, k).F; + e.prototype.has = function(h) { + return !!d(this, h).F; }; - e.prototype.get = function(k) { - return (k = d(this, k).F) && k.value; + e.prototype.get = function(h) { + return (h = d(this, h).F) && h.value; }; e.prototype.entries = function() { - return c(this, function(k) { - return [k.key, k.value]; + return c(this, function(h) { + return [h.key, h.value]; }); }; e.prototype.keys = function() { - return c(this, function(k) { - return k.key; + return c(this, function(h) { + return h.key; }); }; e.prototype.values = function() { - return c(this, function(k) { - return k.value; + return c(this, function(h) { + return h.value; }); }; - e.prototype.forEach = function(k, h) { + e.prototype.forEach = function(h, k) { for (var l = this.entries(), m; !(m = l.next()).done;) { - m = m.value, k.call(h, m[1], m[0], this); + m = m.value, h.call(k, m[1], m[0], this); } }; e.prototype[Symbol.iterator] = e.prototype.entries; @@ -824,7 +824,20 @@ var wa = "function" == typeof Object.assign ? Object.assign : function(a, b) { C("Object.assign", function(a) { return a || wa; }); -function I(a, b, c) { +C("Promise.prototype.finally", function(a) { + return a ? a : function(b) { + return this.then(function(c) { + return Promise.resolve(b()).then(function() { + return c; + }); + }, function(c) { + return Promise.resolve(b()).then(function() { + throw c; + }); + }); + }; +}); +function G(a, b, c) { var d = typeof c, e = typeof a; if ("undefined" !== d) { if ("undefined" !== e) { @@ -913,10 +926,10 @@ function Ga(a) { var g = arguments; } else { g = x(arguments); - for (var f, k = []; !(f = g.next()).done;) { - k.push(f.value); + for (var f, h = []; !(f = g.next()).done;) { + h.push(f.value); } - g = k; + g = h; } return new (c.call(b, Ga, e.call(d, g)))(); } @@ -930,7 +943,7 @@ function Ga(a) { } u = Ga.prototype; u.assign = function(a) { - this.normalize = I(a.normalize, !0, this.normalize); + this.normalize = G(a.normalize, !0, this.normalize); var b = a.include, c = b || a.exclude || a.split; if (c || "" === c) { if ("object" === typeof c && c.constructor !== RegExp) { @@ -953,29 +966,29 @@ u.assign = function(a) { } else { this.split = c, e = !1 === c || 2 > "a1a".split(c).length; } - this.numeric = I(a.numeric, e); + this.numeric = G(a.numeric, e); } else { try { - this.split = I(this.split, Ba); + this.split = G(this.split, Ba); } catch (g) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = I(a.numeric, I(this.numeric, !0)); + this.numeric = G(a.numeric, G(this.numeric, !0)); } - this.prepare = I(a.prepare, null, this.prepare); - this.finalize = I(a.finalize, null, this.finalize); + this.prepare = G(a.prepare, null, this.prepare); + this.finalize = G(a.finalize, null, this.finalize); Fa || (this.mapper = new Map(Aa)); c = a.filter; - this.filter = "function" === typeof c ? c : I(c && new Set(c), null, this.filter); - this.dedupe = I(a.dedupe, !1, this.dedupe); - this.matcher = I((c = a.matcher) && new Map(c), null, this.matcher); - this.mapper = I((c = a.mapper) && new Map(c), null, this.mapper); - this.stemmer = I((c = a.stemmer) && new Map(c), null, this.stemmer); - this.replacer = I(a.replacer, null, this.replacer); - this.minlength = I(a.minlength, 1, this.minlength); - this.maxlength = I(a.maxlength, 0, this.maxlength); - this.rtl = I(a.rtl, !1, this.rtl); - if (this.cache = c = I(a.cache, !0, this.cache)) { + this.filter = "function" === typeof c ? c : G(c && new Set(c), null, this.filter); + this.dedupe = G(a.dedupe, !1, this.dedupe); + this.matcher = G((c = a.matcher) && new Map(c), null, this.matcher); + this.mapper = G((c = a.mapper) && new Map(c), null, this.mapper); + this.stemmer = G((c = a.stemmer) && new Map(c), null, this.stemmer); + this.replacer = G(a.replacer, null, this.replacer); + this.minlength = G(a.minlength, 1, this.minlength); + this.maxlength = G(a.maxlength, 0, this.maxlength); + this.rtl = G(a.rtl, !1, this.rtl); + if (this.cache = c = G(a.cache, !0, this.cache)) { this.D = null, this.T = "number" === typeof c ? c : 2e5, this.B = new Map(), this.C = new Map(), this.H = this.G = 128; } this.h = ""; @@ -1056,42 +1069,42 @@ u.encode = function(a) { this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = Fa ? a.normalize("NFKD").replace(Fa, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(Da, "$1 $2").replace(Ea, "$1 $2").replace(Ca, "$1 ")); - for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, g = 0, f = void 0, k = void 0; g < e.length; g++) { - if ((f = k = e[g]) && !(f.length < this.minlength)) { + for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, g = 0, f = void 0, h = void 0; g < e.length; g++) { + if ((f = h = e[g]) && !(f.length < this.minlength)) { if (c) { d.push(f); } else { if (!this.filter || ("function" === typeof this.filter ? this.filter(f) : !this.filter.has(f))) { if (this.cache && f.length <= this.H) { if (this.D) { - var h = this.C.get(f); - if (h || "" === h) { - h && d.push(h); + var k = this.C.get(f); + if (k || "" === k) { + k && d.push(k); continue; } } else { this.D = setTimeout(N, 50, this); } } - this.stemmer && 2 < f.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), h = f, f = f.replace(this.N, function(q) { + this.stemmer && 2 < f.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), k = f, f = f.replace(this.N, function(q) { return b.stemmer.get(q); - }), h !== f && this.filter && f.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(f) : this.filter.has(f)) && (f = "")); + }), k !== f && this.filter && f.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(f) : this.filter.has(f)) && (f = "")); if (f && (this.mapper || this.dedupe && 1 < f.length)) { - h = ""; + k = ""; for (var l = 0, m = "", n = void 0, p = void 0; l < f.length; l++) { - n = f.charAt(l), n === m && this.dedupe || ((p = this.mapper && this.mapper.get(n)) || "" === p ? p === m && this.dedupe || !(m = p) || (h += p) : h += m = n); + n = f.charAt(l), n === m && this.dedupe || ((p = this.mapper && this.mapper.get(n)) || "" === p ? p === m && this.dedupe || !(m = p) || (k += p) : k += m = n); } - f = h; + f = k; } this.matcher && 1 < f.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), f = f.replace(this.M, function(q) { return b.matcher.get(q); })); if (f && this.replacer) { - for (h = 0; f && h < this.replacer.length; h += 2) { - f = f.replace(this.replacer[h], this.replacer[h + 1]); + for (k = 0; f && k < this.replacer.length; k += 2) { + f = f.replace(this.replacer[k], this.replacer[k + 1]); } } - this.cache && k.length <= this.H && (this.C.set(k, f), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); + this.cache && h.length <= this.H && (this.C.set(h, f), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); f && d.push(f); } } @@ -1109,8 +1122,8 @@ function N(a) { ;var Ha, O; function Ia(a) { var b, c, d, e, g, f; - return ta(function(k) { - switch(k.h) { + return ta(function(h) { + switch(h.h) { case 1: a = a.data; b = a.task; @@ -1123,9 +1136,9 @@ function Ia(a) { postMessage({id:c}); break; default: - k.h = 2; + h.h = 2; return; - }k.h = 0; + }h.h = 0; break; case 2: if ("export" === b) { @@ -1139,25 +1152,25 @@ function Ia(a) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } if (!d[0]) { - k.h = 5; + h.h = 5; break; } - return E(k, O.import.call(Ha, d[0]), 9); + return E(h, O.import.call(Ha, d[0]), 9); } g = d && Ha[b].apply(Ha, d); if (!g || !g.then) { - k.h = 5; + h.h = 5; break; } - return E(k, g, 7); + return E(h, g, 7); case 7: - g = k.D; - k.h = 5; + g = h.D; + h.h = 5; break; case 9: - f = k.D, Ha.import(d[0], f); + f = h.D, Ha.import(d[0], f); case 5: - postMessage("search" === b ? {id:c, msg:g} : {id:c}), k.h = 0; + postMessage("search" === b ? {id:c, msg:g} : {id:c}), h.h = 0; } }); } @@ -1199,19 +1212,19 @@ function Ma(a) { ;var Ra = 0; function Sa(a) { function b(f) { - function k(h) { - h = h.data || h; - var l = h.id, m = l && e.h[l]; - m && (m(h.msg), delete e.h[l]); + 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", k) : this.worker.onmessage = k; + d ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { - return new Promise(function(h) { + return new Promise(function(k) { e.h[++Ra] = function() { - h(e); + k(e); 1e9 < Ra && (Ra = 0); }; e.worker.postMessage({id:Ra, task:"init", factory:c, options:a}); @@ -1315,17 +1328,17 @@ function Za(a, b) { } function $a(a, b, c, d, e, g, f) { f = void 0 === f ? 0 : f; - var k = d && d.constructor === Array, h = k ? d.shift() : d; - if (!h) { + var h = d && d.constructor === Array, k = h ? d.shift() : d; + if (!k) { return this.export(a, b, e, g + 1); } - if ((h = a((b ? b + "." : "") + (f + 1) + "." + c, JSON.stringify(h))) && h.then) { + if ((k = a((b ? b + "." : "") + (f + 1) + "." + c, JSON.stringify(k))) && k.then) { var l = this; - return h.then(function() { - return $a.call(l, a, b, c, k ? d : null, e, g, f + 1); + return k.then(function() { + return $a.call(l, a, b, c, h ? d : null, e, g, f + 1); }); } - return $a.call(this, a, b, c, k ? d : null, e, g, f + 1); + return $a.call(this, a, b, c, h ? d : null, e, g, f + 1); } function ab(a, b) { var c = ""; @@ -1334,13 +1347,13 @@ function ab(a, b) { var e = d.value; d = e[0]; e = e[1]; - for (var g = "", f = 0, k; f < e.length; f++) { - k = e[f] || [""]; - for (var h = "", l = 0; l < k.length; l++) { - h += (h ? "," : "") + ("string" === b ? '"' + k[l] + '"' : k[l]); + for (var g = "", f = 0, h; f < e.length; f++) { + h = e[f] || [""]; + for (var k = "", l = 0; l < h.length; l++) { + k += (k ? "," : "") + ("string" === b ? '"' + h[l] + '"' : h[l]); } - h = "[" + h + "]"; - g += (g ? "," : "") + h; + k = "[" + k + "]"; + g += (g ? "," : "") + k; } g = '["' + d + '",[' + g + "]]"; c += (c ? "," : "") + g; @@ -1389,13 +1402,13 @@ function T(a) { } if ("indexOf" === d) { return function(e) { - for (var g = 0, f = 0, k, h; f < b.index.length; f++) { - k = b.index[f]; - h = k.indexOf(e); - if (0 <= h) { - return g + h; + for (var g = 0, f = 0, h, k; f < b.index.length; f++) { + h = b.index[f]; + k = h.indexOf(e); + if (0 <= k) { + return g + k; } - g += k.length; + g += h.length; } return -1; }; @@ -1599,45 +1612,45 @@ function cb() { if (this.tag) { for (d = 0; d < this.L.length; d++) { f = this.L[d]; - var k = this.aa[d]; - g = this.tag.get(k); + var h = this.aa[d]; + g = this.tag.get(h); e = J(); if ("function" === typeof f) { if (f = f(b), !f) { continue; } } else { - var h = f.R; - if (h && !h(b)) { + var k = f.R; + if (k && !k(b)) { continue; } f.constructor === String && (f = "" + f); f = ya(b, f); } if (g && f) { - for (K(f) && (f = [f]), k = 0, h = void 0; k < f.length; k++) { - var l = f[k]; + for (K(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { + var l = f[h]; if (!e[l]) { e[l] = 1; var m; - (m = g.get(l)) ? h = m : g.set(l, h = []); - if (!c || !h.includes(a)) { - if (h.length === Math.pow(2, 31) - 1) { - m = new T(h); + (m = g.get(l)) ? k = m : g.set(l, k = []); + if (!c || !k.includes(a)) { + if (k.length === Math.pow(2, 31) - 1) { + m = new T(k); if (this.fastupdate) { for (var n = x(this.reg.values()), p = n.next(); !p.done; p = n.next()) { - p = p.value, p.includes(h) && (p[p.indexOf(h)] = m); + p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); } } - g.set(l, h = m); + g.set(l, k = m); } - h.push(a); - this.fastupdate && ((l = this.reg.get(a)) ? l.push(h) : this.reg.set(a, [h])); + k.push(a); + this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); } } } } else { - g || console.warn("Tag '" + k + "' was not found"); + g || console.warn("Tag '" + h + "' was not found"); } } } @@ -1681,7 +1694,7 @@ function ib(a, b, c, d, e, g) { } } } -function hb(a, b, c, d, e, g, f, k) { +function hb(a, b, c, d, e, g, f, h) { if (a = a[f]) { if (d === b.length - 1) { if (a.constructor === Array) { @@ -1693,14 +1706,14 @@ function hb(a, b, c, d, e, g, f, k) { } a = a.join(" "); } - e.add(g, a, k, !0); + e.add(g, a, h, !0); } else { if (a.constructor === Array) { for (f = 0; f < a.length; f++) { - hb(a, b, c, d, e, g, f, k); + hb(a, b, c, d, e, g, f, h); } } else { - f = b[++d], hb(a, b, c, d, e, g, f, k); + f = b[++d], hb(a, b, c, d, e, g, f, h); } } } else { @@ -1708,45 +1721,45 @@ function hb(a, b, c, d, e, g, f, k) { } } ;function jb(a, b, c, d, e, g, f) { - var k = a.length, h = []; + var h = a.length, k = []; var l = J(); for (var m = 0, n = void 0, p, q; m < b; m++) { - for (var t = 0; t < k; t++) { + for (var t = 0; t < h; t++) { var w = a[t]; if (m < w.length && (n = w[m])) { for (var r = 0; r < n.length; r++) { p = n[r]; (w = l[p]) ? l[p]++ : (w = 0, l[p] = 1); - q = h[w] || (h[w] = []); + q = k[w] || (k[w] = []); if (!f) { var A = m + (t || !e ? 0 : g || 0); q = q[A] || (q[A] = []); } q.push(p); - if (f && c && w === k - 1 && q.length - d === c) { + if (f && c && w === h - 1 && q.length - d === c) { return q; } } } } } - if (a = h.length) { + if (a = k.length) { if (e) { - h = 1 < h.length ? kb(h, c, d, f, g) : (h = h[0]).length > c || d ? h.slice(d, c + d) : h; + k = 1 < k.length ? kb(k, c, d, f, g) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; } else { - if (a < k) { + if (a < h) { return []; } - h = h[a - 1]; + k = k[a - 1]; if (c || d) { if (f) { - if (h.length > c || d) { - h = h.slice(d, c + d); + if (k.length > c || d) { + k = k.slice(d, c + d); } } else { e = []; - for (g = 0; g < h.length; g++) { - if (f = h[g], f.length > d) { + for (g = 0; g < k.length; g++) { + if (f = k[g], f.length > d) { d -= f.length; } else { if (f.length > c || d) { @@ -1758,20 +1771,20 @@ function hb(a, b, c, d, e, g, f, k) { } } } - h = 1 < e.length ? [].concat.apply([], e) : e[0]; + k = 1 < e.length ? [].concat.apply([], e) : e[0]; } } } } - return h; + return k; } function kb(a, b, c, d, e) { - var g = [], f = J(), k = a.length, h; + var g = [], f = J(), h = a.length, k; if (d) { - for (e = k - 1; 0 <= e; e--) { - if (h = (d = a[e]) && d.length) { - for (k = 0; k < h; k++) { - var l = d[k]; + for (e = h - 1; 0 <= e; e--) { + if (k = (d = a[e]) && d.length) { + for (h = 0; h < k; h++) { + var l = d[h]; if (!f[l]) { if (f[l] = 1, c) { c--; @@ -1785,16 +1798,16 @@ function kb(a, b, c, d, e) { } } } else { - for (var m = k - 1, n, p = 0; 0 <= m; m--) { + for (var m = h - 1, n, p = 0; 0 <= m; m--) { n = a[m]; for (var q = 0; q < n.length; q++) { - if (h = (d = n[q]) && d.length) { - for (var t = 0; t < h; t++) { + if (k = (d = n[q]) && d.length) { + for (var t = 0; t < k; t++) { if (l = d[t], !f[l]) { if (f[l] = 1, c) { c--; } else { - var w = (q + (m < k - 1 ? e || 0 : 0)) / (m + 1) | 0; + var w = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; (g[w] || (g[w] = [])).push(l); if (++p === b) { return g; @@ -1811,8 +1824,8 @@ function kb(a, b, c, d, e) { function lb(a, b, c) { for (var d = J(), e = [], g = 0, f; g < b.length; g++) { f = b[g]; - for (var k = 0; k < f.length; k++) { - d[f[k]] = 1; + for (var h = 0; h < f.length; h++) { + d[f[h]] = 1; } } if (c) { @@ -1835,21 +1848,21 @@ function lb(a, b, c) { if (1 === a.length) { return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? X.call(this, a) : a; } - for (var e = [], g = 0, f = void 0, k = void 0; g < a.length; g++) { - if ((f = a[g]) && (k = f.length)) { + for (var e = [], g = 0, f = void 0, h = void 0; g < a.length; g++) { + if ((f = a[g]) && (h = f.length)) { if (c) { - if (c >= k) { - c -= k; + if (c >= h) { + c -= h; continue; } - c < k && (f = b ? f.slice(c, c + b) : f.slice(c), k = f.length, c = 0); + c < h && (f = b ? f.slice(c, c + b) : f.slice(c), h = f.length, c = 0); } - k > b && (f = f.slice(0, b), k = b); - if (!e.length && k >= b) { + h > b && (f = f.slice(0, b), h = b); + if (!e.length && h >= b) { return d ? X.call(this, f) : f; } e.push(f); - b -= k; + b -= h; if (!b) { break; } @@ -1869,7 +1882,7 @@ function lb(a, b, c) { return a[b].apply(a, d); } d = []; - for (var e = [], g = 0, f = 0, k, h, l, m = 0, n = void 0; m < c.length; m++) { + for (var e = [], g = 0, f = 0, h, k, l, m = 0, n = void 0; m < c.length; m++) { if (n = c[m]) { var p = void 0; if (n.constructor === Y) { @@ -1877,8 +1890,8 @@ function lb(a, b, c) { } else if (n.constructor === Array) { p = n; } else { - if (g = n.limit || 0, f = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { - n.resolve = !1, n.enrich = !1, p = n.index.search(n).result, n.resolve = h, n.enrich = k; + if (g = n.limit || 0, f = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { + n.resolve = !1, n.enrich = !1, p = n.index.search(n).result, n.resolve = k, n.enrich = h; } else if (n.and) { p = a.and(n.and); } else if (n.or) { @@ -1901,7 +1914,7 @@ function lb(a, b, c) { } } } - return {W:d, $:e, limit:g, offset:f, enrich:k, resolve:h, suggest:l}; + return {W:d, $:e, limit:g, offset:f, enrich:h, resolve:k, suggest:l}; } ;Y.prototype.or = function() { var a = nb(this, "or", arguments); @@ -1910,10 +1923,10 @@ function lb(a, b, c) { function ob(a, b, c, d, e, g) { if (b.length) { var f = this; - return Promise.all(b).then(function(k) { + return Promise.all(b).then(function(h) { a = []; - for (var h = 0, l = void 0; h < k.length; h++) { - (l = k[h]).length && (a[h] = l); + for (var k = 0, l = void 0; k < h.length; k++) { + (l = h[k]).length && (a[k] = l); } return ob.call(f, a, [], c, d, e, g); }); @@ -1937,13 +1950,13 @@ function ob(a, b, c, d, e, g) { }; function pb(a, b, c, d, e, g, f) { if (b.length) { - var k = this; - return Promise.all(b).then(function(h) { + var h = this; + return Promise.all(b).then(function(k) { a = []; - for (var l = 0, m = void 0; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (var l = 0, m = void 0; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return pb.call(k, a, [], c, d, e, g, f); + return pb.call(h, a, [], c, d, e, g, f); }); } if (a.length) { @@ -1966,13 +1979,13 @@ function pb(a, b, c, d, e, g, f) { }; function qb(a, b, c, d, e, g, f) { if (b.length) { - var k = this; - return Promise.all(b).then(function(h) { + var h = this; + return Promise.all(b).then(function(k) { a = []; - for (var l = 0, m = void 0; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (var l = 0, m = void 0; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return qb.call(k, a, [], c, d, e, g, f); + return qb.call(h, a, [], c, d, e, g, f); }); } if (a.length) { @@ -1987,9 +2000,9 @@ function qb(a, b, c, d, e, g, f) { return g ? this.resolve(c, d, e) : this; } function rb(a, b, c, d, e) { - for (var g = [], f = J(), k = 0, h = 0, l; h < a.length; h++) { - if (l = a[h]) { - k < l.length && (k = l.length); + for (var g = [], f = J(), h = 0, k = 0, l; k < a.length; k++) { + if (l = a[k]) { + h < l.length && (h = l.length); for (var m = 0, n; m < l.length; m++) { if (n = l[m]) { for (var p = 0, q; p < n.length; p++) { @@ -1999,10 +2012,10 @@ function rb(a, b, c, d, e) { } } } - for (l = h = 0; h < k; h++) { + for (l = k = 0; k < h; k++) { for (m = 0; m < a.length; m++) { if (n = a[m]) { - if (n = n[h]) { + if (n = n[k]) { for (p = 0; p < n.length; p++) { if (q = n[p], 1 === f[q]) { if (c) { @@ -2013,7 +2026,7 @@ function rb(a, b, c, d, e) { return g; } } else { - var t = h + (m ? e : 0); + var t = k + (m ? e : 0); g[t] || (g[t] = []); g[t].push(q); if (++l === b) { @@ -2035,13 +2048,13 @@ function rb(a, b, c, d, e) { }; function sb(a, b, c, d, e, g, f) { if (b.length) { - var k = this; - return Promise.all(b).then(function(h) { + var h = this; + return Promise.all(b).then(function(k) { a = []; - for (var l = 0, m = void 0; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (var l = 0, m = void 0; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); } - return sb.call(k, a, [], c, d, e, g, f); + return sb.call(h, a, [], c, d, e, g, f); }); } if (a.length && this.result.length) { @@ -2054,10 +2067,10 @@ function sb(a, b, c, d, e, g, f) { function tb(a, b, c, d) { var e = []; a = new Set(a.flat().flat()); - for (var g = 0, f, k = 0; g < this.result.length; g++) { + for (var g = 0, f, h = 0; g < this.result.length; g++) { if (f = this.result[g]) { - for (var h = 0, l; h < f.length; h++) { - if (l = f[h], !a.has(l)) { + for (var k = 0, l; k < f.length; k++) { + if (l = f[k], !a.has(l)) { if (c) { c--; } else { @@ -2066,7 +2079,7 @@ function tb(a, b, c, d) { return e; } } else { - if (e[g] || (e[g] = []), e[g].push(l), ++k === b) { + if (e[g] || (e[g] = []), e[g].push(l), ++h === b) { return e; } } @@ -2129,7 +2142,7 @@ Y.prototype.resolve = function(a, b, c) { J(); W.prototype.search = function(a, b, c, d) { c || (!b && L(a) ? (c = a, a = "") : L(b) && (c = b, b = 0)); - var e = [], g = [], f, k = 0, h = !0; + var e = [], g = [], f, h = 0, k = !0; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; @@ -2138,8 +2151,8 @@ W.prototype.search = function(a, b, c, d) { var n = l || c.field || (n = c.index) && (n.index ? null : n); var p = this.tag && c.tag; var q = c.suggest; - h = !1 !== c.resolve; - if (!h && !l) { + k = !1 !== c.resolve; + if (!k && !l) { if (n = n || this.field) { K(n) ? l = n : (n.constructor === Array && 1 === n.length && (n = n[0]), l = n.field || n.index); } @@ -2147,8 +2160,8 @@ W.prototype.search = function(a, b, c, d) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - this.store && c.enrich && !h && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - var t = (f = this.store && c.enrich && h) && c.highlight; + this.store && c.enrich && !k && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var t = (f = this.store && c.enrich && k) && c.highlight; b = c.limit || b; var w = c.offset || 0; b || (b = 100); @@ -2171,13 +2184,13 @@ W.prototype.search = function(a, b, c, d) { } else { v = Object.keys(z); y = 0; - for (var D = void 0, G = void 0; y < v.length; y++) { - if (D = v[y], G = z[D], G.constructor === Array) { - for (var H = 0; H < G.length; H++) { - r.push(D, G[H]); + for (var D = void 0, H = void 0; y < v.length; y++) { + if (D = v[y], H = z[D], H.constructor === Array) { + for (var I = 0; I < H.length; I++) { + r.push(D, H[I]); } } else { - r.push(D, G); + r.push(D, H); } } } @@ -2187,7 +2200,7 @@ W.prototype.search = function(a, b, c, d) { } p = r; if (!a) { - h = []; + k = []; if (r.length) { for (g = 0; g < r.length; g += 2) { l = void 0; @@ -2197,14 +2210,14 @@ W.prototype.search = function(a, b, c, d) { console.warn("Tag '" + r[g] + ":" + r[g + 1] + "' will be skipped because there is no field '" + r[g] + "'."); continue; } - h.push(l = l.db.tag(r[g + 1], b, w, f)); + k.push(l = l.db.tag(r[g + 1], b, w, f)); } else { l = ub.call(this, r[g], r[g + 1], b, w, f); } e.push({field:r[g], tag:r[g + 1], result:l}); } } - return h.length ? Promise.all(h).then(function(Q) { + return k.length ? Promise.all(k).then(function(Q) { for (var R = 0; R < Q.length; R++) { e[R].result = Q[R]; } @@ -2242,52 +2255,52 @@ W.prototype.search = function(a, b, c, d) { v = v.search(a, b, y), y && f && (y.enrich = f); } } - y = v && (h ? v.length : v.result.length); + y = v && (k ? v.length : v.result.length); if (p && y) { D = []; - G = 0; + H = 0; if (this.db && d) { if (!Ka) { - for (H = n.length; H < d.length; H++) { - var M = d[H]; + for (I = n.length; I < d.length; I++) { + var M = d[I]; if (M && M.length) { - G++, D.push(M); + H++, D.push(M); } else if (!q) { - return h ? e : new Y(e); + return k ? e : new Y(e); } } } } else { - H = 0; - for (var Yb = M = void 0; H < p.length; H += 2) { - M = this.tag.get(p[H]); + I = 0; + for (var Yb = M = void 0; I < p.length; I += 2) { + M = this.tag.get(p[I]); if (!M) { - if (console.warn("Tag '" + p[H] + ":" + p[H + 1] + "' will be skipped because there is no field '" + p[H] + "'."), q) { + if (console.warn("Tag '" + p[I] + ":" + p[I + 1] + "' will be skipped because there is no field '" + p[I] + "'."), q) { continue; } else { - return h ? e : new Y(e); + return k ? e : new Y(e); } } - if (Yb = (M = M && M.get(p[H + 1])) && M.length) { - G++, D.push(M); + if (Yb = (M = M && M.get(p[I + 1])) && M.length) { + H++, D.push(M); } else if (!q) { - return h ? e : new Y(e); + return k ? e : new Y(e); } } } - if (G) { - v = lb(v, D, h); + if (H) { + v = lb(v, D, k); y = v.length; if (!y && !q) { - return h ? v : new Y(v); + return k ? v : new Y(v); } - G--; + H--; } } if (y) { - g[k] = z, e.push(v), k++; + g[h] = z, e.push(v), h++; } else if (1 === n.length) { - return h ? e : new Y(e); + return k ? e : new Y(e); } } } @@ -2299,7 +2312,7 @@ W.prototype.search = function(a, b, c, d) { if (console.warn("Tag '" + p[f] + ":" + p[f + 1] + "' was not found because there is no field '" + p[f] + "'."), q) { continue; } else { - return h ? e : new Y(e); + return k ? e : new Y(e); } } r.push(g.db.tag(p[f + 1], b, w, !1)); @@ -2310,8 +2323,8 @@ W.prototype.search = function(a, b, c, d) { return Q.length ? Zb.search(a, b, c, Q) : Q; }); } - if (!k) { - return h ? e : new Y(e); + if (!h) { + return k ? e : new Y(e); } if (l && (!f || !this.store)) { return e[0]; @@ -2321,7 +2334,7 @@ W.prototype.search = function(a, b, c, d) { q = e[w]; f && q.length && "undefined" === typeof q[0].doc && (this.db ? r.push(q = this.index.get(this.field[0]).db.enrich(q)) : q = X.call(this, q)); if (l) { - return h ? q : new Y(q); + return k ? q : new Y(q); } e[w] = {field:g[w], result:q}; } @@ -2337,31 +2350,31 @@ W.prototype.search = function(a, b, c, d) { return m ? vb(e, b) : t ? wb(e, a, this.index, this.field, this.J, t) : e; }; function wb(a, b, c, d, e, g) { - for (var f, k, h, l = 0, m, n; l < a.length; l++) { + for (var f, h, k, l = 0, m, n; l < a.length; l++) { var p = a[l].result; m = a[l].field; - h = c.get(m); - n = h.encoder; - h = h.tokenize; + k = c.get(m); + n = k.encoder; + k = k.tokenize; m = e[d.indexOf(m)]; - n !== f && (f = n, k = f.encode(b)); + n !== f && (f = n, h = f.encode(b)); for (n = 0; n < p.length; n++) { var q = "", t = ya(p[n].doc, m), w = f.encode(t); t = t.split(f.split); for (var r = 0, A, z; r < w.length; r++) { A = w[r]; z = t[r]; - for (var v = void 0, y = 0, D; y < k.length; y++) { - if (D = k[y], "strict" === h) { + for (var v = void 0, y = 0, D; y < h.length; y++) { + if (D = h[y], "strict" === k) { if (A === D) { q += (q ? " " : "") + g.replace("$1", z); v = !0; break; } } else { - var G = A.indexOf(D); - if (-1 < G) { - q += (q ? " " : "") + z.substring(0, G) + g.replace("$1", z.substring(G, D.length)) + z.substring(G + D.length); + var H = A.indexOf(D); + if (-1 < H) { + q += (q ? " " : "") + z.substring(0, H) + g.replace("$1", z.substring(H, D.length)) + z.substring(H + D.length); v = !0; break; } @@ -2378,14 +2391,14 @@ function vb(a, b) { for (var c = [], d = J(), e = 0, g, f; e < a.length; e++) { g = a[e]; f = g.result; - for (var k = 0, h, l, m; k < f.length; k++) { - if (l = f[k], "object" !== typeof l && (l = {id:l}), h = l.id, m = d[h]) { + for (var h = 0, k, l, m; h < f.length; h++) { + if (l = f[h], "object" !== typeof l && (l = {id:l}), k = l.id, m = d[k]) { m.push(g.field); } else { if (c.length === b) { return c; } - l.field = d[h] = [g.field]; + l.field = d[k] = [g.field]; c.push(l); } } @@ -2428,11 +2441,11 @@ function X(a) { this.reg = !this.fastupdate || a.worker || a.db ? d ? new V(d) : new Set() : d ? new U(d) : new Map(); this.I = (c = b.store || null) && c && !0 !== c && []; this.store = c && (d ? new U(d) : new Map()); - this.cache = (c = a.cache || null) && new Z(c); + this.cache = (c = a.cache || null) && new yb(c); a.cache = !1; this.worker = a.worker; this.priority = a.priority || 4; - this.index = yb.call(this, a, b); + this.index = zb.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { @@ -2462,10 +2475,10 @@ function X(a) { if (a.length) { var g = this; return Promise.all(a).then(function(f) { - for (var k = 0, h = x(g.index.entries()), l = h.next(); !l.done; l = h.next()) { + for (var h = 0, k = x(g.index.entries()), l = k.next(); !l.done; l = k.next()) { l = l.value; var m = l[0]; - l[1].then && g.index.set(m, f[k++]); + l[1].then && g.index.set(m, f[h++]); } return g; }); @@ -2507,17 +2520,17 @@ u.mount = function(a) { }; u.commit = function(a, b) { var c = this, d, e, g, f; - return ta(function(k) { - if (1 == k.h) { + return ta(function(h) { + if (1 == h.h) { d = []; e = x(c.index.values()); for (g = e.next(); !g.done; g = e.next()) { - f = g.value, d.push(f.commit(f, a, b)); + f = g.value, d.push(f.commit(a, b)); } - return E(k, Promise.all(d), 2); + return E(h, Promise.all(d), 2); } c.reg.clear(); - k.h = 0; + h.h = 0; }); }; u.destroy = function() { @@ -2526,7 +2539,7 @@ u.destroy = function() { } return Promise.all(a); }; -function yb(a, b) { +function zb(a, b) { var c = new Map(), d = b.index || b.field || b; K(d) && (d = [d]); for (var e = 0, g, f = void 0; e < d.length; e++) { @@ -2534,8 +2547,8 @@ function yb(a, b) { K(g) || (f = g, g = g.field); f = L(f) ? Object.assign({}, a, f) : a; if (this.worker) { - var k = new Sa(f); - c.set(g, k); + var h = new Sa(f); + c.set(g, h); } this.worker || c.set(g, new P(f, this.reg)); f.custom ? this.J[e] = f.custom : (this.J[e] = xb(g, this.S), f.filter && ("string" === typeof this.J[e] && (this.J[e] = new String(this.J[e])), this.J[e].R = f.filter)); @@ -2616,7 +2629,7 @@ u.set = function(a, b) { this.store.set(a, b); return this; }; -u.searchCache = zb; +u.searchCache = Ab; u.export = function(a, b, c, d) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; @@ -2633,23 +2646,23 @@ u.export = function(a, b, c, d) { switch(d) { case 0: var f = "reg"; - var k = Ya(this.reg); + var h = Ya(this.reg); b = null; break; case 1: f = "tag"; - k = this.tag && Wa(this.tag, this.reg.size); + h = this.tag && Wa(this.tag, this.reg.size); b = null; break; case 2: f = "doc"; - k = this.store && Ua(this.store); + h = this.store && Ua(this.store); b = null; break; default: return; } - return $a.call(this, a, b, f, k, c, d); + return $a.call(this, a, b, f, h, c, d); }; u.import = function(a, b) { var c = a.split("."); @@ -2689,9 +2702,9 @@ u.import = function(a, b) { } }; Ja(W.prototype); -function zb(a, b, c) { +function Ab(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new Z()); + this.cache || (this.cache = new yb()); var d = this.cache.get(a); if (!d) { d = this.search(a, b, c); @@ -2706,54 +2719,54 @@ function zb(a, b, c) { } return d; } -function Z(a) { +function yb(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -Z.prototype.set = function(a, b) { +yb.prototype.set = function(a, b) { this.cache.set(this.h = a, b); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -Z.prototype.get = function(a) { +yb.prototype.get = function(a) { var b = this.cache.get(a); b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); return b; }; -Z.prototype.remove = function(a) { +yb.prototype.remove = function(a) { for (var b = x(this.cache), c = b.next(); !c.done; c = b.next()) { c = c.value; var d = c[0]; c[1].includes(a) && this.cache.delete(d); } }; -Z.prototype.clear = function() { +yb.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -var Ab = {normalize:function(a) { +var Bb = {normalize:function(a) { return a.toLowerCase(); }}; -var Bb = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); -var Cb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Db = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -var Eb = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -var Fb = /[\x00-\x7F]+/g; +var 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 = /[\x00-\x7F]+/g; var Hb = /[\x00-\x7F]+/g; -var Ib = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Ab, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Bb}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Bb, matcher:Cb, replacer:Db}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Bb, replacer:Db.concat([/(?!^)[aeo]/g, ""]), matcher:Cb}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +var Ib = /[\x00-\x7F]+/g; +var Jb = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Bb, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Cb}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Cb, matcher:Db, replacer:Eb}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Cb, replacer:Eb.concat([/(?!^)[aeo]/g, ""]), matcher:Db}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (var b = 0; b < a.length; b++) { - for (var c = a[b], d = c.charAt(0), e = Eb[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = Eb[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) { + for (var c = a[b], d = c.charAt(0), e = Fb[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = Fb[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) { } a[b] = d; } }}, ArabicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Fb, " "); + return ("" + a).replace(Gb, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Gb, ""); + return ("" + a).replace(Hb, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Hb, " "); + return ("" + a).replace(Ib, " "); }}}; -var Jb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +var Kb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; P.prototype.add = function(a, b, c, d) { if (b && (a || 0 === a)) { if (!d && !c && this.reg.has(a)) { @@ -2761,17 +2774,17 @@ P.prototype.add = function(a, b, c, d) { } b = this.encoder.encode(b); if (d = b.length) { - for (var e = J(), g = J(), f = this.depth, k = this.resolution, h = 0; h < d; h++) { - var l = b[this.rtl ? d - 1 - h : h], m = l.length; + for (var e = J(), g = J(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { + var l = b[this.rtl ? d - 1 - k : k], m = l.length; if (m && (f || !g[l])) { - var n = this.score ? this.score(b, l, h, null, 0) : Kb(k, d, h), p = ""; + var n = this.score ? this.score(b, l, k, null, 0) : Lb(h, d, k), p = ""; switch(this.tokenize) { case "full": if (2 < m) { n = 0; for (var q; n < m; n++) { for (var t = m; t > n; t--) { - p = l.substring(n, t), q = this.rtl ? m - 1 - n : n, q = this.score ? this.score(b, l, h, p, q) : Kb(k, d, h, m, q), Lb(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) : Lb(h, d, k, m, q), Mb(this, g, p, q, a, c); } } break; @@ -2779,24 +2792,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, h, p, t) : Kb(k, d, h, m, t), Lb(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) : Lb(h, d, k, m, t), Mb(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], Lb(this, g, p, n, a, c); + p += l[this.rtl ? m - 1 - t : t], Mb(this, g, p, n, a, c); } break; } default: - if (Lb(this, g, l, n, a, c), f && 1 < d && h < d - 1) { - for (m = J(), p = this.da, n = l, t = Math.min(f + 1, this.rtl ? h + 1 : d - h), q = m[n] = 1; q < t; q++) { - if ((l = b[this.rtl ? d - 1 - h - q : h + q]) && !m[l]) { + if (Mb(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, h, l, q - 1) : Kb(p + (d / 2 > p ? 0 : 1), d, h, t - 1, q - 1), r = this.bidirectional && l > n; - Lb(this, e, r ? n : l, w, a, c, r ? l : n); + var w = this.score ? this.score(b, n, k, l, q - 1) : Lb(p + (d / 2 > p ? 0 : 1), d, k, t - 1, q - 1), r = this.bidirectional && l > n; + Mb(this, e, r ? n : l, w, a, c, r ? l : n); } } } @@ -2808,28 +2821,28 @@ P.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.ca && Mb(this)); + this.db && (b || this.commit_task.push({del:a}), this.ca && Nb(this)); return this; }; -function Lb(a, b, c, d, e, g, f) { - var k = f ? a.ctx : a.map, h; - if (!b[c] || f && !(h = b[c])[f]) { - if (f ? (b = h || (b[c] = J()), b[f] = 1, (h = k.get(f)) ? k = h : k.set(f, k = new Map())) : b[c] = 1, (h = k.get(c)) ? k = h : k.set(c, k = h = []), k = k[d] || (k[d] = []), !g || !k.includes(e)) { - if (k.length === Math.pow(2, 31) - 1) { - b = new T(k); +function Mb(a, b, c, d, e, g, f) { + var h = f ? a.ctx : a.map, k; + if (!b[c] || f && !(k = b[c])[f]) { + if (f ? (b = k || (b[c] = J()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) { + if (h.length === Math.pow(2, 31) - 1) { + b = new T(h); if (a.fastupdate) { for (c = x(a.reg.values()), g = c.next(); !g.done; g = c.next()) { - g = g.value, g.includes(k) && (g[g.indexOf(k)] = b); + g = g.value, g.includes(h) && (g[g.indexOf(h)] = b); } } - h[d] = k = b; + k[d] = h = b; } - k.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(k) : a.reg.set(e, [k])); + h.push(e); + a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); } } } -function Kb(a, b, c, d, e) { +function Lb(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) { @@ -2840,8 +2853,8 @@ function Kb(a, b, c, d, e) { b = c.limit || b; e = c.offset || 0; var f = c.context; - var k = c.suggest; - var h = (g = !1 !== c.resolve) && c.enrich; + var h = c.suggest; + var k = (g = !1 !== c.resolve) && c.enrich; var l = c.boost; var m = c.resolution; var n = this.db && c.tag; @@ -2852,11 +2865,11 @@ function Kb(a, b, c, d, e) { var q = p.length; b = b || (g ? 100 : 0); if (1 === q) { - return Nb.call(this, p[0], "", b, e, g, h, n); + return Ob.call(this, p[0], "", b, e, g, k, n); } f = this.depth && !1 !== f; - if (2 === q && f && !k) { - return Nb.call(this, p[0], p[1], b, e, g, h, n); + if (2 === q && f && !h) { + return Ob.call(this, p[0], p[1], b, e, g, k, n); } var t = J(), w = 0; if (1 < q && f) { @@ -2865,7 +2878,7 @@ function Kb(a, b, c, d, e) { } m || 0 === m || (m = r ? this.da : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, p, b, e, k, g, h, n), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, p, b, e, h, g, k, n), !1 !== a)) { return a; } var A = this; @@ -2886,22 +2899,22 @@ function Kb(a, b, c, d, e) { break; } t[v] = 1; - return E(y, Ob(A, v, r, 0, 0, !1, !1), 6); + return E(y, Pb(A, v, r, 0, 0, !1, !1), 6); case 6: z = y.D; - if (z = Pb(z, d, k, m)) { + if (z = Qb(z, d, h, m)) { d = z; y.h = 4; break; } - r && (k && z && d.length || (r = v)); + r && (h && z && d.length || (r = v)); case 5: - k && r && w === q - 1 && !d.length && (m = A.resolution, r = "", w = -1, t = J()); + h && r && w === q - 1 && !d.length && (m = A.resolution, r = "", w = -1, t = J()); w++; y.h = 2; break; case 4: - return y.return(Qb(d, m, b, e, k, l, g)); + return y.return(Rb(d, m, b, e, h, l, g)); } }); }(); @@ -2909,33 +2922,33 @@ function Kb(a, b, c, d, e) { for (c = a = void 0; w < q; w++) { if ((c = p[w]) && !t[c]) { t[c] = 1; - a = Ob(this, c, r, 0, 0, !1, !1); - if (a = Pb(a, d, k, m)) { + a = Pb(this, c, r, 0, 0, !1, !1); + if (a = Qb(a, d, h, m)) { d = a; break; } - r && (k && a && d.length || (r = c)); + r && (h && a && d.length || (r = c)); } - k && r && w === q - 1 && !d.length && (m = this.resolution, r = "", w = -1, t = J()); + h && r && w === q - 1 && !d.length && (m = this.resolution, r = "", w = -1, t = J()); } - return Qb(d, m, b, e, k, l, g); + return Rb(d, m, b, e, h, l, g); }; -function Qb(a, b, c, d, e, g, f) { - var k = a.length, h = a; - if (1 < k) { - h = jb(a, b, c, d, e, g, f); - } else if (1 === k) { +function Rb(a, b, c, d, e, g, f) { + var h = a.length, k = a; + if (1 < h) { + k = jb(a, b, c, d, e, g, f); + } else if (1 === h) { return f ? mb.call(null, a[0], c, d) : new Y(a[0]); } - return f ? h : new Y(h); + return f ? k : new Y(k); } -function Nb(a, b, c, d, e, g, f) { - a = Ob(this, a, b, c, d, e, g, f); - return this.db ? a.then(function(k) { - return e ? k || [] : new Y(k); +function Ob(a, b, c, d, e, g, f) { + a = Pb(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 ? mb.call(this, a, c, d) : new Y(a) : e ? [] : new Y(); } -function Pb(a, b, c, d) { +function Qb(a, b, c, d) { var e = []; if (a && a.length) { if (a.length <= d) { @@ -2956,11 +2969,11 @@ function Pb(a, b, c, d) { return e; } } -function Ob(a, b, c, d, e, g, f, k) { - var h; - c && (h = a.bidirectional && b > c) && (h = c, c = b, b = h); +function Pb(a, b, c, d, e, g, f, h) { + var k; + c && (k = a.bidirectional && b > c) && (k = c, c = b, b = k); if (a.db) { - return a.db.get(b, c, d, e, g, f, k); + 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; @@ -2980,15 +2993,15 @@ function Ob(a, b, c, d, e, g, f, k) { } } } else { - Rb(this.map, a), this.depth && Rb(this.ctx, a); + Sb(this.map, a), this.depth && Sb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.ca && Mb(this)); + this.db && (this.commit_task.push({del:a}), this.ca && Nb(this)); this.cache && this.cache.remove(a); return this; }; -function Rb(a, b) { +function Sb(a, b) { var c = 0; if (a.constructor === Array) { for (var d = 0, e = void 0, g; d < a.length; d++) { @@ -3003,7 +3016,7 @@ function Rb(a, b) { } } else { for (d = x(a.entries()), e = d.next(); !e.done; e = d.next()) { - g = e.value, e = g[0], (g = Rb(g[1], b)) ? c += g : a.delete(e); + g = e.value, e = g[0], (g = Sb(g[1], b)) ? c += g : a.delete(e); } } return c; @@ -3014,12 +3027,12 @@ function Rb(a, b) { } if (a) { var c = K(a) ? a : a.preset; - c && (Jb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Jb[c], a)); + c && (Kb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Kb[c], a)); } else { a = {}; } c = a.context; - var d = !0 === c ? {depth:1} : c || {}, e = K(a.encoder) ? Ib[a.encoder] : a.encode || a.encoder || Ab; + var d = !0 === c ? {depth:1} : c || {}, e = K(a.encoder) ? Jb[a.encoder] : a.encode || a.encoder || Bb; this.encoder = e.encode ? e : "object" === typeof e ? new Ga(e) : {encode:e}; this.resolution = a.resolution || 9; this.tokenize = c = (c = a.tokenize) && "default" !== c && c || "strict"; @@ -3034,7 +3047,7 @@ function Rb(a, b) { this.reg = b || (this.fastupdate ? c ? new U(c) : new Map() : c ? new V(c) : new Set()); this.da = d.resolution || 3; this.rtl = e.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new Z(c); + this.cache = (c = a.cache || null) && new yb(c); this.resolve = !1 !== a.resolve; if (c = a.db) { this.db = this.mount(c); @@ -3057,7 +3070,7 @@ u.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Mb(a) { +function Nb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -3083,7 +3096,7 @@ u.update = function(a, b) { return c.add(a, b); }) : this.add(a, b); }; -function Sb(a) { +function Tb(a) { var b = 0; if (a.constructor === Array) { for (var c = 0, d = void 0; c < a.length; c++) { @@ -3093,7 +3106,7 @@ function Sb(a) { for (c = x(a.entries()), d = c.next(); !d.done; d = c.next()) { var e = d.value; d = e[0]; - (e = Sb(e[1])) ? b += e : a.delete(d); + (e = Tb(e[1])) ? b += e : a.delete(d); } } return b; @@ -3102,11 +3115,11 @@ u.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Sb(this.map); - this.depth && Sb(this.ctx); + Tb(this.map); + this.depth && Tb(this.ctx); return this; }; -u.searchCache = zb; +u.searchCache = Ab; u.export = function(a, b, c, d) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; @@ -3161,23 +3174,23 @@ u.serialize = function(a) { c = "index.map=new Map([" + c + "]);"; g = x(this.ctx.entries()); for (var f = g.next(); !f.done; f = g.next()) { - var k = f.value; - f = k[0]; - k = ab(k[1], e); - k = "new Map([" + k + "])"; - k = '["' + f + '",' + k + "]"; - d += (d ? "," : "") + k; + var h = f.value; + f = h[0]; + h = ab(h[1], e); + h = "new Map([" + h + "])"; + h = '["' + f + '",' + h + "]"; + d += (d ? "," : "") + h; } d = "index.ctx=new Map([" + d + "]);"; } return a ? "function inject(index){" + b + c + d + "}" : b + c + d; }; Ja(P.prototype); -var Tb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Ub = ["map", "ctx", "tag", "reg", "cfg"], Vb = J(); -function Wb(a, b) { +var Ub = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Vb = ["map", "ctx", "tag", "reg", "cfg"], Wb = J(); +function Xb(a, b) { b = void 0 === b ? {} : b; if (!this) { - return new Wb(a, b); + return new Xb(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -3188,7 +3201,7 @@ function Wb(a, b) { this.db = null; this.h = {}; } -u = Wb.prototype; +u = Xb.prototype; u.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -3197,57 +3210,49 @@ u.mount = function(a) { return this.open(); }; u.open = function() { + if (this.db) { + return this.db; + } var a = this; navigator.storage && navigator.storage.persist(); - return this.db || (this.db = new Promise(function(b, c) { - Vb[a.id] || (Vb[a.id] = []); - Vb[a.id].push(a.field); - var d = Tb.open(a.id, 1); - d.onupgradeneeded = function() { - for (var e = a.db = this.result, g = 0, f; g < Ub.length; g++) { - f = Ub[g]; - for (var k = 0, h; k < Vb[a.id].length; k++) { - h = Vb[a.id][k], e.objectStoreNames.contains(f + ("reg" !== f ? h ? ":" + h : "" : "")) || e.createObjectStore(f + ("reg" !== f ? h ? ":" + h : "" : "")); - } + Wb[a.id] || (Wb[a.id] = []); + Wb[a.id].push(a.field); + var b = Ub.open(a.id, 1); + b.onupgradeneeded = function() { + for (var c = a.db = this.result, d = 0, e; d < Vb.length; d++) { + e = Vb[d]; + for (var g = 0, f; g < Wb[a.id].length; g++) { + f = Wb[a.id][g], c.objectStoreNames.contains(e + ("reg" !== e ? f ? ":" + f : "" : "")) || c.createObjectStore(e + ("reg" !== e ? f ? ":" + f : "" : "")); } + } + }; + return a.db = Z(b, function(c) { + a.db = c; + a.db.onversionchange = function() { + a.close(); }; - d.onblocked = function(e) { - console.error("blocked", e); - c(); - }; - d.onerror = function(e) { - console.error(this.error, e); - c(); - }; - d.onsuccess = function() { - a.db = this.result; - a.db.onversionchange = function() { - a.close(); - }; - b(a); - }; - })); + }); }; u.close = function() { this.db && this.db.close(); this.db = null; }; u.destroy = function() { - var a = Tb.deleteDatabase(this.id); - return Xb(a); + var a = Ub.deleteDatabase(this.id); + return Z(a); }; u.clear = function() { - for (var a = [], b = 0, c; b < Ub.length; b++) { - c = Ub[b]; - for (var d = 0, e; d < Vb[this.id].length; d++) { - e = Vb[this.id][d], a.push(c + ("reg" !== c ? e ? ":" + e : "" : "")); + for (var a = [], b = 0, c; b < Vb.length; b++) { + c = Vb[b]; + for (var d = 0, e; d < Wb[this.id].length; d++) { + e = Wb[this.id][d], a.push(c + ("reg" !== c ? e ? ":" + e : "" : "")); } } b = this.db.transaction(a, "readwrite"); for (c = 0; c < a.length; c++) { b.objectStore(a[c]).clear(); } - return Xb(b); + return Z(b); }; u.get = function(a, b, c, d, e, g) { c = void 0 === c ? 0 : c; @@ -3256,33 +3261,33 @@ u.get = function(a, b, c, d, e, g) { g = void 0 === g ? !1 : g; a = this.db.transaction((b ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((b ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(b ? b + ":" + a : a); var f = this; - return Xb(a).then(function(k) { - var h = []; - if (!k || !k.length) { - return h; + return Z(a).then(function(h) { + var k = []; + if (!h || !h.length) { + return k; } if (e) { - if (!c && !d && 1 === k.length) { - return k[0]; + if (!c && !d && 1 === h.length) { + return h[0]; } - for (var l = 0, m = void 0; l < k.length; l++) { - if ((m = k[l]) && m.length) { + for (var l = 0, m = void 0; l < h.length; l++) { + if ((m = h[l]) && m.length) { if (d >= m.length) { d -= m.length; } else { for (var n = c ? d + Math.min(m.length - d, c) : m.length, p = d; p < n; p++) { - h.push(m[p]); + k.push(m[p]); } d = 0; - if (h.length === c) { + if (k.length === c) { break; } } } } - return g ? f.enrich(h) : h; + return g ? f.enrich(k) : k; } - return k; + return h; }); }; u.tag = function(a, b, c, d) { @@ -3291,7 +3296,7 @@ u.tag = function(a, b, c, d) { d = void 0 === d ? !1 : d; a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); var e = this; - return Xb(a).then(function(g) { + return Z(a).then(function(g) { if (!g || !g.length || c >= g.length) { return []; } @@ -3305,7 +3310,7 @@ u.tag = function(a, b, c, d) { u.enrich = function(a) { "object" !== typeof a && (a = [a]); for (var b = this.db.transaction("reg", "readonly").objectStore("reg"), c = [], d = 0; d < a.length; d++) { - c[d] = Xb(b.get(a[d])); + c[d] = Z(b.get(a[d])); } return Promise.all(c).then(function(e) { for (var g = 0; g < e.length; g++) { @@ -3316,7 +3321,7 @@ u.enrich = function(a) { }; u.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Xb(a).then(function(b) { + return Z(a).then(function(b) { return !!b; }); }; @@ -3324,34 +3329,27 @@ u.search = null; u.info = function() { }; u.transaction = function(a, b, c) { - var d = this, e = a + ("reg" !== a ? this.field ? ":" + this.field : "" : ""), g = this.h[e + ":" + b]; - if (g) { - return c.call(this, g); + a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; + var d = this.h[a + ":" + b]; + if (d) { + return c.call(this, d); } - var f = this.db.transaction(e, b); - this.h[e + ":" + b] = g = f.objectStore(e); - return new Promise(function(k, h) { - f.onerror = function(m) { - f.abort(); - f = g = null; - h(m); - }; - f.oncomplete = function(m) { - f = g = null; - k(m || !0); - }; - var l = c.call(d, g); - d.h[e + ":" + b] = null; - return l; + var e = this.db.transaction(a, b); + this.h[a + ":" + b] = d = e.objectStore(a); + var g = c.call(this, d); + this.h[a + ":" + b] = null; + return Z(e).finally(function() { + e = d = null; + return g; }); }; u.commit = function(a, b, c) { var d = this, e, g, f; - return ta(function(k) { - switch(k.h) { + return ta(function(h) { + switch(h.h) { case 1: if (b) { - return E(k, d.clear(), 12); + return E(h, d.clear(), 12); } e = a.commit_task; a.commit_task = []; @@ -3359,45 +3357,45 @@ u.commit = function(a, b, c) { f = void 0; case 4: if (!(g < e.length)) { - k.h = 6; + h.h = 6; break; } f = e[g]; if (!f.clear) { e[g] = f.del; - k.h = 5; + h.h = 5; break; } - return E(k, d.clear(), 8); + return E(h, d.clear(), 8); case 8: b = !0; - k.h = 6; + h.h = 6; break; case 5: g++; - k.h = 4; + h.h = 4; break; case 6: if (b) { - k.h = 3; + h.h = 3; break; } c || (e = e.concat(xa(a.reg))); if (!e.length) { - k.h = 10; + h.h = 10; break; } - return E(k, d.remove(e), 11); + return E(h, d.remove(e), 11); case 11: case 10: - k.h = 3; + h.h = 3; break; case 12: a.commit_task = []; case 3: - return a.reg.size ? E(k, d.transaction("map", "readwrite", function(h) { + return a.reg.size ? E(h, d.transaction("map", "readwrite", function(k) { for (var l = x(a.map), m = l.next(), n = {}; !m.done; n = {O:void 0, Y:void 0}, m = l.next()) { - m = m.value, n.Y = m[0], n.O = m[1], n.O.length && (b ? h.put(n.O, n.Y) : h.get(n.Y).onsuccess = function(p) { + m = m.value, n.Y = m[0], n.O = m[1], n.O.length && (b ? k.put(n.O, n.Y) : k.get(n.Y).onsuccess = function(p) { return function() { var q = this.result, t; if (q && q.length) { @@ -3416,19 +3414,19 @@ u.commit = function(a, b, c) { } else { q = p.O, t = 1; } - t && h.put(q, p.Y); + t && k.put(q, p.Y); }; }(n)); } - }), 13) : k.return(); + }), 13) : h.return(); case 13: - return E(k, d.transaction("ctx", "readwrite", function(h) { + return E(h, d.transaction("ctx", "readwrite", function(k) { for (var l = x(a.ctx), m = l.next(), n = {}; !m.done; n = {V:void 0}, m = l.next()) { m = m.value; n.V = m[0]; m = x(m[1]); for (var p = m.next(), q = {}; !p.done; q = {P:void 0, Z:void 0}, p = m.next()) { - p = p.value, q.Z = p[0], q.P = p[1], q.P.length && (b ? h.put(q.P, n.V + ":" + q.Z) : h.get(n.V + ":" + q.Z).onsuccess = function(t, w) { + p = p.value, q.Z = p[0], q.P = p[1], q.P.length && (b ? k.put(q.P, n.V + ":" + q.Z) : k.get(n.V + ":" + q.Z).onsuccess = function(t, w) { return function() { var r = this.result, A; if (r && r.length) { @@ -3447,7 +3445,7 @@ u.commit = function(a, b, c) { } else { r = t.P, A = 1; } - A && h.put(r, w.V + ":" + t.Z); + A && k.put(r, w.V + ":" + t.Z); }; }(q, n)); } @@ -3455,80 +3453,80 @@ u.commit = function(a, b, c) { }), 14); case 14: if (a.store) { - return E(k, d.transaction("reg", "readwrite", function(h) { + return E(h, d.transaction("reg", "readwrite", function(k) { for (var l = x(a.store), m = l.next(); !m.done; m = l.next()) { var n = m.value; m = n[0]; n = n[1]; - h.put("object" === typeof n ? JSON.stringify(n) : 1, m); + k.put("object" === typeof n ? JSON.stringify(n) : 1, m); } }), 16); } if (a.bypass) { - k.h = 16; + h.h = 16; break; } - return E(k, d.transaction("reg", "readwrite", function(h) { + return E(h, d.transaction("reg", "readwrite", function(k) { for (var l = x(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { - h.put(1, m.value); + k.put(1, m.value); } }), 16); case 16: if (!a.tag) { - k.h = 20; + h.h = 20; break; } - return E(k, d.transaction("tag", "readwrite", function(h) { + return E(h, d.transaction("tag", "readwrite", function(k) { for (var l = x(a.tag), m = l.next(), n = {}; !m.done; n = {X:void 0, ba:void 0}, m = l.next()) { - m = m.value, n.ba = m[0], n.X = m[1], n.X.length && (h.get(n.ba).onsuccess = function(p) { + m = m.value, n.ba = m[0], n.X = m[1], n.X.length && (k.get(n.ba).onsuccess = function(p) { return function() { var q = this.result; q = q && q.length ? q.concat(p.X) : p.X; - h.put(q, p.ba); + k.put(q, p.ba); }; }(n)); } }), 20); case 20: - a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear(), k.h = 0; + a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear(), h.h = 0; } }); }; function $b(a, b, c) { - for (var d = a.value, e, g, f = 0, k = 0, h; k < d.length; k++) { - if (h = c ? d : d[k]) { - for (var l = 0, m, n; l < b.length; l++) { - if (n = b[l], m = h.indexOf(g ? parseInt(n, 10) : n), 0 > m && !g && "string" === typeof n && !isNaN(n) && (m = h.indexOf(parseInt(n, 10))) && (g = 1), 0 <= m) { + 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++) { + if (l = b[k], l = h.indexOf(l), 0 <= l) { if (e = 1, 1 < h.length) { - h.splice(m, 1); + h.splice(l, 1); } else { - d[k] = []; + d[f] = []; break; } } } - f += h.length; + g += h.length; } if (c) { break; } } - f ? e && a.update(d) : a.delete(); + g ? e && a.update(d) : a.delete(); a.continue(); } u.remove = function(a) { "object" !== typeof a && (a = [a]); - return Promise.all([this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function(b) { + return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; c && $b(c, a); }; - }), this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function(b) { + }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; c && $b(c, a); }; - }), this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function(b) { + }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; c && $b(c, a, !0); @@ -3539,19 +3537,18 @@ u.remove = function(a) { } })]); }; -function Xb(a) { - return new Promise(function(b, c) { - a.onsuccess = function() { - b(this.result); +function Z(a, b) { + return new Promise(function(c, d) { + a.onsuccess = a.oncomplete = function() { + b && b(this.result); + b = null; + c(this.result); }; - a.oncomplete = function() { - b(); - }; - a.onerror = c; + a.onerror = a.onblocked = d; a = null; }); } -;var ac = {Index:P, Charset:Ib, Encoder:Ga, Document:W, Worker:Sa, Resolver:Y, IndexedDB:Wb, Language:{}}, bc = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self, cc; +;var ac = {Index:P, Charset:Jb, Encoder:Ga, Document:W, Worker:Sa, Resolver:Y, IndexedDB:Xb, Language:{}}, bc = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self, cc; (cc = bc.define) && cc.amd ? cc([], function() { return ac; }) : "object" === typeof bc.exports ? bc.exports = ac : bc.FlexSearch = ac; diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index 883a793..e5ef107 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.138 (ES5) + * FlexSearch.js v0.8.140 (ES5) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -35,7 +35,8 @@ g.value[1]!=g.value[0]?!1:e.next().done}catch(f){return!1}}())return a;b.prototy b.prototype.values;b.prototype.forEach=function(c,d){var e=this;this.h.forEach(function(g){return c.call(d,g,g,e)})};return b});C("Array.prototype.entries",function(a){return a?a:function(){return va(this,function(b,c){return[b,c]})}});C("Object.is",function(a){return a?a:function(b,c){return b===c?0!==b||1/b===1/c:b!==b&&c!==c}}); C("Array.prototype.includes",function(a){return a?a:function(b,c){var d=this;d instanceof String&&(d=String(d));var e=d.length;c=c||0;for(0>c&&(c=Math.max(c+e,0));c"a1a".split(c).length; -this.numeric=H(a.numeric,e)}else{try{this.split=H(this.split,Ba)}catch(g){this.split=/\s+/}this.numeric=H(a.numeric,H(this.numeric,!0))}this.prepare=H(a.prepare,null,this.prepare);this.finalize=H(a.finalize,null,this.finalize);Fa||(this.mapper=new Map(Aa));c=a.filter;this.filter="function"===typeof c?c:H(c&&new Set(c),null,this.filter);this.dedupe=H(a.dedupe,!1,this.dedupe);this.matcher=H((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=H((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= -H((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=H(a.replacer,null,this.replacer);this.minlength=H(a.minlength,1,this.minlength);this.maxlength=H(a.maxlength,0,this.maxlength);this.rtl=H(a.rtl,!1,this.rtl);if(this.cache=c=H(a.cache,!0,this.cache))this.D=null,this.T="number"===typeof c?c:2E5,this.B=new Map,this.C=new Map,this.H=this.G=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(a=x(this.matcher.keys()),b=a.next();!b.done;b=a.next())this.h+=(this.h?"|":"")+b.value; +u.assign=function(a){this.normalize=G(a.normalize,!0,this.normalize);var b=a.include,c=b||a.exclude||a.split;if(c||""===c){if("object"===typeof c&&c.constructor!==RegExp){var d="";var e=!b;b||(d+="\\p{Z}");c.letter&&(d+="\\p{L}");c.number&&(d+="\\p{N}",e=!!b);c.symbol&&(d+="\\p{S}");c.punctuation&&(d+="\\p{P}");c.control&&(d+="\\p{C}");if(c=c.char)d+="object"===typeof c?c.join(""):c;try{this.split=new RegExp("["+(b?"^":"")+d+"]+","u")}catch(g){this.split=/\s+/}}else this.split=c,e=!1===c||2>"a1a".split(c).length; +this.numeric=G(a.numeric,e)}else{try{this.split=G(this.split,Ba)}catch(g){this.split=/\s+/}this.numeric=G(a.numeric,G(this.numeric,!0))}this.prepare=G(a.prepare,null,this.prepare);this.finalize=G(a.finalize,null,this.finalize);Fa||(this.mapper=new Map(Aa));c=a.filter;this.filter="function"===typeof c?c:G(c&&new Set(c),null,this.filter);this.dedupe=G(a.dedupe,!1,this.dedupe);this.matcher=G((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=G((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= +G((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=G(a.replacer,null,this.replacer);this.minlength=G(a.minlength,1,this.minlength);this.maxlength=G(a.maxlength,0,this.maxlength);this.rtl=G(a.rtl,!1,this.rtl);if(this.cache=c=G(a.cache,!0,this.cache))this.D=null,this.T="number"===typeof c?c:2E5,this.B=new Map,this.C=new Map,this.H=this.G=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(a=x(this.matcher.keys()),b=a.next();!b.done;b=a.next())this.h+=(this.h?"|":"")+b.value; if(this.stemmer)for(a=x(this.stemmer.keys()),b=a.next();!b.done;b=a.next())this.A+=(this.A?"|":"")+b.value;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&N(this);return this};u.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&N(this);return this}; u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&N(this);return this}; u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&N(this);return this}; @@ -85,18 +86,18 @@ function rb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(fu function sb(a,b,c,d,e){for(var g=[],f=J(),h=0,k=0,l;kc||d)a=a.slice(d,d+c);e&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;c=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c): -m.length,p=d;p=g.length)return[];if(!b&&!c)return g;g=g.slice(c,c+b);return d?e.enrich(g):g})}; -u.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length, +p=d;p=g.length)return[];if(!b&&!c)return g;g=g.slice(c,c+b);return d?e.enrich(g):g})}; +u.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;dm&&!g&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(g=1),0<=m)if(e=1,1 [key, res, id] performs - // too bad and blows up amazingly in size - // The schema map:key => [res][id] is currently used instead - // In fact that bypass the idea of a storage solution, - // 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]; - 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 }); - } + const db = self.db = this.result; + + // Using Indexes + IDBKeyRange on schema map => [key, res, id] performs + // too bad and blows up amazingly in size + // The schema map:key => [res][id] is currently used instead + // In fact that bypass the idea of a storage solution, + // 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]; + 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 }); } + } - // switch(event.oldVersion){ // existing db version - // case 0: - // // version 0 means that the client had no database - // // perform initialization - // case 1: - // // client had version 1 - // // update - // } - }; + // switch(event.oldVersion){ // existing db version + // case 0: + // // version 0 means that the client had no database + // // perform initialization + // case 1: + // // client had version 1 + // // update + // } + }; - req.onblocked = function (event) { - // this event shouldn't trigger if we handle onversionchange correctly - // it means that there's another open connection to the same database - // and it wasn't closed after db.onversionchange triggered for it - console.error("blocked", event); - reject(); + return self.db = promisfy(req, function (result) { + self.db = result; //event.target.result; + self.db.onversionchange = function () { + //database is outdated + self.close(); }; + }); - req.onerror = function (event) { - console.error(this.error, event); - reject(); - }; - - req.onsuccess = function () { - self.db = this.result; //event.target.result; - self.db.onversionchange = function () { - //database is outdated - self.close(); - }; - resolve(self); - }; - })); + // req.onblocked = function(event) { + // // this event shouldn't trigger if we handle onversionchange correctly + // // it means that there's another open connection to the same database + // // and it wasn't closed after db.onversionchange triggered for it + // console.error("blocked", event); + // reject(); + // }; + // + // req.onerror = function(event){ + // console.error(this.error, event); + // reject(); + // }; + // + // req.onsuccess = function(event){ + // self.db = this.result; //event.target.result; + // self.db.onversionchange = function(){ + // //database is outdated + // self.close(); + // }; + // resolve(self); + // }; + // }); }; IdxDB.prototype.close = function () { @@ -304,31 +315,37 @@ IdxDB.prototype.transaction = function (ref, modifier, task) { */ let store = this.trx[key + ":" + modifier]; if (store) return task.call(this, store); - let transaction = this.db.transaction(key, modifier); /** * @type {IDBObjectStore} */ this.trx[key + ":" + modifier] = store = transaction.objectStore(key); + const promise = task.call(this, store); + this.trx[key + ":" + modifier] = null; - return new Promise((resolve, reject) => { - transaction.onerror = err => { - transaction.abort(); - transaction = store = null; - reject(err); - //db.close; - }; - transaction.oncomplete = res => { - transaction = store = null; - resolve(res || !0); - //db.close; - }; - const promise = task.call(this, store); - // transactions can just be used within the same event loop - // the indexeddb is such a stupid tool :( - this.trx[key + ":" + modifier] = null; + return promisfy(transaction).finally(function () { + transaction = store = null; return promise; }); + + // return new Promise((resolve, reject) => { + // transaction.onerror = (err) => { + // transaction.abort(); + // transaction = store = null; + // reject(err); + // //db.close; + // }; + // transaction.oncomplete = (res) => { + // transaction = store = null; + // resolve(res || true); + // //db.close; + // }; + // const promise = task.call(this, store); + // // transactions can just be used within the same event loop + // // the indexeddb is such a stupid tool :( + // this.trx[key + ":" + modifier] = null; + // return promise; + // }); }; IdxDB.prototype.commit = async function (flexsearch, _replace, _append) { @@ -541,7 +558,6 @@ function handle(cursor, ids, _tag) { const arr = cursor.value; let changed, - parse, count = 0; @@ -550,11 +566,7 @@ function handle(cursor, ids, _tag) { if (result = _tag ? arr : arr[x]) { for (let i = 0, pos, id; i < ids.length; i++) { id = ids[i]; - pos = result.indexOf(parse ? parseInt(id, 10) : id); - if (0 > pos && !parse && "string" == typeof id && !isNaN(id)) { - pos = result.indexOf(parseInt(id, 10)); - pos && (parse = 1); - } + pos = result.indexOf(id); if (0 <= pos) { changed = 1; if (1 < result.length) { @@ -572,11 +584,9 @@ function handle(cursor, ids, _tag) { } if (!count) { - cursor.delete(); //store.delete(cursor.key); } else if (changed) { - //await new Promise(resolve => { cursor.update(arr); //.onsuccess = resolve; //}); @@ -591,28 +601,30 @@ function handle(cursor, ids, _tag) { */ IdxDB.prototype.remove = function (ids) { + const self = this; + if ("object" != typeof ids) { ids = [ids]; } - return (/** @type {!Promise} */Promise.all([this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { + return (/** @type {!Promise} */Promise.all([self.transaction("map", "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids); }; - }), this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { + }), self.transaction("ctx", "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids); }; - }), this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { + }), self.transaction("tag", "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids, !0); }; }), // let filtered = []; - this.transaction("reg", "readwrite", function (store) { + self.transaction("reg", "readwrite", function (store) { for (let i = 0; i < ids.length; i++) { store.delete(ids[i]); } @@ -639,23 +651,21 @@ IdxDB.prototype.remove = function (ids) { }; /** - * @param {IDBRequest} req + * @param {IDBRequest|IDBOpenDBRequest} req * @param {Function=} callback * @return {!Promise} */ function promisfy(req, callback) { return new Promise((resolve, reject) => { - /** @this {IDBRequest} */ - req.onsuccess = function () { + // oncomplete is used for transaction + /** @this {IDBRequest|IDBOpenDBRequest} */ + req.onsuccess = req.oncomplete = function () { callback && callback(this.result); + callback = null; resolve(this.result); }; - req.oncomplete = function () { - callback && callback(); - resolve(); - }; - req.onerror = reject; + req.onerror = req.onblocked = reject; req = null; }); } \ No newline at end of file diff --git a/dist/module-debug/db/mongodb/index.js b/dist/module-debug/db/mongodb/index.js index 76a3497..03a7d40 100644 --- a/dist/module-debug/db/mongodb/index.js +++ b/dist/module-debug/db/mongodb/index.js @@ -464,6 +464,8 @@ MongoDB.prototype.commit = async function (flexsearch, _replace, _append) { return; } + const promises = []; + if (flexsearch.map.size) { let data = []; for (const item of flexsearch.map) { @@ -484,8 +486,7 @@ MongoDB.prototype.commit = async function (flexsearch, _replace, _append) { } } if (data.length) { - await this.db.collection("map" + this.field).insertMany(data); - flexsearch.map.clear(); + promises.push(this.db.collection("map" + this.field).insertMany(data)); } } @@ -514,27 +515,23 @@ MongoDB.prototype.commit = async function (flexsearch, _replace, _append) { } } if (data.length) { - await this.db.collection("ctx" + this.field).insertMany(data); - flexsearch.ctx.clear(); + promises.push(this.db.collection("ctx" + this.field).insertMany(data)); } } if (flexsearch.tag) { let data = []; - if (flexsearch.tag) { - for (const item of flexsearch.tag) { - const tag = item[0], - ids = item[1]; + for (const item of flexsearch.tag) { + const tag = item[0], + ids = item[1]; - if (!ids.length) continue; - for (let j = 0; j < ids.length; j++) { - data.push({ tag, id: ids[j] }); - } + if (!ids.length) continue; + for (let j = 0; j < ids.length; j++) { + data.push({ tag, id: ids[j] }); } } if (data.length) { - await this.db.collection("tag" + this.field).insertMany(data); - flexsearch.tag.clear(); + promises.push(this.db.collection("tag" + this.field).insertMany(data)); } } @@ -552,11 +549,17 @@ MongoDB.prototype.commit = async function (flexsearch, _replace, _append) { } } if (data.length) { - await this.db.collection("reg").insertMany(data); - flexsearch.store && flexsearch.store.clear(); - flexsearch.document || flexsearch.reg.clear(); + promises.push(this.db.collection("reg").insertMany(data)); } + await Promise.all(promises); + + flexsearch.map.clear(); + flexsearch.ctx.clear(); + flexsearch.tag && flexsearch.tag.clear(); + flexsearch.store && flexsearch.store.clear(); + flexsearch.document || flexsearch.reg.clear(); + // TODO // await this.db.collection("cfg" + this.field).insertOne({ // "encode": typeof flexsearch.encode === "string" ? flexsearch.encode : "", diff --git a/dist/module-debug/db/postgres/index.js b/dist/module-debug/db/postgres/index.js index caf208a..8c96b4b 100644 --- a/dist/module-debug/db/postgres/index.js +++ b/dist/module-debug/db/postgres/index.js @@ -61,7 +61,8 @@ export default function PostgresDB(name, config = {}) { this.id = (config.schema ? sanitize(config.schema) : defaults.schema) + (name ? "_" + sanitize(name) : ""); this.field = config.field ? "_" + sanitize(config.field) : ""; this.type = config.type ? types[config.type.toLowerCase()] : "text"; - this.support_tag_search = /* tag? */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ + 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); @@ -607,7 +608,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-debug/db/sqlite/index.js b/dist/module-debug/db/sqlite/index.js index 3b6f068..35df78b 100644 --- a/dist/module-debug/db/sqlite/index.js +++ b/dist/module-debug/db/sqlite/index.js @@ -550,10 +550,10 @@ SqliteDB.prototype.info = function () { // todo }; -SqliteDB.prototype.transaction = function (task, callback) { +SqliteDB.prototype.transaction = async function (task, callback) { if (TRX[this.id]) { - return task.call(this); + return await task.call(this); } const db = this.db, diff --git a/dist/module-debug/document.js b/dist/module-debug/document.js index 653aade..b7b4404 100644 --- a/dist/module-debug/document.js +++ b/dist/module-debug/document.js @@ -204,7 +204,7 @@ Document.prototype.commit = async function (replace, append) { // parallel: const promises = []; for (const index of this.index.values()) { - promises.push(index.commit(index, replace, append)); + promises.push(index.commit(replace, append)); } await Promise.all(promises); this.reg.clear(); diff --git a/dist/module-min/db/clickhouse/index.js b/dist/module-min/db/clickhouse/index.js index 1232606..a8f82b4 100644 --- a/dist/module-min/db/clickhouse/index.js +++ b/dist/module-min/db/clickhouse/index.js @@ -76,10 +76,10 @@ import{ClickHouse}from"clickhouse";import StorageInterface from"../interface.js" SELECT id, doc FROM ${this.id}.reg WHERE id IN (${g})`,{params:f}).toPromise();if(h&&h.length){for(let a,b=0;bm;k+=(k?" OR ":"")+`(ctx = {ctx${c}:String} AND key = {key${c}:String})`,l["ctx"+c]=d?j:m,l["key"+c]=d?m:j,m=j}if(h){k="("+k+")";for(let a=0,b=1;am;k+=(k?" OR ":"")+`(ctx = {ctx${c}:String} AND key = {key${c}:String})`,l["ctx"+c]=d?j:m,l["key"+c]=d?m:j,m=j}if(h){k="("+k+")";for(let a=0,b=1;a=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{f.onerror=a=>{f.abort(),f=e=null,g(a)},f.oncomplete=b=>{f=e=null,a(b||!0)};const h=c.call(this,e);return this.trx[d+":"+b]=null,h})},IdxDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;ca)||f||"string"!=typeof c||isNaN(c)||(a=h.indexOf(parseInt(c,10)),a&&(f=1)),0<=a)if(e=1,1{a.onsuccess=function(){b&&b(this.result),c(this.result)},a.oncomplete=function(){b&&b(),c()},a.onerror=d,a=null})} \ No newline at end of file +import{PersistentOptions,SearchResults,EnrichedSearchResults}from"../../type.js";const VERSION=1,IndexedDB="undefined"!=typeof window&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),IDBTransaction="undefined"!=typeof window&&(window.IDBTransaction||window.webkitIDBTransaction||window.msIDBTransaction),IDBKeyRange="undefined"!=typeof window&&(window.IDBKeyRange||window.webkitIDBKeyRange||window.msIDBKeyRange),fields=["map","ctx","tag","reg","cfg"];import StorageInterface from"../interface.js";import{create_object,toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}const DB=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(),DB[a.id]||(DB[a.id]=[]),DB[a.id].push(a.field);const b=IndexedDB.open(a.id,VERSION);return b.onupgradeneeded=function(){const b=a.db=this.result;for(let c,d=0;d=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b{a.onsuccess=a.oncomplete=function(){b&&b(this.result),b=null,c(this.result)},a.onerror=a.onblocked=d,a=null})} \ No newline at end of file diff --git a/dist/module-min/db/mongodb/index.js b/dist/module-min/db/mongodb/index.js index 8dad3f9..997be94 100644 --- a/dist/module-min/db/mongodb/index.js +++ b/dist/module-min/db/mongodb/index.js @@ -1 +1 @@ -import{MongoClient}from"mongodb";const defaults={host:"localhost",port:"27017",user:null,pass:null},VERSION=1,fields=["map","ctx","tag","reg","cfg"];import StorageInterface from"../interface.js";import{toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}let CLIENT,DB=Object.create(null);export default function MongoDB(a,b={}){return this?void("object"==typeof a&&(b=a,a=a.name),!a&&console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(a?"-"+sanitize(a):""),this.field=b.field?"-"+sanitize(b.field):"",this.type=b.type||"",this.db=b.db||DB[this.id]||CLIENT||null,this.trx=!1,this.support_tag_search=!0,Object.assign(defaults,b),this.db&&delete defaults.db):new MongoDB(a,b)}MongoDB.prototype.mount=function(a){return a.encoder?(a.db=this,this.open()):a.mount(this)};async function createCollection(a,b,c){"map"===b?(await a.createCollection("map"+c),await a.collection("map"+c).createIndex({key:1}),await a.collection("map"+c).createIndex({id:1})):"ctx"===b?(await a.createCollection("ctx"+c),await a.collection("ctx"+c).createIndex({ctx:1,key:1}),await a.collection("ctx"+c).createIndex({id:1})):"tag"===b?(await a.createCollection("tag"+c),await a.collection("tag"+c).createIndex({tag:1}),await a.collection("tag"+c).createIndex({id:1})):"reg"===b?(await a.createCollection("reg"),await a.collection("reg").createIndex({id:1})):"cfg"===b?await a.createCollection("cfg"+c):void 0}MongoDB.prototype.open=async function(){if(!this.db&&!(this.db=DB[this.id])&&!(this.db=CLIENT)){let a=defaults.url;a||(a=defaults.user?`mongodb://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}`:`mongodb://${defaults.host}:${defaults.port}`),this.db=CLIENT=new MongoClient(a),await this.db.connect()}this.db.db&&(this.db=DB[this.id]=this.db.db(this.id));const a=await this.db.listCollections().toArray();for(let b,c=0;cl;k.push({ctx:d?j:l,key:d?l:j}),l=j}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;bMAXIMUM_QUERY_VARS)&&(this.db.run("INSERT INTO main.map"+this.field+" (key, res, id) VALUES "+c,e),c="",e=[])}}for(const b of a.ctx){const a=b[0],c=b[1];for(const b of c){const c=b[0],d=b[1];for(let b,e=0;eMAXIMUM_QUERY_VARS)&&(this.db.run("INSERT INTO main.ctx"+this.field+" (ctx, key, res, id) VALUES "+d,f),d="",f=[])}}}if(a.store){let b="",c=[];for(const d of a.store.entries()){const a=d[0],e=d[1];b+=(b?",":"")+"(?,?)",c.push(a,"object"==typeof e?JSON.stringify(e):e||null),c.length+2>MAXIMUM_QUERY_VARS&&(this.db.run("INSERT INTO main.reg (id, doc) VALUES "+b,c),b="",c=[])}c.length&&this.db.run("INSERT INTO main.reg (id, doc) VALUES "+b,c)}else if(!a.bypass){let b=toArray(a.reg);for(let a=0;aMAXIMUM_QUERY_VARS?b.slice(a,a+MAXIMUM_QUERY_VARS):a?b.slice(a):b;a+=c.length;const d=build_params(c.length,!0);this.db.run("INSERT INTO main.reg (id) VALUES "+d,c)}}if(a.tag){let b="",c=[];for(const d of a.tag){const a=d[0],e=d[1];if(e.length){for(let d=0;dMAXIMUM_QUERY_VARS&&(this.db.run("INSERT INTO main.tag"+this.field+" (tag, id) VALUES "+b,c),b="",c=[])}}c.length&&this.db.run("INSERT INTO main.tag"+this.field+" (tag, id) VALUES "+b,c)}}),a.map.clear(),a.ctx.clear(),a.tag&&a.tag.clear(),a.store&&a.store.clear(),a.document||a.reg.clear())},SqliteDB.prototype.remove=function(a){"object"!=typeof a&&(a=[a]);let b;a.length>MAXIMUM_QUERY_VARS&&(b=a.slice(MAXIMUM_QUERY_VARS),a=a.slice(0,MAXIMUM_QUERY_VARS));const c=this;return this.transaction(function(){const b=build_params(a.length);this.db.run("DELETE FROM main.map"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.ctx"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.tag"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.reg WHERE id IN ("+b+")",a)}).then(function(a){return b?c.remove(b):a})},SqliteDB.prototype.promisfy=function(a){const b=this.db;return new Promise(function(c,d){b[a.method](a.stmt,a.params||[],function(b,e){a.callback&&a.callback(e),b?d(b):c(e)})})}; \ No newline at end of file + `,params:b})}return i.then(function(a){return create_result(a,f,g)})},SqliteDB.prototype.info=function(){},SqliteDB.prototype.transaction=async function(a,b){if(TRX[this.id])return await a.call(this);const c=this.db,d=this;return TRX[this.id]=new Promise(function(e,f){c.exec("PRAGMA optimize"),c.exec("PRAGMA busy_timeout = 5000"),c.exec("BEGIN"),c.parallelize(function(){a.call(d)}),c.exec("COMMIT",function(a,g){return TRX[d.id]=null,a?f(a):void(b&&b(g),e(g),c.exec("PRAGMA shrink_memory"))})})},SqliteDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;cMAXIMUM_QUERY_VARS)&&(this.db.run("INSERT INTO main.map"+this.field+" (key, res, id) VALUES "+c,e),c="",e=[])}}for(const b of a.ctx){const a=b[0],c=b[1];for(const b of c){const c=b[0],d=b[1];for(let b,e=0;eMAXIMUM_QUERY_VARS)&&(this.db.run("INSERT INTO main.ctx"+this.field+" (ctx, key, res, id) VALUES "+d,f),d="",f=[])}}}if(a.store){let b="",c=[];for(const d of a.store.entries()){const a=d[0],e=d[1];b+=(b?",":"")+"(?,?)",c.push(a,"object"==typeof e?JSON.stringify(e):e||null),c.length+2>MAXIMUM_QUERY_VARS&&(this.db.run("INSERT INTO main.reg (id, doc) VALUES "+b,c),b="",c=[])}c.length&&this.db.run("INSERT INTO main.reg (id, doc) VALUES "+b,c)}else if(!a.bypass){let b=toArray(a.reg);for(let a=0;aMAXIMUM_QUERY_VARS?b.slice(a,a+MAXIMUM_QUERY_VARS):a?b.slice(a):b;a+=c.length;const d=build_params(c.length,!0);this.db.run("INSERT INTO main.reg (id) VALUES "+d,c)}}if(a.tag){let b="",c=[];for(const d of a.tag){const a=d[0],e=d[1];if(e.length){for(let d=0;dMAXIMUM_QUERY_VARS&&(this.db.run("INSERT INTO main.tag"+this.field+" (tag, id) VALUES "+b,c),b="",c=[])}}c.length&&this.db.run("INSERT INTO main.tag"+this.field+" (tag, id) VALUES "+b,c)}}),a.map.clear(),a.ctx.clear(),a.tag&&a.tag.clear(),a.store&&a.store.clear(),a.document||a.reg.clear())},SqliteDB.prototype.remove=function(a){"object"!=typeof a&&(a=[a]);let b;a.length>MAXIMUM_QUERY_VARS&&(b=a.slice(MAXIMUM_QUERY_VARS),a=a.slice(0,MAXIMUM_QUERY_VARS));const c=this;return this.transaction(function(){const b=build_params(a.length);this.db.run("DELETE FROM main.map"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.ctx"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.tag"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.reg WHERE id IN ("+b+")",a)}).then(function(a){return b?c.remove(b):a})},SqliteDB.prototype.promisfy=function(a){const b=this.db;return new Promise(function(c,d){b[a.method](a.stmt,a.params||[],function(b,e){a.callback&&a.callback(e),b?d(b):c(e)})})}; \ No newline at end of file diff --git a/dist/module-min/document.js b/dist/module-min/document.js index 2087919..e59f613 100644 --- a/dist/module-min/document.js +++ b/dist/module-min/document.js @@ -1 +1 @@ -import{IndexOptions,DocumentOptions,DocumentDescriptor,FieldOptions,StoreOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Cache,{searchCache}from"./cache.js";import{is_string,is_object,parse_simple}from"./common.js";import apply_async from"./async.js";import{exportDocument,importDocument}from"./serialize.js";import{KeystoreMap,KeystoreSet}from"./keystore.js";import"./document/add.js";import"./document/search.js";export default function Document(a){if(!this||this.constructor!==Document)return new Document(a);const b=a.document||a.doc||a;let c,d;if(this.tree=[],this.field=[],this.marker=[],this.key=(c=b.key||b.id)&&parse_tree(c,this.marker)||"id",d=a.keystore||0,d&&(this.keystore=d),this.fastupdate=!!a.fastupdate,this.reg=!this.fastupdate||a.worker||a.db?d&&!0?new KeystoreSet(d):new Set:d&&!0?new KeystoreMap(d):new Map,this.storetree=(c=b.store||null)&&c&&!0!==c&&[],this.store=c&&(d&&!0?new KeystoreMap(d):new Map),this.cache=(c=a.cache||null)&&new Cache(c),a.cache=!1,this.worker=a.worker,this.priority=a.priority||4,this.index=parse_descriptor.call(this,a,b),(this.tag=null,(c=b.tag)&&("string"==typeof c&&(c=[c]),c.length))){this.tag=new Map,this.tagtree=[],this.tagfield=[];for(let a,b,d=0;d [key, res, id] performs - // too bad and blows up amazingly in size - // The schema map:key => [res][id] is currently used instead - // In fact that bypass the idea of a storage solution, - // 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]; - 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 }); - } + const db = self.db = this.result; + + // Using Indexes + IDBKeyRange on schema map => [key, res, id] performs + // too bad and blows up amazingly in size + // The schema map:key => [res][id] is currently used instead + // In fact that bypass the idea of a storage solution, + // 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]; + 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 }); } + } - // switch(event.oldVersion){ // existing db version - // case 0: - // // version 0 means that the client had no database - // // perform initialization - // case 1: - // // client had version 1 - // // update - // } - }; + // switch(event.oldVersion){ // existing db version + // case 0: + // // version 0 means that the client had no database + // // perform initialization + // case 1: + // // client had version 1 + // // update + // } + }; - req.onblocked = function (event) { - // this event shouldn't trigger if we handle onversionchange correctly - // it means that there's another open connection to the same database - // and it wasn't closed after db.onversionchange triggered for it - console.error("blocked", event); - reject(); + return self.db = promisfy(req, function (result) { + self.db = result; //event.target.result; + self.db.onversionchange = function () { + //database is outdated + self.close(); }; + }); - req.onerror = function (event) { - console.error(this.error, event); - reject(); - }; - - req.onsuccess = function () { - self.db = this.result; //event.target.result; - self.db.onversionchange = function () { - //database is outdated - self.close(); - }; - resolve(self); - }; - })); + // req.onblocked = function(event) { + // // this event shouldn't trigger if we handle onversionchange correctly + // // it means that there's another open connection to the same database + // // and it wasn't closed after db.onversionchange triggered for it + // console.error("blocked", event); + // reject(); + // }; + // + // req.onerror = function(event){ + // console.error(this.error, event); + // reject(); + // }; + // + // req.onsuccess = function(event){ + // self.db = this.result; //event.target.result; + // self.db.onversionchange = function(){ + // //database is outdated + // self.close(); + // }; + // resolve(self); + // }; + // }); }; IdxDB.prototype.close = function () { @@ -304,31 +315,37 @@ IdxDB.prototype.transaction = function (ref, modifier, task) { */ let store = this.trx[key + ":" + modifier]; if (store) return task.call(this, store); - let transaction = this.db.transaction(key, modifier); /** * @type {IDBObjectStore} */ this.trx[key + ":" + modifier] = store = transaction.objectStore(key); + const promise = task.call(this, store); + this.trx[key + ":" + modifier] = null; - return new Promise((resolve, reject) => { - transaction.onerror = err => { - transaction.abort(); - transaction = store = null; - reject(err); - //db.close; - }; - transaction.oncomplete = res => { - transaction = store = null; - resolve(res || !0); - //db.close; - }; - const promise = task.call(this, store); - // transactions can just be used within the same event loop - // the indexeddb is such a stupid tool :( - this.trx[key + ":" + modifier] = null; + return promisfy(transaction).finally(function () { + transaction = store = null; return promise; }); + + // return new Promise((resolve, reject) => { + // transaction.onerror = (err) => { + // transaction.abort(); + // transaction = store = null; + // reject(err); + // //db.close; + // }; + // transaction.oncomplete = (res) => { + // transaction = store = null; + // resolve(res || true); + // //db.close; + // }; + // const promise = task.call(this, store); + // // transactions can just be used within the same event loop + // // the indexeddb is such a stupid tool :( + // this.trx[key + ":" + modifier] = null; + // return promise; + // }); }; IdxDB.prototype.commit = async function (flexsearch, _replace, _append) { @@ -541,7 +558,6 @@ function handle(cursor, ids, _tag) { const arr = cursor.value; let changed, - parse, count = 0; @@ -550,11 +566,7 @@ function handle(cursor, ids, _tag) { if (result = _tag ? arr : arr[x]) { for (let i = 0, pos, id; i < ids.length; i++) { id = ids[i]; - pos = result.indexOf(parse ? parseInt(id, 10) : id); - if (0 > pos && !parse && "string" == typeof id && !isNaN(id)) { - pos = result.indexOf(parseInt(id, 10)); - pos && (parse = 1); - } + pos = result.indexOf(id); if (0 <= pos) { changed = 1; if (1 < result.length) { @@ -572,11 +584,9 @@ function handle(cursor, ids, _tag) { } if (!count) { - cursor.delete(); //store.delete(cursor.key); } else if (changed) { - //await new Promise(resolve => { cursor.update(arr); //.onsuccess = resolve; //}); @@ -591,28 +601,30 @@ function handle(cursor, ids, _tag) { */ IdxDB.prototype.remove = function (ids) { + const self = this; + if ("object" != typeof ids) { ids = [ids]; } - return (/** @type {!Promise} */Promise.all([this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { + return (/** @type {!Promise} */Promise.all([self.transaction("map", "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids); }; - }), this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { + }), self.transaction("ctx", "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids); }; - }), this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { + }), self.transaction("tag", "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids, !0); }; }), // let filtered = []; - this.transaction("reg", "readwrite", function (store) { + self.transaction("reg", "readwrite", function (store) { for (let i = 0; i < ids.length; i++) { store.delete(ids[i]); } @@ -639,23 +651,21 @@ IdxDB.prototype.remove = function (ids) { }; /** - * @param {IDBRequest} req + * @param {IDBRequest|IDBOpenDBRequest} req * @param {Function=} callback * @return {!Promise} */ function promisfy(req, callback) { return new Promise((resolve, reject) => { - /** @this {IDBRequest} */ - req.onsuccess = function () { + // oncomplete is used for transaction + /** @this {IDBRequest|IDBOpenDBRequest} */ + req.onsuccess = req.oncomplete = function () { callback && callback(this.result); + callback = null; resolve(this.result); }; - req.oncomplete = function () { - callback && callback(); - resolve(); - }; - req.onerror = reject; + req.onerror = req.onblocked = reject; req = null; }); } \ No newline at end of file diff --git a/dist/module/db/mongodb/index.js b/dist/module/db/mongodb/index.js index 76a3497..03a7d40 100644 --- a/dist/module/db/mongodb/index.js +++ b/dist/module/db/mongodb/index.js @@ -464,6 +464,8 @@ MongoDB.prototype.commit = async function (flexsearch, _replace, _append) { return; } + const promises = []; + if (flexsearch.map.size) { let data = []; for (const item of flexsearch.map) { @@ -484,8 +486,7 @@ MongoDB.prototype.commit = async function (flexsearch, _replace, _append) { } } if (data.length) { - await this.db.collection("map" + this.field).insertMany(data); - flexsearch.map.clear(); + promises.push(this.db.collection("map" + this.field).insertMany(data)); } } @@ -514,27 +515,23 @@ MongoDB.prototype.commit = async function (flexsearch, _replace, _append) { } } if (data.length) { - await this.db.collection("ctx" + this.field).insertMany(data); - flexsearch.ctx.clear(); + promises.push(this.db.collection("ctx" + this.field).insertMany(data)); } } if (flexsearch.tag) { let data = []; - if (flexsearch.tag) { - for (const item of flexsearch.tag) { - const tag = item[0], - ids = item[1]; + for (const item of flexsearch.tag) { + const tag = item[0], + ids = item[1]; - if (!ids.length) continue; - for (let j = 0; j < ids.length; j++) { - data.push({ tag, id: ids[j] }); - } + if (!ids.length) continue; + for (let j = 0; j < ids.length; j++) { + data.push({ tag, id: ids[j] }); } } if (data.length) { - await this.db.collection("tag" + this.field).insertMany(data); - flexsearch.tag.clear(); + promises.push(this.db.collection("tag" + this.field).insertMany(data)); } } @@ -552,11 +549,17 @@ MongoDB.prototype.commit = async function (flexsearch, _replace, _append) { } } if (data.length) { - await this.db.collection("reg").insertMany(data); - flexsearch.store && flexsearch.store.clear(); - flexsearch.document || flexsearch.reg.clear(); + promises.push(this.db.collection("reg").insertMany(data)); } + await Promise.all(promises); + + flexsearch.map.clear(); + flexsearch.ctx.clear(); + flexsearch.tag && flexsearch.tag.clear(); + flexsearch.store && flexsearch.store.clear(); + flexsearch.document || flexsearch.reg.clear(); + // TODO // await this.db.collection("cfg" + this.field).insertOne({ // "encode": typeof flexsearch.encode === "string" ? flexsearch.encode : "", diff --git a/dist/module/db/postgres/index.js b/dist/module/db/postgres/index.js index caf208a..8c96b4b 100644 --- a/dist/module/db/postgres/index.js +++ b/dist/module/db/postgres/index.js @@ -61,7 +61,8 @@ export default function PostgresDB(name, config = {}) { this.id = (config.schema ? sanitize(config.schema) : defaults.schema) + (name ? "_" + sanitize(name) : ""); this.field = config.field ? "_" + sanitize(config.field) : ""; this.type = config.type ? types[config.type.toLowerCase()] : "text"; - this.support_tag_search = /* tag? */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ + 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); @@ -607,7 +608,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/sqlite/index.js b/dist/module/db/sqlite/index.js index 3b6f068..35df78b 100644 --- a/dist/module/db/sqlite/index.js +++ b/dist/module/db/sqlite/index.js @@ -550,10 +550,10 @@ SqliteDB.prototype.info = function () { // todo }; -SqliteDB.prototype.transaction = function (task, callback) { +SqliteDB.prototype.transaction = async function (task, callback) { if (TRX[this.id]) { - return task.call(this); + return await task.call(this); } const db = this.db, diff --git a/dist/module/document.js b/dist/module/document.js index 2778e32..34c134c 100644 --- a/dist/module/document.js +++ b/dist/module/document.js @@ -200,7 +200,7 @@ Document.prototype.commit = async function (replace, append) { // parallel: const promises = []; for (const index of this.index.values()) { - promises.push(index.commit(index, replace, append)); + promises.push(index.commit(replace, append)); } await Promise.all(promises); this.reg.clear(); diff --git a/example/nodejs-commonjs/document-worker-export-import/package.json b/example/nodejs-commonjs/document-worker-export-import/package.json index e04e4ba..fd8f6c0 100644 --- a/example/nodejs-commonjs/document-worker-export-import/package.json +++ b/example/nodejs-commonjs/document-worker-export-import/package.json @@ -1,6 +1,6 @@ { "name": "nodejs-commonjs-document-worker-export-import", "dependencies": { - "flexsearch": "github:nextapps-de/flexsearch" + "flexsearch": "^0.8.138" } } diff --git a/example/nodejs-esm/document-worker-export-import/package.json b/example/nodejs-esm/document-worker-export-import/package.json index d8a38df..5380081 100644 --- a/example/nodejs-esm/document-worker-export-import/package.json +++ b/example/nodejs-esm/document-worker-export-import/package.json @@ -2,6 +2,6 @@ "name": "nodejs-esm-document-worker-export-import", "type": "module", "dependencies": { - "flexsearch": "github:nextapps-de/flexsearch" + "flexsearch": "^0.8.138" } } diff --git a/package-lock.json b/package-lock.json index 0117b2f..32e9c73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.138", + "version": "0.8.141", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.138", + "version": "0.8.141", "funding": [ { "type": "github", diff --git a/package.json b/package.json index 40d304e..821b647 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.138", + "version": "0.8.140", "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", diff --git a/src/db/clickhouse/index.js b/src/db/clickhouse/index.js index 59fd133..50d9474 100644 --- a/src/db/clickhouse/index.js +++ b/src/db/clickhouse/index.js @@ -338,13 +338,13 @@ ClickhouseDB.prototype.enrich = async function(ids){ ClickhouseDB.prototype.has = async function(id){ const result = await this.db.query(` - SELECT 1 as exist + SELECT 1 FROM ${this.id}.reg WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}} LIMIT 1`, { params: { id }} ).toPromise(); - return !!(result && result[0] && result[0].exist); + return !!(result && result[0] && result[0]["1"]); }; ClickhouseDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ @@ -530,6 +530,8 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ return; } + const promises = []; + if(flexsearch.map.size){ let data = []; for(const item of flexsearch.map){ @@ -551,9 +553,9 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.insert( + promises.push(this.db.insert( `INSERT INTO ${ this.id }.map${ this.field } (key, res, id)`, data - ).toPromise(); + ).toPromise()); } } @@ -582,9 +584,9 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.insert( + promises.push(this.db.insert( `INSERT INTO ${ this.id }.ctx${ this.field } (ctx, key, res, id)`, data - ).toPromise(); + ).toPromise()); } } @@ -599,9 +601,9 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.insert( + promises.push(this.db.insert( `INSERT INTO ${this.id}.tag${ this.field } (tag, id)`, data - ).toPromise(); + ).toPromise()); } } @@ -613,9 +615,9 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ data.push({ id, doc: doc && JSON.stringify(doc) }); } if(data.length){ - await this.db.insert( + promises.push(this.db.insert( `INSERT INTO ${this.id}.reg (id, doc)`, data - ).toPromise(); + ).toPromise()); } } else if(!flexsearch.bypass){ @@ -624,9 +626,9 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ data[i] = { id: data[i] }; } if(data.length){ - await this.db.insert( + promises.push(this.db.insert( `INSERT INTO ${this.id}.reg (id)`, data - ).toPromise(); + ).toPromise()); } } @@ -649,6 +651,8 @@ ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ // }) // }]).toPromise(); + await Promise.all(promises); + flexsearch.map.clear(); flexsearch.ctx.clear(); flexsearch.tag && diff --git a/src/db/indexeddb/index.js b/src/db/indexeddb/index.js index bb0ff67..8c73606 100644 --- a/src/db/indexeddb/index.js +++ b/src/db/indexeddb/index.js @@ -80,17 +80,20 @@ IdxDB.prototype.mount = function(flexsearch){ IdxDB.prototype.open = function(){ + if(this.db) return this.db; let self = this; navigator.storage && navigator.storage.persist(); - return this.db || (this.db = new Promise(function(resolve, reject){ + // return this.db = new Promise(function(resolve, reject){ DB[self.id] || (DB[self.id] = []); DB[self.id].push(self.field); const req = IndexedDB.open(self.id, VERSION); + + /** @this {IDBOpenDBRequest} */ req.onupgradeneeded = function(event){ const db = self.db = this.result; @@ -120,28 +123,36 @@ IdxDB.prototype.open = function(){ // } }; - req.onblocked = function(event) { - // this event shouldn't trigger if we handle onversionchange correctly - // it means that there's another open connection to the same database - // and it wasn't closed after db.onversionchange triggered for it - console.error("blocked", event); - reject(); - }; - - req.onerror = function(event){ - console.error(this.error, event); - reject(); - }; - - req.onsuccess = function(event){ - self.db = this.result; //event.target.result; + return self.db = promisfy(req, function(result){ + self.db = result; //event.target.result; self.db.onversionchange = function(){ //database is outdated self.close(); }; - resolve(self); - }; - })); + }); + + // req.onblocked = function(event) { + // // this event shouldn't trigger if we handle onversionchange correctly + // // it means that there's another open connection to the same database + // // and it wasn't closed after db.onversionchange triggered for it + // console.error("blocked", event); + // reject(); + // }; + // + // req.onerror = function(event){ + // console.error(this.error, event); + // reject(); + // }; + // + // req.onsuccess = function(event){ + // self.db = this.result; //event.target.result; + // self.db.onversionchange = function(){ + // //database is outdated + // self.close(); + // }; + // resolve(self); + // }; + // }); }; IdxDB.prototype.close = function(){ @@ -336,31 +347,37 @@ IdxDB.prototype.transaction = function(ref, modifier, task){ */ let store = this.trx[key + ":" + modifier]; if(store) return task.call(this, store); - let transaction = this.db.transaction(key, modifier); /** * @type {IDBObjectStore} */ this.trx[key + ":" + modifier] = store = transaction.objectStore(key); + const promise = task.call(this, store); + this.trx[key + ":" + modifier] = null; - return new Promise((resolve, reject) => { - transaction.onerror = (err) => { - transaction.abort(); - transaction = store = null; - reject(err); - //db.close; - }; - transaction.oncomplete = (res) => { - transaction = store = null; - resolve(res || true); - //db.close; - }; - const promise = task.call(this, store); - // transactions can just be used within the same event loop - // the indexeddb is such a stupid tool :( - this.trx[key + ":" + modifier] = null; + return promisfy(transaction).finally(function(){ + transaction = store = null; return promise; }); + + // return new Promise((resolve, reject) => { + // transaction.onerror = (err) => { + // transaction.abort(); + // transaction = store = null; + // reject(err); + // //db.close; + // }; + // transaction.oncomplete = (res) => { + // transaction = store = null; + // resolve(res || true); + // //db.close; + // }; + // const promise = task.call(this, store); + // // transactions can just be used within the same event loop + // // the indexeddb is such a stupid tool :( + // this.trx[key + ":" + modifier] = null; + // return promise; + // }); }; IdxDB.prototype.commit = async function(flexsearch, _replace, _append){ @@ -585,7 +602,6 @@ function handle(cursor, ids, _tag){ const arr = cursor.value; let changed; - let parse; let count = 0; for(let x = 0, result; x < arr.length; x++){ @@ -593,11 +609,7 @@ function handle(cursor, ids, _tag){ if((result = _tag ? arr : arr[x])){ for(let i = 0, pos, id; i < ids.length; i++){ id = ids[i]; - pos = result.indexOf(parse ? parseInt(id, 10) : id); - if(pos < 0 && !parse && typeof id === "string" && !isNaN(id)){ - pos = result.indexOf(parseInt(id, 10)); - pos && (parse = 1); - } + pos = result.indexOf(id); if(pos >= 0){ changed = 1; if(result.length > 1){ @@ -616,12 +628,10 @@ function handle(cursor, ids, _tag){ } if(!count){ - cursor.delete(); //store.delete(cursor.key); } else if(changed){ - //await new Promise(resolve => { cursor.update(arr);//.onsuccess = resolve; //}); @@ -636,31 +646,33 @@ function handle(cursor, ids, _tag){ */ IdxDB.prototype.remove = function(ids){ + const self = this; + if(typeof ids !== "object"){ ids = [ids]; } return /** @type {!Promise} */(Promise.all([ - this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ + self.transaction("map", "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids); }; }), - this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ + self.transaction("ctx", "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids); }; }), - SUPPORT_TAGS && this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ + SUPPORT_TAGS && self.transaction("tag", "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids, /* tag? */ true); }; }), // let filtered = []; - this.transaction("reg", "readwrite", function(store){ + self.transaction("reg", "readwrite", function(store){ for(let i = 0; i < ids.length; i++){ store.delete(ids[i]); } @@ -686,23 +698,21 @@ IdxDB.prototype.remove = function(ids){ }; /** - * @param {IDBRequest} req + * @param {IDBRequest|IDBOpenDBRequest} req * @param {Function=} callback * @return {!Promise} */ function promisfy(req, callback){ return new Promise((resolve, reject) => { - /** @this {IDBRequest} */ - req.onsuccess = function(){ + // oncomplete is used for transaction + /** @this {IDBRequest|IDBOpenDBRequest} */ + req.onsuccess = req.oncomplete = function(){ callback && callback(this.result); + callback = null; resolve(this.result); }; - req.oncomplete = function(){ - callback && callback(); - resolve(); - }; - req.onerror = reject; + req.onerror = req.onblocked = reject; req = null; }); } diff --git a/src/db/mongodb/index.js b/src/db/mongodb/index.js index ce98cd8..96808e6 100644 --- a/src/db/mongodb/index.js +++ b/src/db/mongodb/index.js @@ -569,6 +569,8 @@ MongoDB.prototype.commit = async function(flexsearch, _replace, _append){ return; } + const promises = []; + if(flexsearch.map.size){ let data = []; for(const item of flexsearch.map){ @@ -588,8 +590,9 @@ MongoDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.collection("map" + this.field).insertMany(data); - flexsearch.map.clear(); + promises.push( + this.db.collection("map" + this.field).insertMany(data) + ); } } @@ -616,26 +619,26 @@ MongoDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.collection("ctx" + this.field).insertMany(data); - flexsearch.ctx.clear(); + promises.push( + this.db.collection("ctx" + this.field).insertMany(data) + ); } } if(flexsearch.tag){ let data = []; - if(flexsearch.tag){ - for(const item of flexsearch.tag){ - const tag = item[0]; - const ids = item[1]; - if(!ids.length) continue; - for(let j = 0; j < ids.length; j++){ - data.push({ tag, id: ids[j] }); - } + for(const item of flexsearch.tag){ + const tag = item[0]; + const ids = item[1]; + if(!ids.length) continue; + for(let j = 0; j < ids.length; j++){ + data.push({ tag, id: ids[j] }); } } if(data.length){ - await this.db.collection("tag" + this.field).insertMany(data); - flexsearch.tag.clear(); + promises.push( + this.db.collection("tag" + this.field).insertMany(data) + ); } } @@ -653,13 +656,22 @@ MongoDB.prototype.commit = async function(flexsearch, _replace, _append){ } } if(data.length){ - await this.db.collection("reg").insertMany(data); - flexsearch.store && - flexsearch.store.clear(); - flexsearch.document || - flexsearch.reg.clear(); + promises.push( + this.db.collection("reg").insertMany(data) + ); } + await Promise.all(promises); + + flexsearch.map.clear(); + flexsearch.ctx.clear(); + flexsearch.tag && + flexsearch.tag.clear(); + flexsearch.store && + flexsearch.store.clear(); + flexsearch.document || + flexsearch.reg.clear(); + // TODO // await this.db.collection("cfg" + this.field).insertOne({ // "encode": typeof flexsearch.encode === "string" ? flexsearch.encode : "", diff --git a/src/db/sqlite/index.js b/src/db/sqlite/index.js index 6ab2152..70a09f0 100644 --- a/src/db/sqlite/index.js +++ b/src/db/sqlite/index.js @@ -568,10 +568,10 @@ SqliteDB.prototype.info = function(){ // todo }; -SqliteDB.prototype.transaction = function(task, callback){ +SqliteDB.prototype.transaction = async function(task, callback){ if(TRX[this.id]){ - return task.call(this); + return await task.call(this); } const db = this.db; diff --git a/src/document.js b/src/document.js index 2c5b885..40d48a5 100644 --- a/src/document.js +++ b/src/document.js @@ -241,7 +241,7 @@ if(SUPPORT_PERSISTENT){ // parallel: const promises = []; for(const index of this.index.values()){ - promises.push(index.commit(index, replace, append)); + promises.push(index.commit(replace, append)); } await Promise.all(promises); this.reg.clear(); diff --git a/src/document/search.js b/src/document/search.js index e834ba2..bfb2d9b 100644 --- a/src/document/search.js +++ b/src/document/search.js @@ -655,7 +655,7 @@ function get_tag(tag, key, limit, offset, enrich){ export function apply_enrich(ids){ - if(!this || !this.store) return ids; + if(!SUPPORT_STORE || !this || !this.store) return ids; /** @type {EnrichedSearchResults} */ const result = new Array(ids.length);