From 68526a0c6d9eb2986f127ab70bfbccaf96b0b37d Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sun, 28 Jun 2015 07:52:34 -0500 Subject: [PATCH] allow unsorted multiword query in grid search --- gluon/sqlhtml.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index 717858e1..88bcab5f 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -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)