Rank real fuzzy matches above near-misses [patch] - #124
Merged
Merged
Conversation
Rank computed isMatch for every item but sorted on score alone. A short near-miss such as "hell" avoids the skip and gap penalties a real match inside a longer string pays, so it outscored "say hello to everyone" for "hello". Sort on isMatch first, then score. Non-matches are still kept. Fixes #123 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M9aefrfAYJpanQVrUuFpJh
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #123
Problem
TextFilter.Rankworked outisMatchfor every item and then ignored it, sorting onscorealone. When the pattern isn't fully present, FuzzySearch's score only reflects how far the partial match got. A short near-miss avoids the penalties for skipped and extra characters that a real match inside a longer string pays. Sohellranked abovesay hello to everyoneforhello, andconfranked abovesrc/app/settings/config.jsonforconfig.Change
Rank<TItem>now sorts onisMatchfirst and onscoresecond. TheRank(strings, …)overload goes through it.<remarks>onRank<TItem>now say so.Tests
RankPutsARealMatchAboveAHigherScoringNearMiss, which covers the four rows from the issue (hello,abc,readme,config).RankWithKeySelectorPutsARealMatchAboveAHigherScoringNearMiss, which covers the key-selector overload.TextFilter.csreverted, all 5 new cases fail. With it, the full suite passes: 120 of 120 on net10.0.Ranktests pass unchanged, becauseworldis a non-match forheloand already sorted last.This touches a different method from the open PRs #119 and #121, so it merges independently of them.
🤖 Generated with Claude Code
https://claude.ai/code/session_01M9aefrfAYJpanQVrUuFpJh
Generated by Claude Code