mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add API to process each result when returning it
This commit is contained in:
parent
a398c0ece2
commit
9ae2074669
@ -987,9 +987,10 @@ class DB:
|
||||
return self.fts.dirty_book(book_id, *fmts)
|
||||
|
||||
def fts_search(self,
|
||||
fts_engine_query, use_stemming, highlight_start, highlight_end, snippet_size, restrict_to_book_ids, return_text,
|
||||
fts_engine_query, use_stemming, highlight_start, highlight_end, snippet_size, restrict_to_book_ids, return_text, process_each_result
|
||||
):
|
||||
yield from self.fts.search(fts_engine_query, use_stemming, highlight_start, highlight_end, snippet_size, restrict_to_book_ids, return_text,)
|
||||
yield from self.fts.search(
|
||||
fts_engine_query, use_stemming, highlight_start, highlight_end, snippet_size, restrict_to_book_ids, return_text, process_each_result)
|
||||
|
||||
def shutdown_fts(self):
|
||||
if self.fts_enabled:
|
||||
|
@ -633,6 +633,7 @@ class Cache:
|
||||
restrict_to_book_ids=None,
|
||||
return_text=True,
|
||||
result_type=tuple,
|
||||
process_each_result=None,
|
||||
):
|
||||
return result_type(self.backend.fts_search(
|
||||
fts_engine_query,
|
||||
@ -642,6 +643,7 @@ class Cache:
|
||||
snippet_size=snippet_size,
|
||||
return_text=return_text,
|
||||
restrict_to_book_ids=restrict_to_book_ids,
|
||||
process_each_result=process_each_result,
|
||||
))
|
||||
|
||||
# }}}
|
||||
|
@ -150,7 +150,7 @@ class FTS:
|
||||
|
||||
def search(self,
|
||||
fts_engine_query, use_stemming, highlight_start, highlight_end, snippet_size, restrict_to_book_ids,
|
||||
return_text=True,
|
||||
return_text=True, process_each_result=None
|
||||
):
|
||||
if restrict_to_book_ids is not None and not restrict_to_book_ids:
|
||||
return
|
||||
@ -184,12 +184,15 @@ class FTS:
|
||||
query += f'; DROP TABLE temp.{temp_table_name}'
|
||||
try:
|
||||
for record in conn.execute(query, tuple(data)):
|
||||
ret = yield {
|
||||
result = {
|
||||
'id': record[0],
|
||||
'book_id': record[1],
|
||||
'format': record[2],
|
||||
'text': record[3] if return_text else '',
|
||||
}
|
||||
if process_each_result is not None:
|
||||
result = process_each_result(result)
|
||||
ret = yield result
|
||||
if ret is True:
|
||||
break
|
||||
except apsw.SQLError as e:
|
||||
|
Loading…
x
Reference in New Issue
Block a user