openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Fix: Show covers in search results using edition fallback (Fixes #11563)

Open FizaSiddique123 opened this issue 3 weeks ago • 1 comments

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:

  1. Try get_cover_url(selected_ed)
  2. If missing, try:
    • cover_i
    • cover_edition_key
    • first edition_key
  3. 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:

  1. Go to
    /search?q=Goa+Stott&mode=everything&sort=old&first_publish_year=2011

  2. Before this PR:
    The result “Goa / Stott” displays no cover in search results.

  3. After this PR:
    The cover image appears correctly by using edition fallbacks.

Stakeholders

@internetarchive/openlibrary-developers

FizaSiddique123 avatar Dec 08 '25 06:12 FizaSiddique123

Hi! This PR is ready for review.
Please let me know if any changes are needed. Thank you!

FizaSiddique123 avatar Dec 08 '25 06:12 FizaSiddique123