Skip to content

Rank real fuzzy matches above near-misses [patch] - #124

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/textfilter-123-rank-matches-first
Sep 28, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/textfilter-123-rank-matches-first

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #123

Problem

TextFilter.Rank worked out isMatch for every item and then ignored it, sorting on score alone. 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. So hell ranked above say hello to everyone for hello, and conf ranked above src/app/settings/config.json for config.

Change

  • Rank<TItem> now sorts on isMatch first and on score second. The Rank(strings, …) overload goes through it.
  • Non-matches are still returned, as before. They just sort below every real match.
  • The <remarks> on Rank<TItem> now say so.

Tests

  • Added RankPutsARealMatchAboveAHigherScoringNearMiss, which covers the four rows from the issue (hello, abc, readme, config).
  • Added RankWithKeySelectorPutsARealMatchAboveAHigherScoringNearMiss, which covers the key-selector overload.
  • With the change to TextFilter.cs reverted, all 5 new cases fail. With it, the full suite passes: 120 of 120 on net10.0.
  • The existing Rank tests pass unchanged, because world is a non-match for helo and 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

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
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit a7ee86b into main Sep 28, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the claude/textfilter-123-rank-matches-first branch September 28, 2026 01:40
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

Successfully merging this pull request may close these issues.

Rank() sorts non-matching items above real matches (e.g. "hell" ranks above "say hello …" for "hello")

2 participants