fzy-lua
fzy-lua copied to clipboard
weird scoring in some cases
I get the following scoring where the first one is unexplainable to me
require"fzy".positions("t",'"test"',false)
-- { 5 }, -0.025
require"fzy".positions("te",'"test"',false)
-- { 2, 3 } 0.98
Huh, that's weird. It's consistent with the original implementation:
...which doesn't mean that the behavior is desirable. I'll have to dig in deeper.
The root cause of this is that fzy adds varying bonuses to letters at the beginning of words. However, the word boundary is not your typical regex \b. It's only that matching characters following the these characters get (varying) bonuses:
/ \ - _ .
So all of "test" is only a single word, and the t has no bonus to match the first t (which is the second character in the "word") versus the last.
I'm pondering making the word boundary a bit more rigorous. Maybe a character following any character in the usual non-word \W character class gets a "start of word" bonus? For example abc would match ant!bat!cat before azzzbzzzczz.
This would certainly be different than the original fzy, and will definitely change observable behavior for many searches. I'm trying to brainstorm and see if any of those changes would be surprising and therefore bad.