mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix searching in half star fields
This commit is contained in:
parent
914113868d
commit
33b9f5e520
@ -252,12 +252,11 @@ class NumericSearch(object): # {{{
|
|||||||
else:
|
else:
|
||||||
relop = self.operators['=']
|
relop = self.operators['=']
|
||||||
|
|
||||||
cast = int
|
|
||||||
if dt == 'rating':
|
if dt == 'rating':
|
||||||
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
|
||||||
elif dt in ('float', 'composite'):
|
else:
|
||||||
cast = float
|
cast = float if dt in ('float', 'composite', 'half-rating') else int
|
||||||
|
|
||||||
mult = 1.0
|
mult = 1.0
|
||||||
if len(query) > 1:
|
if len(query) > 1:
|
||||||
@ -270,9 +269,12 @@ class NumericSearch(object): # {{{
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
q = cast(query) * mult
|
q = cast(query) * mult
|
||||||
except:
|
except Exception:
|
||||||
raise ParseException(
|
raise ParseException(
|
||||||
_('Non-numeric value in query: {0}').format(query))
|
_('Non-numeric value in query: {0}').format(query))
|
||||||
|
if dt == 'half-rating':
|
||||||
|
q = int(round(q * 2))
|
||||||
|
cast = int
|
||||||
|
|
||||||
qfalse = query == 'false'
|
qfalse = query == 'false'
|
||||||
for val, book_ids in field_iter():
|
for val, book_ids in field_iter():
|
||||||
@ -282,7 +284,7 @@ class NumericSearch(object): # {{{
|
|||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
v = cast(val)
|
v = cast(val)
|
||||||
except:
|
except Exception:
|
||||||
v = None
|
v = None
|
||||||
if v:
|
if v:
|
||||||
v = adjust(v)
|
v = adjust(v)
|
||||||
@ -569,6 +571,8 @@ class Parser(SearchQueryParser): # {{{
|
|||||||
else:
|
else:
|
||||||
field = self.dbcache.fields[location]
|
field = self.dbcache.fields[location]
|
||||||
fi, is_many = partial(self.field_iter, location, candidates), field.is_many
|
fi, is_many = partial(self.field_iter, location, candidates), field.is_many
|
||||||
|
if dt == 'rating' and fm['display'].get('allow_half_stars'):
|
||||||
|
dt = 'half-rating'
|
||||||
return self.num_search(
|
return self.num_search(
|
||||||
icu_lower(query), fi, location, dt, candidates, is_many=is_many)
|
icu_lower(query), fi, location, dt, candidates, is_many=is_many)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user