mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Code organization
This commit is contained in:
parent
1e77e6538f
commit
e531b51767
@ -141,6 +141,8 @@ class ResultCache(SearchQueryParser):
|
||||
for x in self.iterall():
|
||||
yield x[idx]
|
||||
|
||||
# Search functions {{{
|
||||
|
||||
def universal_set(self):
|
||||
return set([i[0] for i in self._data if i is not None])
|
||||
|
||||
@ -462,6 +464,30 @@ class ResultCache(SearchQueryParser):
|
||||
continue
|
||||
return matches
|
||||
|
||||
def search(self, query, return_matches=False):
|
||||
ans = self.search_getting_ids(query, self.search_restriction)
|
||||
if return_matches:
|
||||
return ans
|
||||
self._map_filtered = ans
|
||||
|
||||
def search_getting_ids(self, query, search_restriction):
|
||||
q = ''
|
||||
if not query or not query.strip():
|
||||
q = search_restriction
|
||||
else:
|
||||
q = query
|
||||
if search_restriction:
|
||||
q = u'%s (%s)' % (search_restriction, query)
|
||||
if not q:
|
||||
return list(self._map)
|
||||
matches = sorted(self.parse(q))
|
||||
return [id for id in self._map if id in matches]
|
||||
|
||||
def set_search_restriction(self, s):
|
||||
self.search_restriction = s
|
||||
|
||||
# }}}
|
||||
|
||||
def remove(self, id):
|
||||
self._data[id] = None
|
||||
if id in self._map:
|
||||
@ -551,6 +577,8 @@ class ResultCache(SearchQueryParser):
|
||||
if self.search_restriction:
|
||||
self.search('', return_matches=False)
|
||||
|
||||
# Sorting functions {{{
|
||||
|
||||
def seriescmp(self, sidx, siidx, x, y, library_order=None):
|
||||
try:
|
||||
if library_order:
|
||||
@ -615,24 +643,6 @@ class ResultCache(SearchQueryParser):
|
||||
self._map.sort(cmp=fcmp, reverse=not ascending)
|
||||
self._map_filtered = [id for id in self._map if id in self._map_filtered]
|
||||
|
||||
def search(self, query, return_matches=False):
|
||||
ans = self.search_getting_ids(query, self.search_restriction)
|
||||
if return_matches:
|
||||
return ans
|
||||
self._map_filtered = ans
|
||||
# }}}
|
||||
|
||||
def search_getting_ids(self, query, search_restriction):
|
||||
q = ''
|
||||
if not query or not query.strip():
|
||||
q = search_restriction
|
||||
else:
|
||||
q = query
|
||||
if search_restriction:
|
||||
q = u'%s (%s)' % (search_restriction, query)
|
||||
if not q:
|
||||
return list(self._map)
|
||||
matches = sorted(self.parse(q))
|
||||
return [id for id in self._map if id in matches]
|
||||
|
||||
def set_search_restriction(self, s):
|
||||
self.search_restriction = s
|
||||
|
@ -69,6 +69,8 @@ class FieldMetadata(dict):
|
||||
VALID_DATA_TYPES = frozenset([None, 'rating', 'text', 'comments', 'datetime',
|
||||
'int', 'float', 'bool', 'series'])
|
||||
|
||||
# Builtin metadata {{{
|
||||
|
||||
_field_metadata = [
|
||||
('authors', {'table':'authors',
|
||||
'column':'name',
|
||||
@ -288,6 +290,7 @@ class FieldMetadata(dict):
|
||||
'is_custom':False,
|
||||
'is_category':False}),
|
||||
]
|
||||
# }}}
|
||||
|
||||
# search labels that are not db columns
|
||||
search_items = [ 'all',
|
||||
|
Loading…
x
Reference in New Issue
Block a user