Skip to content

An early partial match locks in the alignment: Score("src/parser/test_parse","parse") = 4 but Score("src/lexer/test_parse","parse") = 25 #112

Open

Description

@matt-edmondson

What's wrong

CalculateScoreCore (FuzzySearch/Fuzzy.cs, around L198–290) walks the subject left to right and takes the first occurrence of each pattern letter. A letter's position is final as soon as the next pattern letter matches (around L213–221: advanced → score += bestLetterScore; bestLetterIdx = null). The only later correction is rematch, which can move the most recent best letter but cannot undo letters already committed.

So when the first two or more pattern letters appear early in the subject, the matcher commits to that fragment. It then charges every character between the fragment and the real match as an unmatched letter: −1 each, with no cap. It also loses the separator, camelCase and adjacency bonuses the real match would have earned. A subject that contains the whole pattern as a word therefore scores far below an otherwise identical subject without the early fragment.

Repro

Compiled from main at 77fe8c4 on net10.0. "optimal" is a brute-force best alignment scored with the library's own scoring rules:

pattern subject Score optimal
parse src/parser/test_parse 4 25
parse src/lexer/test_parse 25 25
push Git: Pull, then Push 9 20
push Git: Fetch, then Push 20 20
ab axb ab 6 11
ab xxx ab 11 11

Trace for axb ab:

  1. a@0 is the best letter and earns the start bonus: +10.
  2. b@2 matches the next pattern letter, which commits a@0.
  3. The real word ab@4–5 can only rematch b, which gets no adjacency bonus because a@4 was never matched.
  4. Total: 10 − 1 − 1 − 1 − 1 + 0 = 6.

Why it matters

Ranking inverts in the cases fuzzy finders exist for: file pickers and command palettes. Searching parse ranks src/lexer/test_parse far above src/parser/test_parse, which contains the word twice. Searching push ranks "Fetch, then Push" above "Pull, then Push", because Pu of Pull was taken first. Any path whose directory names share a prefix with the file being searched for is pushed down the list.

This is not a duplicate of the existing scoring issues:

Suggested fix / acceptance criteria

Activity

  1. added
    bug
    on Oct 6, 2026
  2. matt-edmondson commented on Oct 6, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions