forked from mirrors/bookwyrm
Don't match arbitrary results on empty isbn queries
This commit is contained in:
parent
d04271af75
commit
9a114e1736
3 changed files with 13 additions and 3 deletions
|
@ -34,10 +34,15 @@ class AbstractMinimalConnector(ABC):
|
|||
for field in self_fields:
|
||||
setattr(self, field, getattr(info, field))
|
||||
|
||||
def search(self, query, min_confidence=None):# pylint: disable=unused-argument
|
||||
def search(self, query, min_confidence=None):
|
||||
''' free text search '''
|
||||
params = {}
|
||||
if min_confidence:
|
||||
params['min_confidence'] = min_confidence
|
||||
|
||||
resp = requests.get(
|
||||
'%s%s' % (self.search_url, query),
|
||||
params=params,
|
||||
headers={
|
||||
'Accept': 'application/json; charset=utf-8',
|
||||
'User-Agent': settings.USER_AGENT,
|
||||
|
|
|
@ -13,6 +13,8 @@ class Connector(AbstractConnector):
|
|||
''' instantiate a connector '''
|
||||
def search(self, query, min_confidence=0.1):
|
||||
''' search your local database '''
|
||||
if not query:
|
||||
return []
|
||||
# first, try searching unqiue identifiers
|
||||
results = search_identifiers(query)
|
||||
if not results:
|
||||
|
|
|
@ -258,10 +258,12 @@ def get_activity_feed(
|
|||
def search(request):
|
||||
''' that search bar up top '''
|
||||
query = request.GET.get('q')
|
||||
min_confidence = request.GET.get('min_confidence', 0.1)
|
||||
|
||||
if is_api_request(request):
|
||||
# only return local book results via json so we don't cause a cascade
|
||||
book_results = connector_manager.local_search(query)
|
||||
book_results = connector_manager.local_search(
|
||||
query, min_confidence=min_confidence)
|
||||
return JsonResponse([r.json() for r in book_results], safe=False)
|
||||
|
||||
# use webfinger for mastodon style account@domain.com username
|
||||
|
@ -278,7 +280,8 @@ def search(request):
|
|||
similarity__gt=0.5,
|
||||
).order_by('-similarity')[:10]
|
||||
|
||||
book_results = connector_manager.search(query)
|
||||
book_results = connector_manager.search(
|
||||
query, min_confidence=min_confidence)
|
||||
data = {
|
||||
'title': 'Search Results',
|
||||
'book_results': book_results,
|
||||
|
|
Loading…
Reference in a new issue