krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
17.76k stars 753 forks source link

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

Open tibineagu opened 4 months ago

tibineagu commented 4 months ago

Is there an existing issue for this?

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.

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!

leeoniya commented 4 months ago

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

tibineagu commented 4 months ago

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

leeoniya commented 4 months ago

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.

github-actions[bot] commented 1 week ago

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