Show results when browsing implemented

This commit is contained in:
Kovid Goyal 2023-09-27 13:31:15 +05:30
parent 634f30156d
commit 7845f4036d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 17 additions and 7 deletions

View File

@ -1004,7 +1004,7 @@ class DB:
def unretire_note(self, field, item_id, item_val): def unretire_note(self, field, item_id, item_val):
return self.notes.unretire(self.conn, 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 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( yield from self.notes.search(

View File

@ -741,9 +741,9 @@ class Cache:
return self.backend.import_note(field, item_id, html, basedir, st.st_ctime, st.st_mtime) 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 @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, self,
fts_engine_query, fts_engine_query='',
use_stemming=True, use_stemming=True,
highlight_start=None, highlight_start=None,
highlight_end=None, highlight_end=None,
@ -755,7 +755,7 @@ class Cache:
limit=None, limit=None,
): ):
' Search the text of notes using an FTS index. If the query is empty return all notes. ' ' 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, fts_engine_query,
use_stemming=use_stemming, use_stemming=use_stemming,
highlight_start=highlight_start, highlight_start=highlight_start,

View File

@ -165,7 +165,7 @@ def test_fts(self: 'NotesTest'):
def ids_for_search(x, restrict_to_fields=()): def ids_for_search(x, restrict_to_fields=()):
return { 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])}) self.ae(ids_for_search('wunderbar'), {('authors', authors[0])})

View File

@ -5,8 +5,8 @@ import os
from functools import partial from functools import partial
from qt.core import ( from qt.core import (
QAbstractItemView, QCheckBox, QDialogButtonBox, QFont, QHBoxLayout, QIcon, QAbstractItemView, QCheckBox, QDialogButtonBox, QFont, QHBoxLayout, QIcon,
QKeySequence, QLabel, QMenu, QSize, Qt, QToolButton, QTreeWidget, QTreeWidgetItem, QKeySequence, QLabel, QMenu, QSize, QSplitter, Qt, QTimer, QToolButton, QTreeWidget,
QVBoxLayout, QWidget, pyqtSignal, QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal,
) )
from calibre.db.backend import FTSQueryError from calibre.db.backend import FTSQueryError
@ -139,6 +139,8 @@ class ResultsList(QTreeWidget):
for result in results: for result in results:
field_map[result['field']]['matches'].append(result) field_map[result['field']]['matches'].append(result)
for field, entry in field_map.items(): for field, entry in field_map.items():
if not entry['matches']:
continue
section = QTreeWidgetItem([entry['title']], 1) section = QTreeWidgetItem([entry['title']], 1)
section.setFlags(Qt.ItemFlag.ItemIsEnabled) section.setFlags(Qt.ItemFlag.ItemIsEnabled)
section.setFont(0, self.section_font) section.setFont(0, self.section_font)
@ -298,6 +300,13 @@ class NotesBrowser(Dialog):
self.search_input = si = SearchInput(self) self.search_input = si = SearchInput(self)
l.addWidget(si) 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')) self.use_stemmer = us = QCheckBox(_('&Match on related words'))
us.setChecked(gprefs['browse_notes_use_stemmer']) us.setChecked(gprefs['browse_notes_use_stemmer'])
us.setToolTip('<p>' + _( us.setToolTip('<p>' + _(
@ -308,6 +317,7 @@ class NotesBrowser(Dialog):
h = QHBoxLayout() h = QHBoxLayout()
l.addLayout(h) l.addLayout(h)
h.addWidget(us), h.addStretch(10), h.addWidget(self.bb) h.addWidget(us), h.addStretch(10), h.addWidget(self.bb)
QTimer.singleShot(0, self.do_find)
def do_find(self, backwards=False): def do_find(self, backwards=False):
q = self.search_input.current_query q = self.search_input.current_query