diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index d63bd135..ab9900a7 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -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, diff --git a/bookwyrm/connectors/self_connector.py b/bookwyrm/connectors/self_connector.py index 0c21e7bc..c5d58a59 100644 --- a/bookwyrm/connectors/self_connector.py +++ b/bookwyrm/connectors/self_connector.py @@ -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: diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 5c5934dd..cc45bfb2 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -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,