-
-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logical $and does not support multiple $or expressions #449
Comments
TITLE == old AND (OR AGE == 62) -- could be understood as TITLE == old
AND (true OR AGE == 62) which would evaluate to true. It looks to me
like a single $or is understood as having an implicit true.
Can you replicate with a $or which two parts, one of which always
evaluates to false?
|
@cshoredaniel I do not think it works as you describe, since if you move the second Also, mine was only a simple example but indeed using more statements in the If you test the code provided on the project live demo page, you will get this behaviour. |
Thank you for the info. That kind of eliminates my hypothesis.
|
Thanks for flagging. Will take a look. |
Ok, there is a bug indeed, but also, your setup is incorrect. You need to enable extended search, and the Thus it should be the following: const options = {
useExtendedSearch: true,
keys: ['title', 'author.firstName', 'author.lastName', 'author.age']
}
const fuse = new Fuse(list, options)
const result = fuse.search({
$and: [
{ title: 'old' },
{
$or: [{ 'author.firstName': 'j' }, { 'author.lastName': 'Sa' }]
},
{
$or: [{ 'author.age': "'62" }]
}
]
}) Regardless, even with the correct setup, the bug still occurs. Just about to publish a fix for this 😄 |
@krisk thanks for looking into this. I am testing your new solution but it does work properly since the score is not calculated (it is |
I tested the build Moreover, when it finds a perfect match the result holds a very high value too (e.g. |
Thanks @belvederef for looking into this!
Could you send me an example list, fuse setup, and search query that demonstrate the issue? Note that the threshold is against the fuzziness score, and not the relevance score (which is used for overall sorting computation, and what is actually exposed).
That evaluates to |
You're right! I overlooked the If you start the project and navigate to Preview of the results
However, if you change the Preview of the results
Apologies if this is not the simplest setup. let me know if you have any questions. |
It seems to be working as expected. The search query is also looking for The reason why it appeared as if it was working in the previous version is because of the original bug. One way you could fine-tune the fuzzy searching is by increasing |
@krisk thanks for looking into this! You are absolutely right, the seemingly messed up results were caused by my attempt at filtering the results. E.g. in my case I want to find matches but only among all the entries that have a property I would see this as a pretty common use case and it ties in with the work described in #411. This could be specified in a new property in fuse.search({
// logical operators for matching
},
{
filters: {
// logical operators for filtering not affecting the score
$and: {
{ type: 'Property$' },
{ $or: [...] },
// etc.
}
}
}) |
Describe the bug
A clear and concise description of what the bug is.In an
$and
logical expression, according to the docs, multiple expressions can be contained and they must all evaluate to true to satisfy the condition. However, if more than one$or
expression is contained in$and
, all apart from the first will be ignored.Version
The Fuse.js version where this bug is happening.6.2.0
Is this a regression?
Don't know
🔬Minimal Reproduction
Data:
Main:
Result:
Additional context
If you move the expression:
before the first
$or
, you'll see it gets correctly picked up and no result is returned.Related to #411.
The text was updated successfully, but these errors were encountered: