For many of my projects, I've relied on String Score to assist with sorting various lists such as names and countries.
Currently, I am tackling a project where I need to match a term within a larger body of text, like an entire paragraph.
Consider the following two strings:
string1 = "I want to eat.";
string2 = "I want to eat. Let's go eat. All this talk about eating is making me hungry. Ready to eat?";
I expect the term eat
to rank string2
higher than string1
. But surprisingly, string1
ends up with a higher score:
string1.score('eat');
> 0.5261904761904762
string2.score('eat');
> 0.4477777777777778
If you have a different perspective on why string1
should receive a higher score, I'm open to hearing your arguments. Otherwise, do you have any suggestions for a more contextually relevant JavaScript matching algorithm?