jeancroy / FuzzySearch

:mag: Fast autocomplete suggestion engine using approximate string matching
MIT License
194 stars 32 forks source link

multiple occurrances of a highlight makes no diff #39

Closed halukkaramete closed 2 years ago

halukkaramete commented 2 years ago

Hi Jean,

Please take a look at the screen shot which demonstrates the issue more visually.

In my demo, I type "Belief", And many Belief entries match but I want one that has the max "Belief" words to match as #1.

For that, I created a "belief" item in which I put 4 "Belief" words back to back. But it is still not #1.

Is there a setting to move that kind of match higher?

Screen Shot 2022-04-01 at 8 34 23 PM
jeancroy commented 2 years ago

You are right, it is by design.

I extract a best match, and this allow other data to exist without affecting the best match. The idea behind this is that very few entry will match the word, and if this is not true, the user type more.

If instead what you want is thematic, the whole entry "feel" like the word, then you want to replace the MAX score function by an AVERAGE scores function. You can have a mix of behavior between max and average by using "average of a power of score" (for example average of squared score) the higher the power the closer it get to max.

I think the change need to be made around here. The tokens are the lowercase words. I don't have much time if any to put on this, but there's enough for you to start playing with it.

I think it's around here. https://github.com/jeancroy/FuzzySearch/blob/36e3ca507d0712af01f07a61f9734bfe22f281b6/src/search.js#L229