From 786ab0ef804c271a7d84ae25a40f716d5c18018e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 24 May 2010 15:26:18 -0600 Subject: [PATCH 1/2] Fix search() behavior --- src/calibre/library/caches.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index 5e6c10c27b..e943a4141e 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -632,19 +632,21 @@ class ResultCache(SearchQueryParser): q = '' if not ignore_search_restriction: q = self.search_restriction - elif not ignore_search_restriction: - q = u'%s (%s)' % (self.search_restriction, query) + else: + if ignore_search_restriction: + q = u'%s' % query + else: + q = u'%s (%s)' % (self.search_restriction, query) if not q: if return_matches: return list(self._map) # when return_matches, do not update the maps! self._map_filtered = list(self._map) - return [] + return matches = sorted(self.parse(q)) ans = [id for id in self._map if id in matches] if return_matches: return ans self._map_filtered = ans - return [] def set_search_restriction(self, s): self.search_restriction = s From c0fbc32e4caf64715d7fb2014563d2aad947f05c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 24 May 2010 15:53:00 -0600 Subject: [PATCH 2/2] Fix search() behavior again --- src/calibre/library/caches.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index e943a4141e..10487af75a 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -628,14 +628,13 @@ class ResultCache(SearchQueryParser): def search(self, query, return_matches=False, ignore_search_restriction=False): + q = '' if not query or not query.strip(): - q = '' if not ignore_search_restriction: q = self.search_restriction else: - if ignore_search_restriction: - q = u'%s' % query - else: + q = query + if not ignore_search_restriction: q = u'%s (%s)' % (self.search_restriction, query) if not q: if return_matches: