Tyler330
Tyler330

Reputation: 415

Fuse.js: Exact name match

I am trying to implement an exact name match on a database.

Is there a way to get only "Smith", and not "Smithee", "Smithers", "Smithe" etc? Setting the Distance and Threshold to 0 do not do it. I can of course go through the results once they have appeared and take out the unwanted values, but it would be more efficient to do it in one take.

Upvotes: 4

Views: 5091

Answers (1)

krisk
krisk

Reputation: 7117

(Hopefully you're on the latest version of Fuse.js)

If your data looks like something like this:

const list = [{ name: 'Smith' } /*, etc...*/]

You could use extended search:

const fuse = new Fuse(list, {
  keys: ['name'],
  useExtendedSearch: true
})

// Search for items that exactly match "smith"
fuse.search('=smith')

Upvotes: 5

Related Questions