forked from mirrors/bookwyrm
Merge pull request #1069 from bookwyrm-social/inventaire-confidence
Adds confidence ratings to inventaire results
This commit is contained in:
commit
9e9f94753d
1 changed files with 12 additions and 0 deletions
|
@ -74,6 +74,14 @@ class Connector(AbstractConnector):
|
|||
**{k: data.get(k) for k in ["uri", "image", "labels", "sitelinks"]},
|
||||
}
|
||||
|
||||
def search(self, query, min_confidence=None):
|
||||
"""overrides default search function with confidence ranking"""
|
||||
results = super().search(query)
|
||||
if min_confidence:
|
||||
# filter the search results after the fact
|
||||
return [r for r in results if r.confidence >= min_confidence]
|
||||
return results
|
||||
|
||||
def parse_search_data(self, data):
|
||||
return data.get("results")
|
||||
|
||||
|
@ -84,6 +92,9 @@ class Connector(AbstractConnector):
|
|||
if images
|
||||
else None
|
||||
)
|
||||
# a deeply messy translation of inventaire's scores
|
||||
confidence = float(search_result.get("_score", 0.1))
|
||||
confidence = 0.1 if confidence < 150 else 0.999
|
||||
return SearchResult(
|
||||
title=search_result.get("label"),
|
||||
key=self.get_remote_id(search_result.get("uri")),
|
||||
|
@ -92,6 +103,7 @@ class Connector(AbstractConnector):
|
|||
self.base_url, search_result.get("uri")
|
||||
),
|
||||
cover=cover,
|
||||
confidence=confidence,
|
||||
connector=self,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue