Closed dfanchon closed 2 years ago
same here
same issue here.
I had a quick look at the sources and I think the issue is: https://github.com/nextapps-de/flexsearch/blob/65b027ca316ceefd8ea89f472561a0f91179b2f3/src/index.js#L444-L447
when doing a multi-field search on a document flexsearch appears to call search on each index without setting query
. if query
were set then length
would be assigned in this block of code: https://github.com/nextapps-de/flexsearch/blob/master/src/index.js#L405-L442
But because that block is not being executed length
is not set and therefore search
returns early (without results).
(I haven't checked my findings yet because I don't currently have a device nearby that I can use for a testing environment)
If I'm right either Document.search
needs to retrieve query
from opt
and pass it along or this has to be done inside Index.search
if no query
was provided.
Ok, finally got around to testing it and this fixes it for me:
This block could to be changed to include e.g.:
query = query || options["query"];
The source of the issue is L481 in document.js
.query
remains undefined
in the example used by @dfanchon because options["query"]
is not defined in that case.
This would be a fix targeting document.js
directly instead of the fix i suggested above in index.js
:
diff --git a/src/document.js b/src/document.js
index 25da47c..9df6471 100644
--- a/src/document.js
+++ b/src/document.js
@@ -558,7 +558,8 @@ Document.prototype.search = function(query, limit, options, _resolve){
if(!is_string(key)){
opt = key;
- key = key["field"];
+ key = opt["field"];
+ query = query || opt["query"];
}
if(promises){
ups, nevermind. my second fix doesn't work as intended because in the second iteration of the loop query
has already been set and remains the same for all remaining iterations.
I guess it could be solved by either introducing a new variable or something like this:
diff --git a/src/document.js b/src/document.js
index 25da47c..5fd44c5 100644
--- a/src/document.js
+++ b/src/document.js
@@ -563,7 +563,7 @@ Document.prototype.search = function(query, limit, options, _resolve){
if(promises){
- promises[i] = this.index[key].searchAsync(query, limit, opt || options);
+ promises[i] = this.index[key].searchAsync((opt && opt["query"]) || query, limit, opt || options);
// just collect and continue
@@ -577,7 +577,7 @@ Document.prototype.search = function(query, limit, options, _resolve){
// inherit options also when search? it is just for laziness, Object.assign() has a cost
- res = this.index[key].search(query, limit, opt || options);
+ res = this.index[key].search((opt && opt["query"]) || query, limit, opt || options);
}
len = res && res.length;
but performance-wise both of these solutions might not be optimal. so for now I will stick to my first suggestion (to modify index.js
) but changing the order around to give precedence to opt["query"]
over query
:
diff --git a/src/index.js b/src/index.js
index 782ee0e..797cda8 100644
--- a/src/index.js
+++ b/src/index.js
@@ -400,6 +400,7 @@ Index.prototype.search = function(query, limit, options){
offset = options["offset"] || 0;
context = options["context"];
suggest = SUPPORT_SUGGESTION && options["suggest"];
+ query = options["query"] || query;
}
if(query){
@theguy147 have you considered making a PR?
@theguy147 when is the next release planned with the fix?
@GanserITService he won't be able to tell you that since he's not a contributor, but a user.
@micheljung I had thought about opening a PR but because I didn't know if my fix is good enough I thought explaining what the problem is and what could be changed might be just as good. I did anyway open that PR now and referenced this issue for the details.
@GanserITService Yes, as @micheljung said, I am not a contributor in this project and therefore have no say in this ;) Hopefully soon :)
Update: @ts-thomas just merged the fix into master, so it should be fixed if you're on current master now
@theguy147 do you have any idea how this works with {enrich: true}
? I feel like there's another bug :)
I also face this bug, what would be the workaround?
I also face this bug, what would be the workaround?
I think the stable production version should not make such low-level mistakes
Automated tests will be back in the next version. Sorry for the circumstances. This issue gets the top priority.
Additional fix was added in v0.7.23
Hi,
Following the doc this sample code should work but it yields an empty array. Any clues about what is done wrong?