diff --git a/src/calibre/library/server/ajax.py b/src/calibre/library/server/ajax.py index f6f3f686d7..eac53b91bc 100644 --- a/src/calibre/library/server/ajax.py +++ b/src/calibre/library/server/ajax.py @@ -590,8 +590,7 @@ class AjaxServer(object): if isbytestring(query): query = query.decode('UTF-8') - ids = self.db.search_getting_ids(query.strip(), self.search_restriction, sort_results=False) - ids = list(ids) + ids = list(self.search_for_books(query)) self.db.data.multisort(fields=[(sfield, sort_order == 'asc')], subsort=True, only_ids=ids) total_num = len(ids) diff --git a/src/calibre/library/server/base.py b/src/calibre/library/server/base.py index 0fc301662f..e64319e88b 100644 --- a/src/calibre/library/server/base.py +++ b/src/calibre/library/server/base.py @@ -314,3 +314,9 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache, t.daemon = True t.start() + def search_for_books(self, query): + return self.db.search_getting_ids( + (query or '').strip(), self.search_restriction, + sort_results=False, use_virtual_library=False) + + diff --git a/src/calibre/library/server/browse.py b/src/calibre/library/server/browse.py index b489ed58db..6496ac09b9 100644 --- a/src/calibre/library/server/browse.py +++ b/src/calibre/library/server/browse.py @@ -931,8 +931,7 @@ class BrowseServer(object): def browse_random(self, *args, **kwargs): import random try: - book_id = random.choice(self.db.search_getting_ids( - '', self.search_restriction, sort_results=False)) + book_id = random.choice(self.search_for_books('')) except IndexError: raise cherrypy.HTTPError(404, 'This library has no books') ans = self.browse_render_details(book_id, add_random_button=True) @@ -957,7 +956,7 @@ class BrowseServer(object): def browse_search(self, query='', list_sort=None): if isbytestring(query): query = query.decode('UTF-8') - ids = self.db.search_getting_ids(query.strip(), self.search_restriction) + ids = self.search_for_books(query) items = [self.db.data.tablerow_for_id(x) for x in ids] sort = self.browse_sort_book_list(items, list_sort) ids = [x[0] for x in items] diff --git a/src/calibre/library/server/cache.py b/src/calibre/library/server/cache.py index 2c7f49162e..4133e4d31d 100644 --- a/src/calibre/library/server/cache.py +++ b/src/calibre/library/server/cache.py @@ -21,9 +21,7 @@ class Cache(object): def search_cache(self, search): old = self._search_cache.pop(search, None) if old is None or old[0] <= self.db.last_modified(): - matches = self.db.data.search_getting_ids(search, self.search_restriction, sort_results=False) - if not matches: - matches = [] + matches = self.search_for_books(search) or [] self._search_cache[search] = (utcnow(), frozenset(matches)) if len(self._search_cache) > 50: self._search_cache.popitem(last=False) diff --git a/src/calibre/library/server/mobile.py b/src/calibre/library/server/mobile.py index 9740216b5a..1b6479250e 100644 --- a/src/calibre/library/server/mobile.py +++ b/src/calibre/library/server/mobile.py @@ -222,7 +222,7 @@ class MobileServer(object): search = '' if isbytestring(search): search = search.decode('UTF-8') - ids = self.db.search_getting_ids(search.strip(), self.search_restriction, sort_results=False) + ids = self.search_for_books(search) FM = self.db.FIELD_MAP items = [r for r in iter(self.db) if r[FM['id']] in ids] if sort is not None: diff --git a/src/calibre/library/server/xml.py b/src/calibre/library/server/xml.py index 5f3fe5ec35..9808f8d9a8 100644 --- a/src/calibre/library/server/xml.py +++ b/src/calibre/library/server/xml.py @@ -53,7 +53,7 @@ class XMLServer(object): if isbytestring(search): search = search.decode('UTF-8') - ids = self.db.search_getting_ids(search.strip(), self.search_restriction, sort_results=False) + ids = self.search_for_books(search) FM = self.db.FIELD_MAP