Merge pull request #2141 from bookwyrm-social/ol-search-rank

Use relative list order ranking in OpenLibrary search
This commit is contained in:
Mouse Reeve 2022-05-31 13:11:49 -07:00 committed by GitHub
commit 4c050d0999
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -153,12 +153,17 @@ class Connector(AbstractConnector):
return f"{self.covers_url}/b/id/{image_name}"
def parse_search_data(self, data, min_confidence):
for search_result in data.get("docs"):
for idx, search_result in enumerate(data.get("docs")):
# build the remote id from the openlibrary key
key = self.books_url + search_result["key"]
author = search_result.get("author_name") or ["Unknown"]
cover_blob = search_result.get("cover_i")
cover = self.get_cover_url([cover_blob], size="M") if cover_blob else None
# OL doesn't provide confidence, but it does sort by an internal ranking, so
# this confidence value is relative to the list position
confidence = 1 / (idx + 1)
yield SearchResult(
title=search_result.get("title"),
key=key,
@ -166,6 +171,7 @@ class Connector(AbstractConnector):
connector=self,
year=search_result.get("first_publish_year"),
cover=cover,
confidence=confidence,
)
def parse_isbn_search_data(self, data):