diff --git a/bookwyrm/connectors/connector_manager.py b/bookwyrm/connectors/connector_manager.py index 86cebe80..cac8eb7c 100644 --- a/bookwyrm/connectors/connector_manager.py +++ b/bookwyrm/connectors/connector_manager.py @@ -19,7 +19,7 @@ class ConnectorException(HTTPError): """when the connector can't do what was asked""" -def search(query, min_confidence=0.1): +def search(query, min_confidence=0.1, return_first=False): """find books based on arbitary keywords""" if not query: return [] @@ -51,6 +51,9 @@ def search(query, min_confidence=0.1): logger.exception(e) continue + if return_first and result_set: + return result_set[0] + results.append( { "connector": connector, @@ -58,6 +61,9 @@ def search(query, min_confidence=0.1): } ) + if return_first: + return None + return results @@ -77,12 +83,7 @@ def isbn_local_search(query, raw=False): def first_search_result(query, min_confidence=0.1): """search until you find a result that fits""" - for connector in get_connectors(): - result = connector.search(query, min_confidence=min_confidence) - if result: - return result[0] - return None - + return search(query, min_confidence=min_confidence, return_first=True) def get_connectors(): """load all connectors"""