diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index c12326182a..b5e3013f61 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -1004,7 +1004,7 @@ class DB: def unretire_note(self, field, item_id, item_val): return self.notes.unretire(self.conn, field, item_id, item_val) - def notes_search(self, + def search_notes(self, fts_engine_query, use_stemming, highlight_start, highlight_end, snippet_size, restrict_to_fields, return_text, process_each_result, limit ): yield from self.notes.search( diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 388b7fa798..7392851156 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -741,9 +741,9 @@ class Cache: return self.backend.import_note(field, item_id, html, basedir, st.st_ctime, st.st_mtime) @write_api # we need to use write locking as SQLITE gives a locked table error if multiple FTS queries are made at the same time - def notes_search( + def search_notes( self, - fts_engine_query, + fts_engine_query='', use_stemming=True, highlight_start=None, highlight_end=None, @@ -755,7 +755,7 @@ class Cache: limit=None, ): ' Search the text of notes using an FTS index. If the query is empty return all notes. ' - return result_type(self.backend.notes_search( + return result_type(self.backend.search_notes( fts_engine_query, use_stemming=use_stemming, highlight_start=highlight_start, diff --git a/src/calibre/db/tests/notes.py b/src/calibre/db/tests/notes.py index 1fed6b61df..75c8ebd759 100644 --- a/src/calibre/db/tests/notes.py +++ b/src/calibre/db/tests/notes.py @@ -165,7 +165,7 @@ def test_fts(self: 'NotesTest'): def ids_for_search(x, restrict_to_fields=()): return { - (x['field'], x['item_id']) for x in cache.notes_search(x, restrict_to_fields=restrict_to_fields) + (x['field'], x['item_id']) for x in cache.search_notes(x, restrict_to_fields=restrict_to_fields) } self.ae(ids_for_search('wunderbar'), {('authors', authors[0])}) diff --git a/src/calibre/gui2/library/notes.py b/src/calibre/gui2/library/notes.py index 9310ce0a90..d07ee56ec5 100644 --- a/src/calibre/gui2/library/notes.py +++ b/src/calibre/gui2/library/notes.py @@ -5,8 +5,8 @@ import os from functools import partial from qt.core import ( QAbstractItemView, QCheckBox, QDialogButtonBox, QFont, QHBoxLayout, QIcon, - QKeySequence, QLabel, QMenu, QSize, Qt, QToolButton, QTreeWidget, QTreeWidgetItem, - QVBoxLayout, QWidget, pyqtSignal, + QKeySequence, QLabel, QMenu, QSize, QSplitter, Qt, QTimer, QToolButton, QTreeWidget, + QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal, ) from calibre.db.backend import FTSQueryError @@ -139,6 +139,8 @@ class ResultsList(QTreeWidget): for result in results: field_map[result['field']]['matches'].append(result) for field, entry in field_map.items(): + if not entry['matches']: + continue section = QTreeWidgetItem([entry['title']], 1) section.setFlags(Qt.ItemFlag.ItemIsEnabled) section.setFont(0, self.section_font) @@ -298,6 +300,13 @@ class NotesBrowser(Dialog): self.search_input = si = SearchInput(self) l.addWidget(si) + self.splitter = s = QSplitter(self) + l.addWidget(s, stretch=100) + s.setChildrenCollapsible(False) + + self.results_list = rl = ResultsList(self) + s.addWidget(rl) + self.use_stemmer = us = QCheckBox(_('&Match on related words')) us.setChecked(gprefs['browse_notes_use_stemmer']) us.setToolTip('

' + _( @@ -308,6 +317,7 @@ class NotesBrowser(Dialog): h = QHBoxLayout() l.addLayout(h) h.addWidget(us), h.addStretch(10), h.addWidget(self.bb) + QTimer.singleShot(0, self.do_find) def do_find(self, backwards=False): q = self.search_input.current_query