From 622833eb05744505eee8a2da23c6f749f5eca34a Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sat, 19 Aug 2017 14:37:55 +0200 Subject: [PATCH] Add ability to search for books in a vl (vl:foo). Fix not recomputing the search cache when vls are edited. --- src/calibre/db/search.py | 9 +++++++++ src/calibre/library/field_metadata.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/calibre/db/search.py b/src/calibre/db/search.py index 71138d0132..73934fe834 100644 --- a/src/calibre/db/search.py +++ b/src/calibre/db/search.py @@ -498,6 +498,15 @@ class Parser(SearchQueryParser): # {{{ if location not in self.all_search_locations: return matches + if location == 'vl': + vl = self.dbcache._pref('virtual_libraries', {}).get(query) if query else None + if not vl: + raise ParseException(_('No such virtual library: {0}').format(query)) + try: + return candidates & self.dbcache.books_in_virtual_library(query) + except (RuntimeError): + raise ParseException(_('Virtual library search is recursive: {0}').format(query)) + if (len(location) > 2 and location.startswith('@') and location[1:] in self.grouped_search_terms): location = location[1:] diff --git a/src/calibre/library/field_metadata.py b/src/calibre/library/field_metadata.py index 66153ddce5..12b35e0130 100644 --- a/src/calibre/library/field_metadata.py +++ b/src/calibre/library/field_metadata.py @@ -380,7 +380,7 @@ class FieldMetadata(object): 'int', 'float', 'bool', 'series', 'composite', 'enumeration']) # search labels that are not db columns - search_items = ['all', 'search'] + search_items = ['all', 'search', 'vl'] __calibre_serializable__ = True def __init__(self):