fuzzy-search icon indicating copy to clipboard operation
fuzzy-search copied to clipboard

Highlight matching characters

Open kacpak opened this issue 4 years ago • 5 comments

I think that it would be great if we could highlight characters that triggered the match

search: somestring result: foosomestringbar foosomethingStringbar

API could be something like this

const searcher = new FuzzySearch(people, ['name.firstName', 'state'], {
  caseSensitive: true,
  highlight: substring => colors.underline.bold(substring)
});

What do you think about such feature? I really miss something like this.

kacpak avatar Mar 05 '20 15:03 kacpak

I am not in favour of this proposal simply because it's not the job of this library to handle results rendering. Instead, it would be great to have more control on the matching algorithm. For instance, wether is should be stricter or not, etc. As it is now, the API does not provide anything in this regard.

ralf57 avatar Mar 09 '20 15:03 ralf57

@ralf57 I think that API strictness should become another issue, since it's not really relevant for highlighting.

I agree that this lib shouldn't handle rendering and this request doesn't change that. It allows for mapping over results with relevant information. Right now, for my use-case, it's incomplete if I cannot get any information on because of what parts of the string, the object was included in the results. That's why I'm suggesting a function that allows for mapping over results and modifying them with relevant data. This function API in description is only proposal to showcase the idea, it could be more generic.

kacpak avatar Mar 09 '20 15:03 kacpak

Something I could do which wouldn't change much in the code I think; would be to return the indexes of the matches somehow. As I already use the indexes to search for matches.

const searcher = new FuzzySearch(people, ['name.firstName', 'state'], {
  caseSensitive: true,
});
const results = searcher.search('something');
const indexes = searcher.indexes();

Something along those lines, probably won't be exactly that. I'll have to figure a nicer way, but that way you can manually map the results.

wouterrutgers avatar Mar 09 '20 19:03 wouterrutgers

Hey, Any news on this one?

SzNagyMisu avatar Nov 19 '21 15:11 SzNagyMisu

Something I could do which wouldn't change much in the code I think; would be to return the indexes of the matches somehow. As I already use the indexes to search for matches.

const searcher = new FuzzySearch(people, ['name.firstName', 'state'], {
  caseSensitive: true,
});
const results = searcher.search('something');
const indexes = searcher.indexes();

Something along those lines, probably won't be exactly that. I'll have to figure a nicer way, but that way you can manually map the results.

Is it underway? would love to have that.

AshwinC8 avatar Aug 08 '24 11:08 AshwinC8