Add language-aware filtering to random book feature #11630
+25
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #10810
Feature: Add language-aware filtering to the random book feature (
/randomendpoint)When users select a non-English language for the Open Library interface, the random book feature now prioritizes showing books with editions available in their selected language. This applies only to "populated languages" (those with >15k borrowable ebooks), with automatic fallback to all languages for unpopulated languages.
Technical
Implementation follows the existing QueryCarousel.html pattern:
home.random_book.{lang}(e.g.,home.random_book.fre,home.random_book.eng,home.random_book.all)random_book.GET()to:web.ctx.langtype:edition AND ebook_access:[borrowable TO *] AND language:{lang}when language is populatedPopulated languages (10 total): eng, fre, ger, spa, chi, ita, lat, dut, rus, jpn
Fallback behavior: For unpopulated languages (e.g., Hindi), the feature falls back to showing books from all languages, ensuring users always get results.
(cci:7://file:///home/krishna/Contribution/openlibrary/openlibrary/plugins/openlibrary/home.py:0:0-0:0)
Stakeholders
@cdrini