fzy-lua icon indicating copy to clipboard operation
fzy-lua copied to clipboard

weird scoring in some cases

Open max397574 opened this issue 1 year ago • 2 comments

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

max397574 avatar Oct 13 '24 14:10 max397574

Huh, that's weird. It's consistent with the original implementation:

Screenshot 2024-10-13 at 9 49 12 AM

...which doesn't mean that the behavior is desirable. I'll have to dig in deeper.

swarn avatar Oct 13 '24 14:10 swarn

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.

swarn avatar Oct 23 '24 02:10 swarn