Book Page: Other Editions Table → Solr
Describe the problem that you'd like solved
Today, the "Other Editions" table is one of the most expensive parts to load of our Book Page, which is one of our more important pages; see: #6195. There are two main reasons for this:
- It requires we fetch lots of records from infogami
- It requires we fetch Bulk Book Availability info for these items
The table has other issues. Most patrons likely only want readable books in the list. But to determine this (without solr) we need to fetch more than we need from infogami. This results in issues like #7233
Proposal & Constraints
This issue proposes we:
- switch the Other Editions table to use Solr Editions instead of infogami
- update the search function so it also uses Solr (solving #7233)
- Get a further win by pairing this issue with #7450 (to remove the Bulk Availability check)
Stakeholders
@cdrini @mekarpeles @jimchamp
Switching the editions page to solr may not be trivial.
Proposed path forward: /search/editions UI + API
After discussion (cc @cdrini), we'd like to propose a concrete implementation path for this issue. Rather than rewiring the existing editions table in place as a first step, we think the best approach is:
Build a new /search/editions page and /search/editions.json API endpoint powered by Solr, closely mirroring our existing search UI.
Why this approach?
Creating /search/editions.json is effectively a prerequisite for replacing the editions table anyway — we need a clean API layer over Solr edition results before we can swap out the infogami-backed table. Building it as a standalone search page first gives us:
- A working API that the editions table can later be rewired to consume
- A place to prototype edition management features (merge, delete) that we've been wanting
- An incremental, non-destructive path — we build alongside the existing table rather than modifying it, reducing risk
- A community-friendly work breakdown — the API and UI are cleanly separable across contributors
This directly addresses the core problems in this issue:
- Expensive infogami fetches → Solr replaces infogami as the data source
- Bulk Availability overhead → pairs with #7450 (Book Availability in Solr) to eliminate this entirely
- The 1000-edition cap (#7233) → Solr handles pagination natively, so "View all editions" works properly
Scope
Phase 1: API — /search/editions.json (FastAPI)
- New FastAPI endpoint at
/search/editions.json - Queries Solr's edition index with standard search parameters (q, sort, page, limit, facets, etc.)
- Returns edition results in a JSON format consistent with our existing
/search.jsonpatterns - This is the easier lift and a good candidate for community and/or AI-assisted contribution
Phase 2: UI — /search/editions (web.py) using plugins/worksearch
- New web.py route at
/search/editions - UI closely mirrors the existing
/searchinterface (search bar, faceted sidebar, paginated results) - Results display edition-specific metadata (publisher, publish date, ISBN, format, availability, etc.)
- More complex — requires careful design work to match existing search UX patterns
Phase 3: Rewire the editions table
- Once
/search/editions.jsonis stable and proven, swap the "Other Editions" table on the Book Page to consume it instead of fetching from infogami - This is the payoff that solves the original performance problem in #6195
- Will need to similarly support selection of editions (for future merge capability to merge editions #2114
Future: Edition management
- The
/search/editionspage becomes a natural surface for prototyping bulk edition operations (merge, delete)
@mekarpeles,I would love to work on the phase 1 FastAPI endpoint for /search/editions.json following the existing /search.json patterns. Is this open for community contributors?
Thank you @bhardwajparth51 , this is already being tackled in PR #12663
Hi, I would love to work on this issue! Will submit my approach soon.
Hi @RsbhThakur, thank you. This is a big task.
There's a handful of existing work that may be really helpful. For instance:
- #12663
In this PR, we create a new search endpoint for editions (and a UI for testing it). The /search/editions.json could be very useful as a backend to power the editions table.
By default the editions table should likely only show books that are e.g. ebook_access:[borrowable TO *] (i.e. one page of results from some useful query)
Thanks @mekarpeles! Excited to take this on.
Now that Phase 1 (GET /search/editions.json in FastAPI) and Phase 2 (GET /search/editions UI) have been established in #12663, I'm proposing the following concrete implementation plan for Phase 3: rewiring the Book Page "Other Editions" table to consume Solr.
Key Goals & Proposed Approach
1. Replace Infogami DB Fetches with Solr Edition Queries
- Currently,
get_sorted_editions()inmodels.pyfetches raw Infogami edition objects viaweb.ctx.site.get_many(...). For works with hundreds or thousands of editions, this causes significant initial page load latency and heavy DB overhead. - Fix: Update the edition table provider (
editions_datatable.html/editions.html/ helper) to query Solr edition documents (type:editionscoped bywork_key) via the Solr edition service //search/editions.jsonpattern introduced in #12663.
2. Native Solr Pagination & Fixing the 1000-Edition Cap (#7233)
- Solr handles pagination natively via
startandlimit. Rewiring the table to Solr's pagination will eliminate the 1000-edition truncation cap (#7233), allowing users to seamlessly paginate through all editions of works with large publication histories (e.g. classic literature).
3. Unblocking Work-Wide Availability & Language Boosting (#13179 / PR #13289)
- In #13179 (PR #13289), we updated
get_best_editionto boost edition selection by user language match and ebook availability tier. However, because candidate editions were previously sampled/capped via Infogami DB queries, borrowable or same-language editions outside the initial candidate sample could be missed. - Fix: Moving edition queries to Solr allows us to pass
ebook_accessandlanguageboosting directly as query parameters upfront into the Solr request. Solr evaluates the entire edition pool for a work instantly without candidate sampling limitations.
4. (Optional / Needs feedback)
- Interactive Table Sorting: Add simple controls above the editions datatable:
- Sort Dropdown: Sort editions by Publication Date (Newest/Oldest), Popularity, or Relevance.
- Async Datatable Pagination: Update table pagination to fetch subsequent pages (
page 2,page 3) asynchronously viafetch('/search/editions.json?work_key=...&page=2')for instant navigation without full page reloads. - Foundation for Edition Management Actions: Lay the initial UI structure (e.g., edition selection checkboxes) to prepare the datatable for future bulk librarian workflows like Edition Merge (#2114), edition deletion, or adding editions to personal lists.
Implementation Steps
- Backend Integration: Add a Solr-backed edition fetcher helper for works that converts Solr edition docs into the template-compatible payload needed by
editions_datatable.html. - Template Rewiring: Replace direct
get_sorted_editions()calls ineditions_datatable.html/editions.htmlwith the Solr-backed edition provider. - Query-Time Boosting: Connect user language (
web.ctx.lang) andebook_accessboosting into the Solr edition query. - Testing: Add tests in
test_search.pyand work page tests ensuring fast pagination, correct field rendering, and graceful fallback if Solr data is partial.
Looking forward to maintainers' thoughts on this approach! If this looks good, I'll dive in and open the draft PR.
Also, I did some deep dive and cross referencing realted open issues
This approach on #7451 paired up with the my approach in #13179 will address and solve 4 interconnected open issues:
Issues that Will be closed
-
#7233 — View all editions maxes out at 1000
- Reason: Solr handles pagination natively via
startandlimit. Moving away from Infogami DB queries removes the artificial 1,000-record cap, allowing readers to view and paginate through all 3,500+ editions of classic works.
- Reason: Solr handles pagination natively via
-
#7452 — Books Page: Get Best Edition → Solr
- Reason: Currently sitting in
State: Blockedwaiting for #7451. Shifting edition selection and fetching on work pages from Infogami DB to Solr in this issue along with update ofget_best_editionin #13179 satisfies #7452's exact requirements.
- Reason: Currently sitting in
-
#13179 — Smart "Available Alternate Edition" Fallback on Work Pages
- Reason: The language match and ebook availability boosting algorithm implemented in PR #13289 was previously limited by candidate sampling (top 10 DB records). Solr allows this boosting logic to evaluate the entire edition index upfront.
-
#10925 — Editions table filter does not work when ISBN 10 and ISBN 13 aren't equivalent
- Reason: Replaces legacy client-side jQuery DataTables DOM text matching (which broke when hidden ISBN 10/13 representations differed) with structured Solr index queries over both
isbn_10andisbn_13fields.
- Reason: Replaces legacy client-side jQuery DataTables DOM text matching (which broke when hidden ISBN 10/13 representations differed) with structured Solr index queries over both
This makes #7451 a multi-issue win! Let me know if you have any suggestions or feedback before i start working along this appraoch.
Hi, thank you for doing this research. I agree that all of the issues you referenced are interrelated! For this specific issue, rather than to attempt a solution that satisfies all four directions, I'd strongly encourage you to prototype a version of the editions table in isolation that is powered by solr. Sometimes developing the simplest integration path in isolation is the fastest way to understand how difficult the problem is and the real world characteristics of the solution.
I think the majority of the value of this feature will be both in the performance improvements, if any, and also the user experience improvements of the new table and its search capabilities.
We want to make sure that we build something that is actually usable and useful to the community and if we can develop a prototype of the table wired up to solar and let the community try it out on our testing server, this would be a great first milestone.
As Per the discussion with @mekarpeles, This issue will be done in the following milestones:
- Milestone 1: Minimal, isolated prototype view at
/works/OL...W/solr_editions. It uses field-restricted Solr queries (rows=20,facet=False) and UI similar toeditions_datatable.html, along with timing benchmark logs so we can measure raw Solr query latency on staging with zero risk to live book pages. - Milestone 2: Interactive client-side JS, text searchbox, availability filters, and sort dropdowns.
- Milestone 3: Live book page editions table rewire (
editions_datatable.html) + 5-minute Memcached layer to protect Solr under production traffic. - Milestone 4: Query-time boosting for language & availability (
language:<user_lang>^40,ebook_access:borrowable^8) to handle best-edition selection and handle related issues.
Also I would like to note that Draft PR #13384, has already been done targetting milestone 1, and needs feedback and suggestions from Mek, or other maintainers to continue the work on this and the related issues.
Now that #13863 has been merged, I will be proceeding to further milestones of this issue.
Here is how the follow-up work maps across the remaining milestones:
- Milestone 2 (Next Step - Book Page Rewire):
- Swap out Infogami DB edition fetching (
web.ctx.site.get_many) inget_sorted_editions()andeditions_datatable.htmlwith this Solr service. - Add a 5-minute JSON Memcached layer (
cache.memcache_memoize) for default work page views to ensure zero Solr overhead in production. - Closes #7451 and #7233.
- Swap out Infogami DB edition fetching (
- Milestone 3 (Query-Time Boosting for Best Edition Selection):
- Connect language and availability boosting directly into Solr query parameters (
language:<user_lang>^40,ebook_access:borrowable^8). - Closes #7452 and #13179.
- Connect language and availability boosting directly into Solr query parameters (
- Milestone 4 (Interactive Client Filtering, Sorting, & Solr 10 Syntax):
- Add interactive searchbox (
q), format/ebook availability dropdowns, and Solr 10 sort syntax. - Wire progressive AJAX updates via the FastAPI
/search/editions.jsonendpoint. - Lay the foundation for Edition Merge (#2114) librarian checkboxes and close #10925.
- Add interactive searchbox (