krisk / Fuse

Lightweight fuzzy-search, in JavaScript

Home Page:https://fusejs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unclear how to do non-fuzzy search on a per-word basis

tibineagu opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Your question

Hi @krisk - First off, thanks for all the amazing work you've been doing with this library. We've been using it for the better part of a decade now!

We've recently found ourselves in the position of using the searcher with a rather unorthodox set of requirements.

  • the search should only return exact matches
  • the matches should only be at the beginning of a word
  • it doesn't matter where the word appears

Here's an example:

const list = ['Project Management', 'Manager', 'Random word', 'Emanation Interepretation'];
const searchString = 'mana';

// expected results: ['Project Management', 'Manager']

"Emanation ..." should not be included because the pattern is not at the beginning of the word.

While I can make threshold: 0 to disable fuzzy search, and set ignoreLocation: true to search the entire string, I am not sure what i need to do to tell the searcher that i only need matches at the beginning of a word.

Any help would be greatly appreciated!

if your haystack is just an array of strings, you can try uFuzzy with interLft: 2:

https://leeoniya.github.io/uFuzzy/demos/compare.html?libs=uFuzzy&search=mana&interLft=2

@leeoniya thanks for the reply. it's not, it's usually a set of { text, value } objects.

as long as there's 1:1 mapping and you're searching just text you can still do it. uFuzzy will just give you back matched idxs. so use Array.map to build a haystack from your objects that's [text0, text1, text2,...] and then use the matched idxs to pull value out of the original array/objects.

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