mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make true and false searches work correctly for numeric fields.
This commit is contained in:
parent
13a484833d
commit
566fa8d80f
@ -402,10 +402,22 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
matches = set([])
|
matches = set([])
|
||||||
if len(query) == 0:
|
if len(query) == 0:
|
||||||
return matches
|
return matches
|
||||||
|
|
||||||
|
if val_func is None:
|
||||||
|
loc = self.field_metadata[location]['rec_index']
|
||||||
|
val_func = lambda item, loc=loc: item[loc]
|
||||||
|
|
||||||
if query == 'false':
|
if query == 'false':
|
||||||
query = '0'
|
q = ''
|
||||||
|
relop = lambda x,y: x is None
|
||||||
|
val_func = lambda item, loc=loc: item[loc]
|
||||||
|
cast = adjust = lambda x: x
|
||||||
elif query == 'true':
|
elif query == 'true':
|
||||||
query = '!=0'
|
q = ''
|
||||||
|
relop = lambda x,y: x is not None
|
||||||
|
val_func = lambda item, loc=loc: item[loc]
|
||||||
|
cast = adjust = lambda x: x
|
||||||
|
else:
|
||||||
relop = None
|
relop = None
|
||||||
for k in self.numeric_search_relops.keys():
|
for k in self.numeric_search_relops.keys():
|
||||||
if query.startswith(k):
|
if query.startswith(k):
|
||||||
@ -414,19 +426,15 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
if relop is None:
|
if relop is None:
|
||||||
(p, relop) = self.numeric_search_relops['=']
|
(p, relop) = self.numeric_search_relops['=']
|
||||||
|
|
||||||
if val_func is None:
|
|
||||||
loc = self.field_metadata[location]['rec_index']
|
|
||||||
val_func = lambda item, loc=loc: item[loc]
|
|
||||||
|
|
||||||
dt = self.field_metadata[location]['datatype']
|
dt = self.field_metadata[location]['datatype']
|
||||||
if dt == 'int':
|
if dt == 'int':
|
||||||
cast = (lambda x: int (x))
|
cast = lambda x: int (x) if x is not None else None
|
||||||
adjust = lambda x: x
|
adjust = lambda x: x
|
||||||
elif dt == 'rating':
|
elif dt == 'rating':
|
||||||
cast = (lambda x: int (x))
|
cast = lambda x: int (x)
|
||||||
adjust = lambda x: x/2
|
adjust = lambda x: x/2
|
||||||
elif dt in ('float', 'composite'):
|
elif dt in ('float', 'composite'):
|
||||||
cast = lambda x : float (x)
|
cast = lambda x : float (x) if x is not None else None
|
||||||
adjust = lambda x: x
|
adjust = lambda x: x
|
||||||
else: # count operation
|
else: # count operation
|
||||||
cast = (lambda x: int (x))
|
cast = (lambda x: int (x))
|
||||||
@ -452,9 +460,7 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
v = cast(val_func(item))
|
v = cast(val_func(item))
|
||||||
except:
|
except:
|
||||||
v = 0
|
v = 0
|
||||||
if not v:
|
if v:
|
||||||
v = 0
|
|
||||||
else:
|
|
||||||
v = adjust(v)
|
v = adjust(v)
|
||||||
if relop(v, q):
|
if relop(v, q):
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user