Skip to content

README's "Ranking a Collection" example ranks the prefix match "Storage Provider" last, not first: actual scores are Data Store 19, AppDataStorage 17, Storage Provider 15 #99

Description

@matt-edmondson

What's wrong

The README's only end-to-end example of the library's main use case, Ranking a Collection, prints this for pattern "stor":

// Storage Provider (Score: 15)
// Data Store (Score: 14)
// AppDataStorage (Score: 10)

Running the sample exactly as written against main (ebb0555) gives the opposite order:

Item README Actual
Data Store 14 (2nd) 19 (1st)
AppDataStorage 10 (3rd) 17 (2nd)
Storage Provider 15 (1st) 15 (3rd)

For comparison, "Storage" scores 22 and "Stor" 25.

Why it matters

A user who types stor gets the one candidate that starts with the pattern ranked last, behind a mid-word match. The README promises the opposite. Either the scoring has regressed, or the README advertises a ranking the library doesn't produce. The sample probably went stale when the prefix-penalty refund and cap changed (#82, #94 area), but I didn't bisect it.

The root of the order is that the per-letter unmatched penalty (unmatchedLetterPenalty, Fuzzy.cs:263) has no cap. "Storage Provider" is charged for its 12 trailing letters, and that outweighs its word-start and no-prefix advantage over "Data Store".

ReadmeTests.cs only checks that the API names used in the README exist, not what the samples print, so nothing caught the drift.

Suggested fix / acceptance criteria

  • Decide which ranking is intended:
    • If a word-start prefix match should win, as the README says, reduce, scale or cap the trailing unmatched-letter penalty so that Storage Provider outranks Data Store for stor.
    • Otherwise, update the README's printed scores and order.
  • Add a test that runs the README's ranking sample and asserts its printed order and scores, so the README can't drift again.

Related, but separate scoring issues: #89, #91.

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions