From 809119b492918b07d757b1983dd84091c71db098 Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Thu, 22 May 2025 11:00:45 +0200 Subject: [PATCH] fix indexing empty fields fix redis clear --- dist/db/redis/index.cjs | 21 ++++++++----- dist/flexsearch.bundle.debug.js | 4 +-- dist/flexsearch.bundle.min.js | 4 +-- dist/flexsearch.bundle.module.debug.js | 4 +-- dist/flexsearch.bundle.module.min.js | 4 +-- 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 | 4 +-- dist/flexsearch.es5.min.js | 4 +-- 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/redis/index.js | 6 +++- dist/module-debug/document/add.js | 4 --- dist/module-min/db/redis/index.js | 2 +- dist/module-min/document/add.js | 2 +- dist/module/db/redis/index.js | 6 +++- dist/module/document/add.js | 4 --- doc/resolver-consecutive.svg | 2 +- doc/resolver-parallel.svg | 2 +- doc/resolver.md | 39 ++++++++++++++++++------- package-lock.json | 4 +-- src/db/redis/index.js | 21 ++++++++----- src/document/add.js | 10 +++---- test/issues.js | 26 ++++------------- 28 files changed, 98 insertions(+), 91 deletions(-) diff --git a/dist/db/redis/index.cjs b/dist/db/redis/index.cjs index 8bc6cfa..6102b03 100644 --- a/dist/db/redis/index.cjs +++ b/dist/db/redis/index.cjs @@ -108,14 +108,19 @@ RedisDB.prototype.destroy = function(){ }; RedisDB.prototype.clear = function(){ - return this.db.unlink([ - this.id + "map" + this.field, - this.id + "ctx" + this.field, - this.id + "tag" + this.field, - this.id + "cfg" + this.field, - this.id + "doc", - this.id + "reg" - ]); + if(!this.id) return; + const self = this; + return this.db.keys( + this.id + "*" + + + + + + + ).then(function(keys){ + return keys.length && self.db.unlink(keys); + }); }; function create_result(range, type, resolve, enrich, resolution){ diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 1e9d38f..2a9a782 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.200 (Bundle/Debug) + * FlexSearch.js v0.8.201 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -789,8 +789,6 @@ function Oa(a, c, b, e, d, f, g, h) { g = c[++e], Oa(a, c, b, e, d, f, g, h); } } - } else { - d.db && d.remove(f); } } ;function Sa(a, c, b, e) { diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index b2680c7..ed4863c 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.200 (Bundle) + * FlexSearch.js v0.8.201 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -34,7 +34,7 @@ function Ma(a,c,b){return c?"undefined"!==typeof module?new(require("worker_thre "module/worker/worker.js"),{type:"module"})};Na.prototype.add=function(a,c,b){ba(a)&&(c=a,a=ea(c,this.key));if(c&&(a||0===a)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hc?a.slice(b,b+c):a,e?Ta.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}g=g.slice(b,b+c);h=g.length;b=0}h>c&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?Ta.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1c?a.slice(b,b+c):a,e?Ta.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}g=g.slice(b,b+c);h=g.length;b=0}h>c&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?Ta.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ya(a,c,b,!1,this.h),b=0));d&&(this.await=null);return d?this.resolve(c,b,e):this};Y.prototype.and=function(){return Ua(this,"and",Za,arguments)};function Za(a,c,b,e,d,f){if(!f&&!this.result.length)return d?this.result:this;let g;if(a.length)if(this.result.length&&a.unshift(this.result),2>a.length)this.result=a[0];else{let h=0;for(let k=0,m,l;kc?a.slice(b,b+c):a,e?Ta.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}g=g.slice(b,b+c);h=g.length;b=0}h>c&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?Ta.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1c?a.slice(b,b+c):a,e?Ta.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}g=g.slice(b,b+c);h=g.length;b=0}h>c&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?Ta.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ya(a,c,b,!1,this.h),b=0));d&&(this.await=null);return d?this.resolve(c,b,e):this};Y.prototype.and=function(){return Ua(this,"and",Za,arguments)};function Za(a,c,b,e,d,f){if(!f&&!this.result.length)return d?this.result:this;let g;if(a.length)if(this.result.length&&a.unshift(this.result),2>a.length)this.result=a[0];else{let h=0;for(let k=0,m,l;kb?a.slice(c,c+b):a,d?tb.call(this,a):a;for(var e=[],g=0,f=void 0,h=void 0;g=h){c-=h;continue}f=f.slice(c,c+b);h=f.length;c=0}h>b&&(f=f.slice(0,b),h=b);if(!e.length&&h>=b)return d?tb.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1b?a.slice(c,c+b):a,d?tb.call(this,a):a;for(var e=[],g=0,f=void 0,h=void 0;g=h){c-=h;continue}f=f.slice(c,c+b);h=f.length;c=0}h>b&&(f=f.slice(0,b),h=b);if(!e.length&&h>=b)return d?tb.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=yb(a,b,c,!1,this.h),c=0));e&&(this.await=null);return e?this.resolve(b,c,d):this};Z.prototype.and=function(){return ub(this,"and",zb,arguments)};function zb(a,b,c,d,e,g){if(!g&&!this.result.length)return e?this.result:this;if(a.length)if(this.result.length&&a.unshift(this.result),2>a.length)this.result=a[0];else{for(var f=0,h=0,k=void 0,l=void 0;hconsole.error(a)).connect()},RedisDB.prototype.close=async function(){return DB&&(await this.db.disconnect()),this.db=DB=null,this},RedisDB.prototype.destroy=function(){return this.clear()},RedisDB.prototype.clear=function(){return this.db.unlink([this.id+"map"+this.field,this.id+"ctx"+this.field,this.id+"tag"+this.field,this.id+"cfg"+this.field,this.id+"doc",this.id+"reg"])};function create_result(a,b,c,d,e){if(c){for(let c,e,f=0;f=a.length)return[];if(!b&&!c)return a;const f=a.slice(c,c+b);return d?e.enrich(f):f})},RedisDB.prototype.enrich=function(a){return"object"!=typeof a&&(a=[a]),this.db.hmGet(this.id+"doc","number"===this.type?a.map(a=>""+a):a).then(function(b){for(let c=0;ce,k.push(c+(f?d:e)+":"+(f?e:d)),l.push(1),e=d}else{const a=this.id+"map"+this.field+":";for(let c=0;cconsole.error(a)).connect()},RedisDB.prototype.close=async function(){return DB&&(await this.db.disconnect()),this.db=DB=null,this},RedisDB.prototype.destroy=function(){return this.clear()},RedisDB.prototype.clear=function(){if(!this.id)return;const a=this;return this.db.keys(this.id+"*").then(function(b){return b.length&&a.db.unlink(b)})};function create_result(a,b,c,d,e){if(c){for(let c,e,f=0;f=a.length)return[];if(!b&&!c)return a;const f=a.slice(c,c+b);return d?e.enrich(f):f})},RedisDB.prototype.enrich=function(a){return"object"!=typeof a&&(a=[a]),this.db.hmGet(this.id+"doc","number"===this.type?a.map(a=>""+a):a).then(function(b){for(let c=0;ce,k.push(c+(f?d:e)+":"+(f?e:d)),l.push(1),e=d}else{const a=this.id+"map"+this.field+":";for(let c=0;c -
Resolver
Resolver
DB
DB
NOT
NOT
Result
Result
AND
AND
OR
OR
NOT
NOT
Resolve
Resolve
OR
OR
AND
AND
\ No newline at end of file +
Resolver
Resolver
DB
DB
NOT
NOT
Result
Result
AND
AND
OR
OR
NOT
NOT
Resolve
Resolve
OR
OR
AND
AND
\ No newline at end of file diff --git a/doc/resolver-parallel.svg b/doc/resolver-parallel.svg index 3632630..b52e037 100644 --- a/doc/resolver-parallel.svg +++ b/doc/resolver-parallel.svg @@ -1,3 +1,3 @@ -
Resolver
Resolver
DB
DB
NOT
NOT
Result
Result
AND
AND
OR
OR
NOT
NOT
Resolve
Resolve
OR
OR
AND
AND
\ No newline at end of file +
Resolver
Resolver
DB
DB
NOT
NOT
Result
Result
AND
AND
OR
OR
NOT
NOT
Resolve
Resolve
OR
OR
AND
AND
\ No newline at end of file diff --git a/doc/resolver.md b/doc/resolver.md index 0d9b76d..29202c1 100644 --- a/doc/resolver.md +++ b/doc/resolver.md @@ -1,4 +1,4 @@ -## Resolver +## Resolver (Complex Queries) Retrieve an unresolved result: @@ -63,7 +63,8 @@ const raw2 = index.search("another query", { // 2. apply and chain resolver operations const raw3 = raw1.and(raw2, /* ... */); -// you can access the aggregated result by raw3.result +// raw1 has changed, raw2 is same, raw3 refers to raw1 +// you can access the raw result by console.log("The aggregated result is:", raw3.result) // apply further operations ... @@ -186,6 +187,26 @@ const resolver = new Resolver({ const result = await resolver.resolve(100); ``` +When you need to access the raw result `resolver.result` you should await for the task completion of all added resolver stages up to this point. + +```js +const resolver = new Resolver({ + index: index, + query: "a query", + async: true +}) +.and({ + query: "another query", + async: true +}); + +// await for the task completion +await resolver.await; +// get the raw result +const raw = resolver.result; +// continue adding further tasks ... +``` + ### Queuing Async Queries All queued tasks will run consecutively, also balanced by the runtime observer: @@ -212,19 +233,15 @@ When tasks are processed consecutively, it will skip specific resolver stages wh ### Compare Parallel VS. Consecutive -When using the parallel workflow, all resolver stages will send their requests (including nested tasks) to the DB immediately and calculate the results in the right order as soon as the request resolves. When the overall workload of your applications has some free resources, a parallel request workflow improves performance compared to the consecutive counterpart. +When using the parallel workflow by passing `{ async: true }`, all resolver stages will send their requests (including nested tasks) to the DB immediately and calculate the results in the right order as soon as the request resolves. When the overall workload of your applications has some free resources, a parallel request workflow improves performance compared to the consecutive counterpart. -

- -

+
---- +

-When using the consecutive workflow, all resolver stages will send their requests (including nested tasks) to the DB only when the previous request resolves. The advantage of this variant is when a stage becomes invalid because of the previous result, it can skip the request completely and continue with the next stage. This can reduce the overall workload. +When using the consecutive workflow by passing `{ queue: true }`, all resolver stages will send their requests (including nested tasks) to the DB only when the previous request resolves. The advantage of this variant is when a stage becomes invalid because of the previous result, it can skip the request completely and continue with the next stage. This can reduce the overall workload. -

- -

+