Skip to content

Fix IsAcronymNumber and correctly group digit runs in acronym counting#4509

Open
DavidGBrett wants to merge 3 commits into
devfrom
fix-IsAcronymNumber
Open

Fix IsAcronymNumber and correctly group digit runs in acronym counting#4509
DavidGBrett wants to merge 3 commits into
devfrom
fix-IsAcronymNumber

Conversation

@DavidGBrett

@DavidGBrett DavidGBrett commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #4508

Replaces incorrect comparison of char to the intergers 0 and 9 (instead of the actual ASCII values of those characters) with char.IsAsciiDigit

Used IsAsciiDigit instead of IsDigit as that more closely replicates what originally existed and the other parts of this class don't seem ready to accept non ascii digits

Now the digits are actually being detected, we also need to fix the inconsistency where sometimes a digit run was treated as a single count in tallying but not in scoring - so score could exceed the 100 maximum.
Added a new CountDistinctAcronymGroups method to group digit runs into a single count, while leaving alphabetic acronyms as individual counts.


Summary by cubic

Improves acronym matching with numbers in StringMatcher by using ASCII-only digit checks and grouping consecutive digits as one unit. This fixes scoring inflation and restores correct matches for names like "Visual Studio 2019".

Summary of changes

  • Changed: IsAcronymNumber now uses char.IsAsciiDigit. Acronym scoring uses CountDistinctAcronymGroups so digit runs count once.
  • Added: CountDistinctAcronymGroups helper; unit tests for digit-run acronyms in Flow.Launcher.Test/FuzzyMatcherTest.cs.
  • Removed: Incorrect char >= 0 && <= 9 check; per-digit overcounting in acronym scoring.
  • Memory impact: Minimal. Adds a small, short-lived HashSet during matching.
  • Security risks: None.
  • Unit tests: Added cases for queries like "vs2", "vs19", "vs2019", "v29", and mismatched digit runs.

Release Note
Abbreviation matching now treats number sequences like "2019" as a single part, improving search results and ranking.

Written for commit d7b0757. Summary will update on new commits.

Review in cubic

…scii value comparison

Used IsAsciiDigit instead of IsDigit as that more closely replicates what originally existed and the other parts of this class don't seem ready to accept non ascii digits
@github-actions github-actions Bot added this to the 2.2.0 milestone Jun 4, 2026
@DavidGBrett DavidGBrett marked this pull request as ready for review June 4, 2026 16:33
@DavidGBrett DavidGBrett added the bug Something isn't working label Jun 4, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

StringMatcher groups contiguous ASCII digit runs as single acronym units, counts distinct matched acronym groups for acronym scoring, replaces the manual digit check with char.IsAsciiDigit(...), and adds NUnit tests validating digit-run acronym behavior.

Changes

Acronym grouping & digit detection

Layer / File(s) Summary
Acronym grouping and scoring
Flow.Launcher.Infrastructure/StringMatcher.cs
Adds CountDistinctAcronymGroups, changes acronym score to use matched group count, updates comments clarifying digit-run counting, and replaces manual digit range check with char.IsAsciiDigit(...).
Acronym scoring tests
Flow.Launcher.Test/FuzzyMatcherTest.cs
Adds NUnit [TestCase] entries and documentation to assert digit-run grouping behavior: full-match (100), partial-match (~66), and non-match (0) scenarios.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies both main changes: fixing IsAcronymNumber and correctly grouping digit runs in acronym counting, matching the primary objectives of the PR.
Linked Issues check ✅ Passed The PR successfully addresses issue #4508 by replacing the incorrect char-to-int comparison with char.IsAsciiDigit and implements the new CountDistinctAcronymGroups method to correctly group consecutive digits.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the digit detection bug and improving acronym scoring logic; no extraneous modifications detected.
Description check ✅ Passed The pull request description clearly explains the bug fix (incorrect char-to-integer comparison), the solution (using char.IsAsciiDigit), and why it was needed (digit detection now works properly), with details about the new CountDistinctAcronymGroups method and test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-IsAcronymNumber

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DavidGBrett DavidGBrett marked this pull request as draft June 4, 2026 19:31
@DavidGBrett DavidGBrett changed the title Fix IsAcronymNumber by using char.IsAsciiDigit instead of incorrect ascii value comparison Fix IsAcronymNumber by using char.IsAsciiDigit instead of incorrect ascii value comparison and group digit runs in counting Jun 5, 2026
@DavidGBrett DavidGBrett changed the title Fix IsAcronymNumber by using char.IsAsciiDigit instead of incorrect ascii value comparison and group digit runs in counting Fix IsAcronymNumber and correctly group digit runs in counting Jun 5, 2026
@DavidGBrett DavidGBrett changed the title Fix IsAcronymNumber and correctly group digit runs in counting Fix IsAcronymNumber and correctly group digit runs in acronym counting Jun 5, 2026
@DavidGBrett DavidGBrett marked this pull request as ready for review June 5, 2026 12:35

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
Flow.Launcher.Infrastructure/StringMatcher.cs (2)

278-315: ⚡ Quick win

Ensure consistent spacing and document precondition.

Minor style issues:

  • Line 299: groups+=1;groups += 1; or groups++;
  • Line 302: Missing space after comma in IsAcronymNumber(stringToCompare,matchedIndex)
  • Line 307: stringToCompare.Length-1stringToCompare.Length - 1

Additionally, the algorithm assumes matchedIndices is sorted ascending (currently satisfied because indices are added in loop order at line 142). Document this precondition in the XML comment or add a defensive sort.

✨ Proposed fixes
 /// <summary>
 /// Counts distinct acronym groups from matched character indices in <paramref name="stringToCompare"/>.
+/// Assumes <paramref name="matchedIndices"/> is sorted in ascending order.
 /// Each matched non-digit character index forms its own group.
 /// Contiguous digit characters in the string form a single group regardless of how many indices match within the run.
 ///
 /// Example:
 /// For "Visual Studio 2019", matched indices [0, 14, 17] refer to characters 'V', '2', and '9'.
 /// These produce 2 groups: 'V' and the digit run "2019".
 /// </summary>
 private static int CountDistinctAcronymGroups(List<int> matchedIndices, string stringToCompare)
 {
     int groups = 0;
     var processedIndices = new HashSet<int>();

     foreach (int matchedIndex in matchedIndices)
     {
         // try process index and skip if already processed in a previous group
         if (!processedIndices.Add(matchedIndex))
             continue;

         // since we processed a new index we start a new group
-        groups+=1;
+        groups++;

         // if this isn't a digit then its a single index group so we stop here
-        if (!IsAcronymNumber(stringToCompare,matchedIndex))
+        if (!IsAcronymNumber(stringToCompare, matchedIndex))
             continue;

         // check if this is a digit run and process any indices in that run as they are part of this group
         int digitRunEnd = matchedIndex;
-        while (digitRunEnd < stringToCompare.Length-1 && IsAcronymNumber(stringToCompare, digitRunEnd + 1))
+        while (digitRunEnd < stringToCompare.Length - 1 && IsAcronymNumber(stringToCompare, digitRunEnd + 1))
         {
             digitRunEnd += 1;
             processedIndices.Add(digitRunEnd);
         }
     }

     return groups;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Flow.Launcher.Infrastructure/StringMatcher.cs` around lines 278 - 315, The
CountDistinctAcronymGroups method has minor style issues and an unstated
precondition: fix spacing (use "groups += 1;" or "groups++;", add a space after
the comma in IsAcronymNumber(stringToCompare, matchedIndex), and change
"stringToCompare.Length-1" to "stringToCompare.Length - 1"), and either document
that matchedIndices must be sorted ascending in the XML summary or defensively
sort matchedIndices at the start of CountDistinctAcronymGroups (before using
processedIndices) so the digit-run grouping logic using IsAcronymNumber and
processedIndices behaves deterministically.

275-275: ⚡ Quick win

Remove commented-out code.

Commented-out code is a maintenance burden. Since the fix is verified and tested, the old incorrect implementation should be deleted.

🧹 Proposed cleanup
 private static bool IsAcronymNumber(string stringToCompare, int compareStringIndex)
-    // => stringToCompare[compareStringIndex] >= 0 && stringToCompare[compareStringIndex] <= 9;
     => char.IsAsciiDigit(stringToCompare[compareStringIndex]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Flow.Launcher.Infrastructure/StringMatcher.cs` at line 275, Remove the
leftover commented-out code line "// => stringToCompare[compareStringIndex] >= 0
&& stringToCompare[compareStringIndex] <= 9;" from
Flow.Launcher.Infrastructure.StringMatcher.cs; locate the comment inside the
StringMatcher implementation (the code referencing stringToCompare and
compareStringIndex) and delete that stale comment so only the current, verified
logic remains.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@Flow.Launcher.Infrastructure/StringMatcher.cs`:
- Around line 278-315: The CountDistinctAcronymGroups method has minor style
issues and an unstated precondition: fix spacing (use "groups += 1;" or
"groups++;", add a space after the comma in IsAcronymNumber(stringToCompare,
matchedIndex), and change "stringToCompare.Length-1" to "stringToCompare.Length
- 1"), and either document that matchedIndices must be sorted ascending in the
XML summary or defensively sort matchedIndices at the start of
CountDistinctAcronymGroups (before using processedIndices) so the digit-run
grouping logic using IsAcronymNumber and processedIndices behaves
deterministically.
- Line 275: Remove the leftover commented-out code line "// =>
stringToCompare[compareStringIndex] >= 0 && stringToCompare[compareStringIndex]
<= 9;" from Flow.Launcher.Infrastructure.StringMatcher.cs; locate the comment
inside the StringMatcher implementation (the code referencing stringToCompare
and compareStringIndex) and delete that stale comment so only the current,
verified logic remains.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8e5763c7-36bd-4c53-93e0-119981fd94dc

📥 Commits

Reviewing files that changed from the base of the PR and between 258932a and d524d99.

📒 Files selected for processing (2)
  • Flow.Launcher.Infrastructure/StringMatcher.cs
  • Flow.Launcher.Test/FuzzyMatcherTest.cs

@DavidGBrett DavidGBrett marked this pull request as draft June 5, 2026 12:45
@DavidGBrett DavidGBrett force-pushed the fix-IsAcronymNumber branch from d524d99 to d7b0757 Compare June 5, 2026 12:48
@DavidGBrett DavidGBrett marked this pull request as ready for review June 5, 2026 12:48

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@Jack251970 Jack251970 requested a review from jjw24 June 8, 2026 03:43
@jjw24 jjw24 added the review in progress Indicates that a review is in progress for this PR label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review in progress Indicates that a review is in progress for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: IsAcronymNumber in StringMatcher doesn't correctly identify digits

2 participants