Fuse: How can an object get a score without any matches?

Created on 14 Jun 2020  路  4Comments  路  Source: krisk/Fuse

Describe the bug

Fuse is returning search results that have scores but have no matches.

I'm using Fuse to search objects that look like this:

export class Business {
    public name: string,
    public number: string,
    public street: string,
    public city: string,
    public state: string,
    public zipCode: string,
    public website: string,
    public phone: string,
    public description: string,
    public logoImgSrc: string,
    public distance: number,
    public categories: Array<string>,
    public discount: string,
    public spanishDescription: string,
    public spanishDiscount: string
  }

My fuse options look like this:

includeScore: true,
includeMatches: true,
keys: [
    "name"
    "street"
    "city"
    "zipCode"
    "description"
    "categories"
    "discount"
    "spanishDescription"
    "spanishDiscount"
],
minMatchCharLength: Math.ceil(searchTerm.length / 2),
threshold: 0.5,
distance: 10000000,

I'm using a very high distance because I essentially want to ignore it. Some of the fields I'm searching are hundreds of characters long, and I don't care whether a match is found at the beginning or the end. I discovered that using a huge distance limits its impact on the score.

Note that I'm using half the search term length (rounded up) for the minimum match character length. I'm planning to experiment with changing that. I want users to be able to make typos where there are too many letters, so I didn't want to say that the minimum match character length was exactly the search term length. Maybe this is misguided.

When I run a search for the word "old" on an array of 38 of these businesses, the results include all 38 businesses.

  • The scores with matches range from 0.0008140476608581672 for a business called "Old Standard Bank" to 0.39039305209113007 for a business where the match is "lo" at character index 59 in the description field.
  • 8 of the businesses come back in the search results with no matches, and they all have a score of 0.4598587108156556.

Furthermore, if I adjust the minimum match character length from 2 to 3 for this search term:

  • I still get 38 search results.
  • 15 of the results have no matches.
  • 5 of the results with no matches have higher scores than at least one other result that _does_ have a match.
  • No-match scores range from 0.08129004777396812 to 0.4598587108156556.
  • Highest-ranked business with no matches is 19th out of 38.

How is it possible to get search results that have no matches? Am I using Fuse wrong in some way?

Version

5.2.3

Is this a regression?

I don't know

bug

Most helpful comment

Now in latest [email protected]

All 4 comments

Searching for "remy" in the demo returns unrelated records as well. https://fusejs.io/demo.html

Searching for "remy" in the demo returns unrelated records as well. https://fusejs.io/demo.html

Very helpful, thanks for finding that!

Yes, this is a bug, thanks for filing this. minMatchCharLength is ignored when determining which records to exclude. I'll address it for the next release.

Now in latest [email protected]

Was this page helpful?
0 / 5 - 0 ratings