allow unsorted multiword query in grid search

This commit is contained in:
mdipierro
2015-06-28 07:52:34 -05:00
parent ad2003c618
commit 68526a0c6d
+9 -7
View File
@@ -1756,10 +1756,16 @@ class SQLFORM(FORM):
keywords = keywords[0]
request.vars.keywords = keywords
key = keywords.strip()
if key and ' ' not in key and not '"' in key and not "'" in key:
if not '"' in key:
SEARCHABLE_TYPES = ('string', 'text', 'list:string')
parts = [field.contains(
key) for field in fields if field.type in SEARCHABLE_TYPES]
sfields = [field for field in fields if field.type in SEARCHABLE_TYPES]
if settings.global_settings.web2py_runtime_gae:
return reduce(lambda a,b: a|b, [field.contains(key) for field in sfields])
else:
return reduce(lambda a,b:a&b,[
reduce(lambda a,b: a|b, [
field.contains(k) for field in sfields]
) for k in key.split()])
# from https://groups.google.com/forum/#!topic/web2py/hKe6lI25Bv4
# needs testing...
@@ -1773,10 +1779,6 @@ class SQLFORM(FORM):
# filters.append(reduce(lambda a, b: (a & b), all_words_filters))
#parts = filters
else:
parts = None
if parts:
return reduce(lambda a, b: a | b, parts)
else:
return smart_query(fields, key)