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():
|
for x in self.iterall():
|
||||||
yield x[idx]
|
yield x[idx]
|
||||||
|
|
||||||
|
# Search functions {{{
|
||||||
|
|
||||||
def universal_set(self):
|
def universal_set(self):
|
||||||
return set([i[0] for i in self._data if i is not None])
|
return set([i[0] for i in self._data if i is not None])
|
||||||
|
|
||||||
@ -462,6 +464,30 @@ class ResultCache(SearchQueryParser):
|
|||||||
continue
|
continue
|
||||||
return matches
|
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):
|
def remove(self, id):
|
||||||
self._data[id] = None
|
self._data[id] = None
|
||||||
if id in self._map:
|
if id in self._map:
|
||||||
@ -551,6 +577,8 @@ class ResultCache(SearchQueryParser):
|
|||||||
if self.search_restriction:
|
if self.search_restriction:
|
||||||
self.search('', return_matches=False)
|
self.search('', return_matches=False)
|
||||||
|
|
||||||
|
# Sorting functions {{{
|
||||||
|
|
||||||
def seriescmp(self, sidx, siidx, x, y, library_order=None):
|
def seriescmp(self, sidx, siidx, x, y, library_order=None):
|
||||||
try:
|
try:
|
||||||
if library_order:
|
if library_order:
|
||||||
@ -615,24 +643,6 @@ class ResultCache(SearchQueryParser):
|
|||||||
self._map.sort(cmp=fcmp, reverse=not ascending)
|
self._map.sort(cmp=fcmp, reverse=not ascending)
|
||||||
self._map_filtered = [id for id in self._map if id in self._map_filtered]
|
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',
|
VALID_DATA_TYPES = frozenset([None, 'rating', 'text', 'comments', 'datetime',
|
||||||
'int', 'float', 'bool', 'series'])
|
'int', 'float', 'bool', 'series'])
|
||||||
|
|
||||||
|
# Builtin metadata {{{
|
||||||
|
|
||||||
_field_metadata = [
|
_field_metadata = [
|
||||||
('authors', {'table':'authors',
|
('authors', {'table':'authors',
|
||||||
'column':'name',
|
'column':'name',
|
||||||
@ -287,7 +289,8 @@ class FieldMetadata(dict):
|
|||||||
'search_terms':[],
|
'search_terms':[],
|
||||||
'is_custom':False,
|
'is_custom':False,
|
||||||
'is_category':False}),
|
'is_category':False}),
|
||||||
]
|
]
|
||||||
|
# }}}
|
||||||
|
|
||||||
# search labels that are not db columns
|
# search labels that are not db columns
|
||||||
search_items = [ 'all',
|
search_items = [ 'all',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user