Skip to content

Language-Aware "Random Book" Feature #10810

@JordanFrederick

Description

@JordanFrederick

With Open Library becoming increasingly more language-aware (edition aware carousals, etc), it would be nice if the "Random Book" feature was as well. For example, only showing books with French editions available when the user has chosen to display the website in French.

Relevant code

This function will need to take into account the current user language:

class random_book(delegate.page):
path = "/random"
def GET(self):
keys = get_random_borrowable_ebook_keys(1000)
raise web.seeother(random.choice(keys))

@cache.memoize(
engine="memcache", key="home.random_book", expires=dateutil.HALF_HOUR_SECS
)
def get_random_borrowable_ebook_keys(count: int) -> list[str]:
solr = search.get_solr()
docs = solr.select(
'type:edition AND ebook_access:[borrowable TO *]',
fields=['key'],
rows=count,
sort=f'random_{random.random()} desc',
)['docs']
return [doc['key'] for doc in docs]

But only for populated languages. Something similar to this:

$ fallback_query = None
$if user_lang_only:
$ web_lang = get_lang() or 'en'
$ user_lang= convert_iso_to_marc(web_lang)
$if user_lang and user_lang in get_populated_languages():
$ fallback_query = query
$ query = query + ' language:' + user_lang

Metadata

Metadata

Assignees

No one assigned

    Labels

    Lead: @cdriniIssues overseen by Drini (Staff: Team Lead & Solr, Library Explorer, i18n) [managed]Priority: 3Issues that we can consider at our leisure. [managed]Theme: InternationalizationMaking OpenLibrary work for both foreign-language users and books. [managed]Type: Feature RequestIssue describes a feature or enhancement we'd like to implement. [managed]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions