Repository: internetarchive/openlibrary

Issue:
Covers not appearing in search when they should
### Evidence / Screenshot (if possible)
![image](https://user-images.githubusercontent.com/6251786/138917632-5ae38204-fc77-496d-bf98-7a8d9a62871b.png)

### Relevant url?
https://openlibrary.org/search?q=openstax+microbiology&mode=everything

### Steps to Reproduce
1. Go to https://openlibrary.org/search?q=openstax+microbiology&mode=everything

<!-- What actually happened after these steps? What did you expect to happen? -->
* Actual: Cover should be there
* Expected: Cover is not there

### Details

- **Logged in (Y/N)?** Y
- **Browser type/version?** FF93
- **Operating system?** Win10
- **Environment (prod/dev/local)?** prod
<!-- If not sure, put prod -->

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

### Related files
Likely caused by #5271 .

### Stakeholders
<!-- @ tag stakeholders of this bug -->



Discussion:

Resolving patch:
diff --git a/openlibrary/book_providers.py b/openlibrary/book_providers.py
--- a/openlibrary/book_providers.py
+++ b/openlibrary/book_providers.py
@@ -53,41 +53,6 @@ def render_download_options(self, edition: Edition, extra_args: List = None):
             *(extra_args or [])
         )
 
-    def get_cover_url(self, ed_or_solr: Union[Edition, dict]) -> Optional[str]:
-        """
-        Get the cover url most appropriate for this copy when made available by this
-        provider
-        """
-        size = 'M'
-
-        # Editions
-        if isinstance(ed_or_solr, Edition):
-            return ed_or_solr.get_cover().url(size)
-
-        # Solr document augmented with availability
-        availability = ed_or_solr.get('availability', {})
-
-        if availability.get('openlibrary_edition'):
-            olid = availability.get('openlibrary_edition')
-            return f"{get_coverstore_public_url()}/b/olid/{olid}-{size}.jpg"
-        if availability.get('identifier'):
-            ocaid = ed_or_solr['availability']['identifier']
-            return f"//archive.org/services/img/{ocaid}"
-
-        # Plain solr - we don't know which edition is which here, so this is most
-        # preferable
-        if ed_or_solr.get('cover_i'):
-            cover_i = ed_or_solr["cover_i"]
-            return f'{get_coverstore_public_url()}/b/id/{cover_i}-{size}.jpg'
-        if ed_or_solr.get('cover_edition_key'):
-            olid = ed_or_solr['cover_edition_key']
-            return f"{get_coverstore_public_url()}/b/olid/{olid}-{size}.jpg"
-        if ed_or_solr.get('ocaid'):
-            return f"//archive.org/services/img/{ed_or_solr.get('ocaid')}"
-
-        # No luck
-        return None
-
     def is_own_ocaid(self, ocaid: str) -> bool:
         """Whether the ocaid is an archive of content from this provider"""
         return False
@@ -172,6 +137,41 @@ def is_own_ocaid(self, ocaid: str) -> bool:
 ]
 
 
+def get_cover_url(ed_or_solr: Union[Edition, dict]) -> Optional[str]:
+    """
+    Get the cover url most appropriate for this edition or solr work search result
+    """
+    size = 'M'
+
+    # Editions
+    if isinstance(ed_or_solr, Edition):
+        return ed_or_solr.get_cover().url(size)
+
+    # Solr document augmented with availability
+    availability = ed_or_solr.get('availability', {})
+
+    if availability.get('openlibrary_edition'):
+        olid = availability.get('openlibrary_edition')
+        return f"{get_coverstore_public_url()}/b/olid/{olid}-{size}.jpg"
+    if availability.get('identifier'):
+        ocaid = ed_or_solr['availability']['identifier']
+        return f"//archive.org/services/img/{ocaid}"
+
+    # Plain solr - we don't know which edition is which here, so this is most
+    # preferable
+    if ed_or_solr.get('cover_i'):
+        cover_i = ed_or_solr["cover_i"]
+        return f'{get_coverstore_public_url()}/b/id/{cover_i}-{size}.jpg'
+    if ed_or_solr.get('cover_edition_key'):
+        olid = ed_or_solr['cover_edition_key']
+        return f"{get_coverstore_public_url()}/b/olid/{olid}-{size}.jpg"
+    if ed_or_solr.get('ocaid'):
+        return f"//archive.org/services/img/{ed_or_solr.get('ocaid')}"
+
+    # No luck
+    return None
+
+
 def is_non_ia_ocaid(ocaid: str) -> bool:
     """
     Check if the ocaid "looks like" it's from another provider
diff --git a/openlibrary/plugins/openlibrary/code.py b/openlibrary/plugins/openlibrary/code.py
--- a/openlibrary/plugins/openlibrary/code.py
+++ b/openlibrary/plugins/openlibrary/code.py
@@ -18,7 +18,8 @@
 import infogami
 
 # make sure infogami.config.features is set
-from openlibrary.book_providers import get_book_provider, get_book_provider_by_name
+from openlibrary.book_providers import get_book_provider, get_book_provider_by_name, \
+    get_cover_url
 
 if not hasattr(infogami.config, 'features'):
     infogami.config.features = []
@@ -945,6 +946,7 @@ def setup_template_globals():
         'ceil': math.ceil,
         'get_book_provider': get_book_provider,
         'get_book_provider_by_name': get_book_provider_by_name,
+        'get_cover_url': get_cover_url,
 
         # bad use of globals
         'is_bot': is_bot,


Test patch: