Skip to content

fix(ui): rank verbatim search matches above scattered ones - #14

Open
hadoukim wants to merge 1 commit into
Walkercito:mainfrom
hadoukim:fix/search-ranking
Open

hadoukim wants to merge 1 commit into
Walkercito:mainfrom
hadoukim:fix/search-ranking

Conversation

@hadoukim

@hadoukim hadoukim commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Searching for a clip by its exact text could bury it. The fuzzy filter accepts any clip whose text contains the query's characters in order, so a long clip (logs, code, rich text) spells almost any query out of scattered letters — and since results keep the history order, those clips sit above the one that holds the query verbatim.

Seen on a real 70-clip history: 123Soleil matched 9 clips. The only one containing it verbatim came 7th, below six clips of 700–2200 characters — off-screen, with the cursor on an unrelated clip. Typing 123Soleil! found it alone.

Matches are now ranked rather than just accepted:

  • match_quality() (replaces fuzzy_matches()) returns Substring, Subsequence or None, ordered best first.
  • Each ClipCard carries its rank and the list sorts on it before pinned/newest. With no query every card ranks alike, so the history order is unchanged.
  • A new query puts the cursor on its best match, so Enter pastes the top result.

Fuzzy matching is kept: spng still finds screenshot.png.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Docs
  • Build / CI

Checklist

  • The build is clean — warnings are errors (-Werror).
  • ctest --preset debug passes.
  • The sanitizer build passes: cmake --build --preset asan && ctest --preset asan (zero leaks, zero UB).
  • clang-format and clang-tidy are clean.
  • Commits follow Conventional Commits, with no AI/assistant trailers.
  • A change to core/ ships with tests. (No core/ change; FuzzyTest covers the new ranking.)
  • Docs (README / CONTRIBUTING) updated if behavior changed.

Notes for reviewers

  • clang-tidy was run locally with 22.1, since 18.1.8 cannot parse GCC 16's libstdc++ (Fedora 44): no new findings. CI's 18.1.8 has the final word.
  • search-changed now goes through sync_search_from_entry(), so the debounced signal and the pre-paste/arrow flush share one path; its equality check makes a late search-changed a no-op.
  • Clearing the query (Escape, or backspacing to empty) leaves the cursor where it was, as before.

The fuzzy filter accepts any clip that spells the query out of scattered
letters, so long clips match almost anything and, kept in history order,
bury the clip that holds the query verbatim. Rank matches instead: a
contiguous run sorts above a scattered subsequence, and a new query puts
the cursor on its best match so Enter pastes it.
@hadoukim hadoukim mentioned this pull request Nov 13, 2026
8 of 12 tasks
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