mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
API to easily get books in a virtual library
Uses the search cache for maximum performance
This commit is contained in:
parent
ebeec06b0b
commit
303a5cca6a
@ -981,6 +981,14 @@ class Cache(object):
|
||||
'''
|
||||
return self._search_api(self, query, restriction, virtual_fields=virtual_fields, book_ids=book_ids)
|
||||
|
||||
@read_api
|
||||
def books_in_virtual_library(self, vl):
|
||||
' Return the set of books in the specified virtual library '
|
||||
vl = self._pref('virtual_libraries', {}).get(vl) if vl else None
|
||||
if vl is None:
|
||||
return self.all_book_ids()
|
||||
return frozenset(self._search('', vl))
|
||||
|
||||
@api
|
||||
def get_categories(self, sort='name', book_ids=None, already_fixed=None,
|
||||
first_letter_sort=False):
|
||||
|
@ -483,13 +483,18 @@ class ReadingTest(BaseTest):
|
||||
def test_restrictions(self): # {{{
|
||||
' Test searching with and without restrictions '
|
||||
cache = self.init_cache()
|
||||
self.assertSetEqual(cache.all_book_ids(), cache.search(''))
|
||||
self.assertSetEqual({1, 2}, cache.search('', 'not authors:=Unknown'))
|
||||
self.assertSetEqual(set(), cache.search('authors:=Unknown', 'not authors:=Unknown'))
|
||||
self.assertSetEqual({2}, cache.search('not authors:"=Author Two"', 'not authors:=Unknown'))
|
||||
self.assertSetEqual({2}, cache.search('not authors:"=Author Two"', book_ids={1, 2}))
|
||||
self.assertSetEqual({2}, cache.search('not authors:"=Author Two"', 'not authors:=Unknown', book_ids={1,2,3}))
|
||||
self.assertSetEqual(set(), cache.search('authors:=Unknown', 'not authors:=Unknown', book_ids={1,2,3}))
|
||||
se = self.assertSetEqual
|
||||
se(cache.all_book_ids(), cache.search(''))
|
||||
se({1, 2}, cache.search('', 'not authors:=Unknown'))
|
||||
se(set(), cache.search('authors:=Unknown', 'not authors:=Unknown'))
|
||||
se({2}, cache.search('not authors:"=Author Two"', 'not authors:=Unknown'))
|
||||
se({2}, cache.search('not authors:"=Author Two"', book_ids={1, 2}))
|
||||
se({2}, cache.search('not authors:"=Author Two"', 'not authors:=Unknown', book_ids={1,2,3}))
|
||||
se(set(), cache.search('authors:=Unknown', 'not authors:=Unknown', book_ids={1,2,3}))
|
||||
se(cache.all_book_ids(), cache.books_in_virtual_library(''))
|
||||
se(cache.all_book_ids(), cache.books_in_virtual_library('does not exist'))
|
||||
cache.set_pref('virtual_libraries', {'1':'title:"=Title One"'})
|
||||
se({2}, cache.books_in_virtual_library('1'))
|
||||
# }}}
|
||||
|
||||
def test_search_caching(self): # {{{
|
||||
|
Loading…
x
Reference in New Issue
Block a user