forked from mirrors/bookwyrm
Uses one set of search logic for all results or just first
This commit is contained in:
parent
c005e458fa
commit
f2d985e583
1 changed files with 8 additions and 7 deletions
|
@ -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"""
|
||||
|
|
Loading…
Reference in a new issue