internetarchive / openlibrary

One webpage for every book ever published!
https://openlibrary.org
GNU Affero General Public License v3.0
4.98k stars 1.25k forks source link

Books Page: Get Best Edition → Solr #7452

Open mekarpeles opened 1 year ago

mekarpeles commented 1 year ago

Related to #7451, performance

Describe the problem that you'd like solved

When a reader visits a Book Page, many of its editions are fetched, e.g. for the Other Editions table or to find the best edition: (https://github.com/internetarchive/openlibrary/blob/master/openlibrary/templates/type/edition/view.html#L41-L71). This process requires we fetch all the editions from infogami (rather than solr). This function should make a single solr call (instead of infogami db) -- potentially the same call which is required for loading the #7451. By using solr, we can also do a better job about choosing the desired edition (since we know more about the target language, etc)

Unknowns / Risks

Details

Needs

A fully complete book record for testing

mekarpeles commented 6 months ago

@cdrini to write docs on which solr work query to use

cdrini commented 6 months ago

The query we'll want is something like:

run_solr_query(
    WorkSearchScheme(),
    f'key:"{work_key}"',
    rows=1,
    fields=['key', 'editions'],
)

That should return a result like this: https://testing.openlibrary.org/search.json?q=key%3A%2Fworks%2FOL24156W&mode=everything&fields=key,editions

Note: I've fixed a bug with this endpoint that was preventing it from working correctly with key , so the link above is for testing. The PR for that bug fix is #8642 .

jimchamp commented 6 months ago

Thanks @cdrini!