diff --git a/src/calibre/db/search.py b/src/calibre/db/search.py index bd8853cbe0..b4e1c62a21 100644 --- a/src/calibre/db/search.py +++ b/src/calibre/db/search.py @@ -671,7 +671,7 @@ class Parser(SearchQueryParser): # {{{ matches = set() error_string = '*@*TEMPLATE_ERROR*@*' template_cache = {} - global_vars = {} + global_vars = {'_candidates': candidates} for book_id in candidates: mi = self.dbcache.get_proxy_metadata(book_id) val = mi.formatter.safe_format(template, {}, error_string, mi, diff --git a/src/calibre/gui2/dialogs/search.py b/src/calibre/gui2/dialogs/search.py index 4204036a1b..f5794fc335 100644 --- a/src/calibre/gui2/dialogs/search.py +++ b/src/calibre/gui2/dialogs/search.py @@ -294,7 +294,15 @@ def create_template_tab(self): self.template_program_box = le = TemplateLineEditor(self.tab_widget) le.setObjectName('template_program_box') le.setPlaceholderText(_('The template that generates the value')) - le.setToolTip(_('Right click to open a template editor')) + le.setToolTip('

' + + _('Right click to open a template editor.
' + 'Technical note: the set of book ids already matched by ' + 'previous search terms in the search expression is passed ' + 'to the template in the global variables dictionary with the ' + 'key "{0}". You can use the set to limit any work the ' + 'template does to the set of books already matched, possibly ' + 'improving performance.' + ).format('_candidates') + '

') lo = QHBoxLayout() lo.addWidget(le) self.edit_template_button = tb = QToolButton()