Skip to content
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

How can an object get a score without any matches? #442

Closed
washtenawIdtreble opened this issue Jun 14, 2020 · 4 comments
Closed

How can an object get a score without any matches? #442

washtenawIdtreble opened this issue Jun 14, 2020 · 4 comments
Assignees
Labels
Milestone

Comments

@washtenawIdtreble
Copy link

washtenawIdtreble commented Jun 14, 2020

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

@marcus-at-localhost
Copy link

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

@washtenawIdtreble
Copy link
Author

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

Very helpful, thanks for finding that!

@krisk
Copy link
Owner

krisk commented Jun 16, 2020

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.

@krisk krisk added this to the v6.2.x milestone Jun 16, 2020
@krisk krisk self-assigned this Jun 16, 2020
krisk added a commit that referenced this issue Jun 17, 2020
@krisk
Copy link
Owner

krisk commented Jun 17, 2020

Now in latest fuse.js@6.2.0

@krisk krisk closed this as completed Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants