feat(search): group results by main book with variants and related material #11

Merged
chris-paganon merged 10 commits from feat/cleaner-search-results into master 2026-11-14 20:20:04 +00:00

Cleaner search results

Search and series pages now group each fetched page so that main books come first. Known variants collapse under their main result, and collections, box sets, study guides and adaptations move to a "Related material" section that is collapsed by default. Grouping runs on the client from data already in the response and the reader's library, so it adds no Open Library request.

Changes

  • shared/utils/result-grouping.ts: groupBookResults(books, { links, collectionHints, rejectedPairs, canonicalWork, ungrouped }) returns main groups, related groups and per-main related counts.
  • BookGroupedResults and BookResultGroupInfo components:
    • a "N variants" toggle on main cards, and a "Variant of X. " line on variant cards with Show separately;
    • a related-material section, and a "N in related material" link on main cards;
    • a switch to turn grouping off (shows the raw page in catalogue order) and a page note.
    • Same-page links to a collapsed result expand its group first.
  • BookLibraryGrid: an extra slot, itemClass, and resultBooks, so relationship pickers and same-page links cover the whole page when it is split into two grids.
  • useBookRelationships().rejectedPairs(): pairs rejected in responses or locally since the responses were fetched.
  • Search results include editionCount (edition_count added to the existing search field list; it is accepted in save payloads but not stored).
  • Classification fixes found while investigating:
    • "House Harkonnen (Dune: House Trilogy, Book 2)" is no longer a collection: trilogy followed by "Book N" is a volume annotation.
    • "Nacidos de la Bruma / Mistborn" and "Mistborn. Historia Secreta / Mistborn" are read as translations of the book named after the slash, not as "A / B" bind-ups. This applies only when that book shares an author, has another known language, and the left side names no other book by that author.
  • Series pages reuse the grouping. Author pages keep their existing series, collection and contribution grouping unchanged.
  • README "Grouped results" section and a status note in docs/current-project.md.

Grouping rules (for each result, first match wins)

  1. Works the reader mapped as the same book (PR #8). Confirmed.
  2. Recorded relationships: part_of makes a variant; contains, adaptation_of and study_guide_for make related material.
  3. Suggested relationships (PR #9), then collection hints. A hinted collection whose suggestion the reader rejected stays in the main list.
  4. Title heuristics, always labeled as such:
    • "Translated title / Original title";
    • special editions (leather, anniversary, deluxe, collector's…);
    • same full title and a shared author, or no author.
  5. Anything else stays in the main list, in catalogue order.

Groups are placed at the position of their earliest member. The main result of a group is the mapped or parent book when known. Otherwise it is chosen in this order: has authors, has no part label, most ratings, most editions, earliest in catalogue order. Every grouped card says why it was grouped and whether that was recorded or a heuristic. Confirm, Not related, Same book as… and the Related menu work on every card and regroup immediately.

Pagination

  • Navigation stays by raw catalogue page (20 works).
  • The heading keeps Open Library's numFound.
  • A note says what the page became, e.g. "Showing 8 main results grouped from 20 catalogue records on this page, with 7 variants collapsed and 5 in related material… each page is grouped on its own".
  • No prefetching and no larger page size. Grouping already works for the investigated queries, and a bigger page would slow every search.
  • Requests per search are unchanged: one. The new field changes cache keys once.

Verification

  • pnpm lint-full passes.
  • curl against the dev server (API and SSR HTML), test account:
    • Words of Radiance: 20 records become 8 main results. Words of Radiance has 7 variants (5 parts, 2 author-less duplicates). 5 box sets are in related material.
    • House in the Cerulean Sea: 5 records become 1 main result plus 4 related (2 collections, a workbook and a study guide).
    • Mistborn: 12 main results. The two Spanish "… / Mistborn" editions are translation variants. 6 in related material (trilogies, samplers, Wax and Wayne / quartet box sets, a study guide).
    • Dune: 19 main results; only "The Great Dune Trilogy" is related material. House Harkonnen stays a main result.
    • Ursula Le Guin: plain query; nothing to group, so the page renders 20 cards with no note or switch, as before.
    • Reader-mapped pair: mapping "Way of Kings Part One" onto the saved "The Way of Kings" shows it as "1 same book" under The Way of Kings, taking precedence over the part suggestion. Undoing the mapping shows "1 part" again.
  • Per the changed process for this feature, there was no browser testing and no demo recording.

Known limits

  • Grouping covers only the current page.
  • Classification quality depends on PR #9's suggestions; unclassified summaries such as "Station Eleven: … Summary and Analysis" stay in the main list.
  • Ungrouping a single result lasts for the session only. "Not related" and the relationship menu record a lasting correction for everyone on the instance; "Same book as…" records one for the reader only.
## Cleaner search results Search and series pages now group each fetched page so that main books come first. Known variants collapse under their main result, and collections, box sets, study guides and adaptations move to a "Related material" section that is collapsed by default. Grouping runs on the client from data already in the response and the reader's library, so it adds **no Open Library request**. ### Changes - `shared/utils/result-grouping.ts`: `groupBookResults(books, { links, collectionHints, rejectedPairs, canonicalWork, ungrouped })` returns main groups, related groups and per-main related counts. - `BookGroupedResults` and `BookResultGroupInfo` components: - a "N variants" toggle on main cards, and a "Variant of X. <reason>" line on variant cards with **Show separately**; - a related-material section, and a "N in related material" link on main cards; - a switch to turn grouping off (shows the raw page in catalogue order) and a page note. - Same-page links to a collapsed result expand its group first. - `BookLibraryGrid`: an `extra` slot, `itemClass`, and `resultBooks`, so relationship pickers and same-page links cover the whole page when it is split into two grids. - `useBookRelationships().rejectedPairs()`: pairs rejected in responses or locally since the responses were fetched. - Search results include `editionCount` (`edition_count` added to the existing search field list; it is accepted in save payloads but not stored). - Classification fixes found while investigating: - "House Harkonnen (Dune: House Trilogy, Book 2)" is no longer a collection: trilogy followed by "Book N" is a volume annotation. - "Nacidos de la Bruma / Mistborn" and "Mistborn. Historia Secreta / Mistborn" are read as translations of the book named after the slash, not as "A / B" bind-ups. This applies only when that book shares an author, has another known language, and the left side names no other book by that author. - Series pages reuse the grouping. Author pages keep their existing series, collection and contribution grouping unchanged. - README "Grouped results" section and a status note in `docs/current-project.md`. ### Grouping rules (for each result, first match wins) 1. Works the reader mapped as the same book (PR #8). Confirmed. 2. Recorded relationships: `part_of` makes a variant; `contains`, `adaptation_of` and `study_guide_for` make related material. 3. Suggested relationships (PR #9), then collection hints. A hinted collection whose suggestion the reader rejected stays in the main list. 4. Title heuristics, always labeled as such: - "Translated title / Original title"; - special editions (leather, anniversary, deluxe, collector's…); - same full title and a shared author, or no author. 5. Anything else stays in the main list, in catalogue order. Groups are placed at the position of their earliest member. The main result of a group is the mapped or parent book when known. Otherwise it is chosen in this order: has authors, has no part label, most ratings, most editions, earliest in catalogue order. Every grouped card says why it was grouped and whether that was recorded or a heuristic. Confirm, Not related, Same book as… and the Related menu work on every card and regroup immediately. ### Pagination - Navigation stays by raw catalogue page (20 works). - The heading keeps Open Library's `numFound`. - A note says what the page became, e.g. "Showing 8 main results grouped from 20 catalogue records on this page, with 7 variants collapsed and 5 in related material… each page is grouped on its own". - No prefetching and no larger page size. Grouping already works for the investigated queries, and a bigger page would slow every search. - Requests per search are unchanged: one. The new field changes cache keys once. ### Verification - `pnpm lint-full` passes. - curl against the dev server (API and SSR HTML), test account: - **Words of Radiance**: 20 records become 8 main results. Words of Radiance has 7 variants (5 parts, 2 author-less duplicates). 5 box sets are in related material. - **House in the Cerulean Sea**: 5 records become 1 main result plus 4 related (2 collections, a workbook and a study guide). - **Mistborn**: 12 main results. The two Spanish "… / Mistborn" editions are translation variants. 6 in related material (trilogies, samplers, Wax and Wayne / quartet box sets, a study guide). - **Dune**: 19 main results; only "The Great Dune Trilogy" is related material. House Harkonnen stays a main result. - **Ursula Le Guin**: plain query; nothing to group, so the page renders 20 cards with no note or switch, as before. - **Reader-mapped pair**: mapping "Way of Kings Part One" onto the saved "The Way of Kings" shows it as "1 same book" under The Way of Kings, taking precedence over the part suggestion. Undoing the mapping shows "1 part" again. - Per the changed process for this feature, there was no browser testing and no demo recording. ### Known limits - Grouping covers only the current page. - Classification quality depends on PR #9's suggestions; unclassified summaries such as "Station Eleven: … Summary and Analysis" stay in the main list. - Ungrouping a single result lasts for the session only. "Not related" and the relationship menu record a lasting correction for everyone on the instance; "Same book as…" records one for the reader only.
chris-paganon deleted branch feat/cleaner-search-results 2026-11-14 20:20:04 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
chris-paganon/chrisp-books!11
No description provided.