krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
17.89k stars 759 forks source link

Inconsistent results when using object queries #516

Closed spike-rabbit closed 3 years ago

spike-rabbit commented 3 years ago

Describe the bug

When using object queries, the order of keys seems to matter. I guess this is not intended.

Version

6.4.3

Is this a regression?

I don't know. Previously I was not using the object search

🔬Minimal Reproduction

just run this script https://gist.github.com/spike-rabbit/389e2b2cfdea1d706dac38a899748de1

Additional context

As mentioned in the gist, lowering the threshold seems to bypass the problem.

krisk commented 3 years ago

This is by design:

The $or operator uses short-circuit evaluation (i.e, if the first expression evaluates to true, Fuse.js will not evaluate the remaining expressions).

For example, in your second query, the first OR condition is { "name": "IN_PROGRESS"}, which is still finding a match for the first item in the list:

{
    "id": 132,
    "name": "serious request",
    "status": "IN_PROGRESS",
    "client": {
      "name": "serious-client", // <-- still finding a match for this
    }
  }

Since the match's score is good enough for it to be included, all subsequent conditions in the $or query are skipped.

If you want more restrictive searching, you could decrease the threshold and change minMatchCharLength 😄

krisk commented 3 years ago

I guess there's a question there on whether it should continue with all subsequent conditions and pick the one with the best score, as opposed to short-circuiting.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

matthewjumpsoffbuildings commented 3 years ago

@krisk

I guess there's a question there on whether it should continue with all subsequent conditions and pick the one with the best score, as opposed to short-circuiting.

Surely this should be an option? The short circuit behaviour is not always desirable, and allowing all conditions to evaluate and give a proper score would help make the sorted results significantly more relevant.