mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Bug #1927141: Exception when search testing the length of an is_multiple composite
I made get_metadata a keyword argument for compatibility. There are no other uses in base calibre, but ...
This commit is contained in:
parent
6279cd7f2f
commit
9827755a9e
@ -331,6 +331,21 @@ class CompositeField(OneToOneField):
|
||||
for val, book_ids in iteritems(val_map):
|
||||
yield val, book_ids
|
||||
|
||||
def iter_counts(self, candidates, get_metadata=None):
|
||||
val_map = defaultdict(set)
|
||||
splitter = self.splitter
|
||||
for book_id in candidates:
|
||||
vals = self.get_value_with_cache(book_id, get_metadata)
|
||||
if splitter:
|
||||
length = len(list(vv.strip() for vv in vals.split(splitter) if vv.strip()))
|
||||
elif vals.strip:
|
||||
length = 1
|
||||
else:
|
||||
length = 0
|
||||
val_map[length].add(book_id)
|
||||
for val, book_ids in iteritems(val_map):
|
||||
yield val, book_ids
|
||||
|
||||
def get_composite_categories(self, tag_class, book_rating_map, book_ids,
|
||||
is_multiple, get_metadata):
|
||||
ans = []
|
||||
@ -542,7 +557,7 @@ class ManyToManyField(Field):
|
||||
if book_ids:
|
||||
yield val, book_ids
|
||||
|
||||
def iter_counts(self, candidates):
|
||||
def iter_counts(self, candidates, get_metadata=None):
|
||||
val_map = defaultdict(set)
|
||||
cbm = self.table.book_col_map
|
||||
for book_id in candidates:
|
||||
|
@ -265,7 +265,7 @@ class NumericSearch(object): # {{{
|
||||
cast = lambda x: 0 if x is None else int(x)
|
||||
adjust = lambda x: x // 2
|
||||
else:
|
||||
# Datatype is empty if the source is a tempate. Assume float
|
||||
# Datatype is empty if the source is a template. Assume float
|
||||
cast = float if dt in ('float', 'composite', 'half-rating', '') else int
|
||||
|
||||
mult = 1.0
|
||||
@ -609,7 +609,8 @@ class Parser(SearchQueryParser): # {{{
|
||||
if (fm['is_multiple'] and
|
||||
len(query) > 1 and query[0] == '#' and query[1] in '=<>!'):
|
||||
return self.num_search(icu_lower(query[1:]), partial(
|
||||
self.dbcache.fields[location].iter_counts, candidates),
|
||||
self.dbcache.fields[location].iter_counts, candidates,
|
||||
get_metadata=self.dbcache._get_proxy_metadata),
|
||||
location, dt, candidates)
|
||||
|
||||
# take care of boolean special case
|
||||
|
Loading…
x
Reference in New Issue
Block a user