Files
romm/backend/handler
Sam Dornan 4080cee68e feat(search): Order v2 search results by relevance until a sort is picked (#4995)
* Order v2 search results by relevance until a sort is picked

The Search page fell back to the gallery-wide title sort whenever the URL
named none, so the backend only used search relevance to break ties
between identical titles. Search now sends an empty order_by by default,
letting relevance lead; clicking a column still sorts by it and lands in
the URL as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6

* pr-ready step 2 (code-review): fix relevance-order edge cases

The backend now decides whether relevance leads and returns an empty
char_index when it does, so single-word searches (still name-ordered)
keep the A-Z strip and letter grouping, and multi-word searches get no
letter headers over rows that are not in letter order. A write under a
relevance-ordered search refetches, since the row lacks the filename and
aliases relevance ranks on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6

* pr-ready step 3 (simplify): drop duplicated defaults and test setup

Gallery order clauses check order_by directly again, since the phrases
are already known there; useGalleryOrderUrl takes its default from the
caller only; the default key comes from DEFAULT_ORDER_BY in useRomSync;
and the new tests reuse the existing setup and mount helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6

* Offer Relevance as a sort on Search and read it off the backend

Search's sort menu (grid toolbar and the compact list header) now lists
Relevance, and a third click on a desktop column header returns to it,
so the default order is reachable again after picking a column. The
direction toggle hides under relevance, which has no direction.

useRomSync's refetch now follows the backend's own signal for a
relevance order (an unset sort answered without letter positions)
instead of treating every search as one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6

* Check the Relevance sort entry when it is active

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6

* Show the order the backend applied in Search's sort controls

An unset sort the backend still answered by name (an empty or one-word
search) now reads as Title in the sort controls, with its direction
toggle, rather than as Relevance. The store records whether the last
answer led with relevance and keeps it through refetches, so the controls
don't flicker while a search reloads. Picking Relevance from the toolbar
now also resets the direction, as the list header's third click does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6

* pr-ready simplify: read the applied order from effectiveOrderBy

- The letter strip reads `effectiveOrderBy` instead of re-checking
  `charIndex`, which also stops it vanishing during every refetch of a
  relevance-ordered search.
- `useRomSync` reads `effectiveOrderBy`, so `relevanceLeads` goes.
- `setOrderBy(null)` resets the direction itself, so `clearOrder` and
  the shell's toolbar handler go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6

* Tell the sort controls whether relevance is applied

The controls read a null sort key as "unsorted", but the shell also
passes null for a gallery key no column carries, so
`/search?orderBy=last_played` ticked Relevance and hid the direction
toggle. The toolbar, list header and phone sort menu now take an
explicit `unsorted` flag from the store's `effectiveOrderBy`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015iCApu4gYrGBWDX8JD9JH6

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 15:56:36 -05:00
..