Fix: Show covers in search results using edition fallback (Fixes #11563)
What issue does this PR close?
Closes #11563
What does this PR achieve?
This PR fixes an issue where some search results failed to display a cover image even though the corresponding work/edition page showed one.
The previous logic only attempted get_cover_url(selected_ed).
However, many Solr search documents do not include cover_i, and therefore
get_cover_url returned None, resulting in missing covers.
This PR adds proper fallback logic so search results can display covers whenever a book has any valid cover available.
Technical
Updated SearchResultsWork.html to include fallback cover logic:
- Try
get_cover_url(selected_ed) - If missing, try:
cover_icover_edition_key- first
edition_key
- If all fail, use default placeholder icon
This mirrors other areas of OpenLibrary where fallback logic is used, ensuring that search results behave consistently.
Testing
To reproduce:
-
Go to
/search?q=Goa+Stott&mode=everything&sort=old&first_publish_year=2011 -
Before this PR:
The result “Goa / Stott” displays no cover in search results. -
After this PR:
The cover image appears correctly by using edition fallbacks.
Stakeholders
@internetarchive/openlibrary-developers
Hi! This PR is ready for review.
Please let me know if any changes are needed. Thank you!