Created
August 15, 2024 17:47
-
-
Save mekarpeles/701ed09cbd49c3b3b8303c29cc639085 to your computer and use it in GitHub Desktop.
Adding star ratings info to search page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/openlibrary/plugins/worksearch/code.py b/openlibrary/plugins/worksearch/code.py | |
index be3f4cefe..40d613166 100644 | |
--- a/openlibrary/plugins/worksearch/code.py | |
+++ b/openlibrary/plugins/worksearch/code.py | |
@@ -308,8 +308,10 @@ def do_search( | |
:param sort: csv sort ordering | |
:param spellcheck_count: Not really used; should probably drop | |
""" | |
+ # If you want work_search page html to extend default_fetched_fields: | |
+ extra_fields = {'editions', 'providers', 'ratings_average', 'ratings_count'} | |
+ fields = WorkSearchScheme.default_fetched_fields | extra_fields | |
- fields = WorkSearchScheme.default_fetched_fields | {'editions', 'providers'} | |
if web.cookies(sfw="").sfw == 'yes': | |
fields |= {'subject'} | |
@@ -376,6 +378,8 @@ def get_doc(doc: SolrDocument): | |
) | |
for ed in doc.get('editions', {}).get('docs', []) | |
], | |
+ ratings_average=doc.get('ratings_average'), | |
+ ratings_count=doc.get('ratings_count') | |
) | |
diff --git a/openlibrary/templates/work_search.html b/openlibrary/templates/work_search.html | |
index 853a95c57..f07894968 100644 | |
--- a/openlibrary/templates/work_search.html | |
+++ b/openlibrary/templates/work_search.html | |
@@ -140,6 +140,8 @@ $ ) | |
</div> | |
<div class="resultsContainer search-results-container"> | |
<div id="searchResults"> | |
+ $for d in search_response.docs: | |
+ $get_doc(d) | |
<ul class="list-books"> | |
$ works = [get_doc(d) for d in search_response.docs] | |
$ add_availability([(w.get('editions') or [None])[0] or w for w in works]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment