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"""
|
"""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"""
|
"""find books based on arbitary keywords"""
|
||||||
if not query:
|
if not query:
|
||||||
return []
|
return []
|
||||||
|
@ -51,6 +51,9 @@ def search(query, min_confidence=0.1):
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if return_first and result_set:
|
||||||
|
return result_set[0]
|
||||||
|
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
"connector": connector,
|
"connector": connector,
|
||||||
|
@ -58,6 +61,9 @@ def search(query, min_confidence=0.1):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if return_first:
|
||||||
|
return None
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,12 +83,7 @@ def isbn_local_search(query, raw=False):
|
||||||
|
|
||||||
def first_search_result(query, min_confidence=0.1):
|
def first_search_result(query, min_confidence=0.1):
|
||||||
"""search until you find a result that fits"""
|
"""search until you find a result that fits"""
|
||||||
for connector in get_connectors():
|
return search(query, min_confidence=min_confidence, return_first=True)
|
||||||
result = connector.search(query, min_confidence=min_confidence)
|
|
||||||
if result:
|
|
||||||
return result[0]
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_connectors():
|
def get_connectors():
|
||||||
"""load all connectors"""
|
"""load all connectors"""
|
||||||
|
|
Loading…
Reference in a new issue