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

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

Open
1 task done
tibineagu opened this issue Feb 5, 2024 · 3 comments
Open
1 task done

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

tibineagu opened this issue Feb 5, 2024 · 3 comments
Labels

Comments

@tibineagu
Copy link

tibineagu commented Feb 5, 2024

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!

@leeoniya
Copy link

leeoniya commented Feb 7, 2024

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
Copy link
Author

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

@leeoniya
Copy link

leeoniya commented Feb 18, 2024

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.

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

2 participants