mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
Fixes #1927141 [specify separator for composite columns](https://bugs.launchpad.net/calibre/+bug/1927141)
This commit is contained in:
commit
3fe28fb1a4
@ -331,6 +331,21 @@ class CompositeField(OneToOneField):
|
|||||||
for val, book_ids in iteritems(val_map):
|
for val, book_ids in iteritems(val_map):
|
||||||
yield val, book_ids
|
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,
|
def get_composite_categories(self, tag_class, book_rating_map, book_ids,
|
||||||
is_multiple, get_metadata):
|
is_multiple, get_metadata):
|
||||||
ans = []
|
ans = []
|
||||||
@ -542,7 +557,7 @@ class ManyToManyField(Field):
|
|||||||
if book_ids:
|
if book_ids:
|
||||||
yield val, book_ids
|
yield val, book_ids
|
||||||
|
|
||||||
def iter_counts(self, candidates):
|
def iter_counts(self, candidates, get_metadata=None):
|
||||||
val_map = defaultdict(set)
|
val_map = defaultdict(set)
|
||||||
cbm = self.table.book_col_map
|
cbm = self.table.book_col_map
|
||||||
for book_id in candidates:
|
for book_id in candidates:
|
||||||
|
@ -265,7 +265,7 @@ class NumericSearch(object): # {{{
|
|||||||
cast = lambda x: 0 if x is None else int(x)
|
cast = lambda x: 0 if x is None else int(x)
|
||||||
adjust = lambda x: x // 2
|
adjust = lambda x: x // 2
|
||||||
else:
|
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
|
cast = float if dt in ('float', 'composite', 'half-rating', '') else int
|
||||||
|
|
||||||
mult = 1.0
|
mult = 1.0
|
||||||
@ -609,7 +609,8 @@ class Parser(SearchQueryParser): # {{{
|
|||||||
if (fm['is_multiple'] and
|
if (fm['is_multiple'] and
|
||||||
len(query) > 1 and query[0] == '#' and query[1] in '=<>!'):
|
len(query) > 1 and query[0] == '#' and query[1] in '=<>!'):
|
||||||
return self.num_search(icu_lower(query[1:]), partial(
|
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)
|
location, dt, candidates)
|
||||||
|
|
||||||
# take care of boolean special case
|
# take care of boolean special case
|
||||||
|
Loading…
x
Reference in New Issue
Block a user