Fuse: Search returns wrong results

Created on 16 Nov 2020  路  7Comments  路  Source: krisk/Fuse

Describe the bug

Search does not return expected results.

Expected Result

Only one object returned

Actual Result

All items returned

Version

^6.4.3"

Is this a regression?

No - Never used before

馃敩Minimal Reproduction

1) npm install --save fuse.js
2) copy and paste code below
3) run

Specs:

macOS: 10.15.7 (19H15)

Additional context

import Fuse from 'fuse.js';

const list = [
{
auditLog: "logs-1/.asjdfnjasbfa.json",
author: 'John Scalzi',
tags: ['fiction']
},
{
auditLog: "logs-2/.ahjdfnjasbfa.json",
author: 'Steve',
tags: ['thriller']
}
]

const options = {
// Search in author and in tags array
keys: ['auditLog']
}

const fuse = new Fuse(list, options)

const result = fuse.search("logs-1")

console.log(result)

notabug

Most helpful comment

This is working as expected. If the search criteria is "logs-1", it will match both "logs-1" and "logs-2". Remember that Fuse is doing an approximate string matching (aka, fuzzy matching), and while "logs-1" is a perfect match, "logs-2" is a very close match nonetheless.

All 7 comments

I'm seeing all items returned:

[
  {
    item: {
      auditLog: 'logs-1/.asjdfnjasbfa.json',
      author: 'John Scalzi',
      tags: [ 'fiction' ]
    },
    refIndex: 0
  },
  {
    item: {
      auditLog: 'logs-2/.ahjdfnjasbfa.json',
      author: 'Steve',
      tags: [ 'thriller' ]
    },
    refIndex: 1
  }
]

Fuse version: 6.4.3

@krisk I would think that only one item would be returned for a match on "logs-1"?

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

bump

This is working as expected. If the search criteria is "logs-1", it will match both "logs-1" and "logs-2". Remember that Fuse is doing an approximate string matching (aka, fuzzy matching), and while "logs-1" is a perfect match, "logs-2" is a very close match nonetheless.

What would be the best way to get fuse to return only an exact match if there is one, likewise only return the partial matches if it can't find an exact?

Anyone find a good config? I want to make something like the fuzzy finder in vscode - if I am looking for a file called log-1 with the query log-1, I do not want log-2 in my search results.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vexa picture vexa  路  4Comments

danitrod picture danitrod  路  4Comments

andy-polhill picture andy-polhill  路  4Comments

cekvenich picture cekvenich  路  4Comments

imanjra picture imanjra  路  3Comments