Skip to content

Improve fuzzy search scoring: fix IsAcronymNumber bug, take max(acronym, fuzzy), proportional length bonus#6

Draft
Copilot wants to merge 2 commits into
devfrom
copilot/improve-fuzzy-search-algorithm
Draft

Improve fuzzy search scoring: fix IsAcronymNumber bug, take max(acronym, fuzzy), proportional length bonus#6
Copilot wants to merge 2 commits into
devfrom
copilot/improve-fuzzy-search-algorithm

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 10, 2026

The fuzzy score algorithm produced counterintuitive rankings: short queries like "at" ranked "Kate" above "ATLauncher" (consecutive match scored higher than the acronym), and same-prefix strings of different lengths (e.g. "VLC" vs "VLC media player") received undifferentiated scores.

Changes

Bug fix: IsAcronymNumber always returned false

// Before: compares char to int literals 0 and 9 (NUL/HT control chars) — always false for digits
=> stringToCompare[compareStringIndex] >= 0 && stringToCompare[compareStringIndex] <= 9;

// After
=> stringToCompare[compareStringIndex] >= '0' && stringToCompare[compareStringIndex] <= '9';

Take max(acronym_score, fuzzy_score) when both paths complete

Previously, a successful acronym match short-circuited the fuzzy score entirely. For "at" vs "ATLauncher", the acronym score was 66 (2/3 acronyms matched) while the fuzzy consecutive score is 99 — but only the acronym score was returned, losing to "Kate"'s fuzzy score of 90. Now both scores are computed and the higher is returned.

Replace step-function length bonus with a continuous proportional formula

// Before: coarse step function
if (stringToCompare.Length - query.Length < 5)  score += 20;
else if (stringToCompare.Length - query.Length < 10) score += 10;

// After: continuous — rewards queries that cover a larger fraction of the result string
score += (int)((double)query.Length * 20 / stringToCompare.Length);

This creates a proper gradient so "vlc" ranks "VLC" (score 130) above "VLC media player" (113) above "VLC settings shortcut" (112) rather than treating them equally.

Test updates

  • Benchmark scores in WhenGivenQueryString_ThenShouldReturn_TheDesiredScoring updated (all changes ≤ 5 points).
  • Two new ordering tests added: WhenQueryMatchesAtStartVsMiddle_ShouldRankStartHigher and WhenQueryCoversMoreOfString_ShouldScoreHigher.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…roportional length bonus

Co-authored-by: Jack251970 <53996452+Jack251970@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve fuzzy search algorithm using FuzzySharp library Improve fuzzy search scoring: fix IsAcronymNumber bug, take max(acronym, fuzzy), proportional length bonus Mar 10, 2026
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.

2 participants