Fix #1914910 [Annotations Browser: Error when searching for punctuation](https://bugs.launchpad.net/calibre/+bug/1914910)

This commit is contained in:
Kovid Goyal 2021-02-07 19:49:35 +05:30
parent 973bd004d8
commit e723f56973
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -17,6 +17,7 @@ from urllib.parse import quote
from calibre import prepare_string_for_xml from calibre import prepare_string_for_xml
from calibre.ebooks.metadata import authors_to_string, fmt_sidx from calibre.ebooks.metadata import authors_to_string, fmt_sidx
from calibre.db.backend import FTSQueryError
from calibre.gui2 import Application, choose_save_file, config, error_dialog, gprefs from calibre.gui2 import Application, choose_save_file, config, error_dialog, gprefs
from calibre.gui2.dialogs.confirm_delete import confirm from calibre.gui2.dialogs.confirm_delete import confirm
from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox
@ -543,22 +544,29 @@ class BrowsePanel(QWidget):
if q == self.current_query: if q == self.current_query:
self.results_list.show_next(backwards) self.results_list.show_next(backwards)
return return
with BusyCursor(): try:
db = current_db() with BusyCursor():
if not q['fts_engine_query']: db = current_db()
results = db.all_annotations( if not q['fts_engine_query']:
restrict_to_user=q['restrict_to_user'], limit=4096, annotation_type=q['annotation_type'], results = db.all_annotations(
ignore_removed=True, restrict_to_book_ids=q['restrict_to_book_ids'] or None restrict_to_user=q['restrict_to_user'], limit=4096, annotation_type=q['annotation_type'],
) ignore_removed=True, restrict_to_book_ids=q['restrict_to_book_ids'] or None
else: )
q2 = q.copy() else:
q2['restrict_to_book_ids'] = q.get('restrict_to_book_ids') or None q2 = q.copy()
results = db.search_annotations( q2['restrict_to_book_ids'] = q.get('restrict_to_book_ids') or None
highlight_start='\x1d', highlight_end='\x1d', snippet_size=64, results = db.search_annotations(
ignore_removed=True, **q2 highlight_start='\x1d', highlight_end='\x1d', snippet_size=64,
) ignore_removed=True, **q2
self.results_list.set_results(results, bool(q['fts_engine_query'])) )
self.current_query = q self.results_list.set_results(results, bool(q['fts_engine_query']))
self.current_query = q
except FTSQueryError as err:
return error_dialog(self, _('Invalid search expression'), '<p>' + _(
'The search expression: {0} is invalid. The search syntax used is the'
'SQLite Full text Search Query syntax, <a href="{1}">described here</a>.').format(
err.query, 'https://www.sqlite.org/fts5.html#full_text_query_syntax'),
det_msg=str(err), show=True)
def effective_query_changed(self): def effective_query_changed(self):
self.do_find() self.do_find()