Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weird scoring in some cases #14

Open
max397574 opened this issue Oct 13, 2024 · 2 comments
Open

weird scoring in some cases #14

max397574 opened this issue Oct 13, 2024 · 2 comments

Comments

@max397574
Copy link

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
@swarn
Copy link
Owner

swarn commented Oct 13, 2024

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
Copy link
Owner

swarn commented Oct 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants