summaryrefslogtreecommitdiff
path: root/py-fake-service
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2014-08-13 18:53:28 -0300
committerVictor Shyba <victor.shyba@gmail.com>2014-08-13 18:53:28 -0300
commitdca88ab6261e44740106fc050cfce388a0aaa299 (patch)
treebd4e3ca59ea7f1bee1d8069ab9739711baf7cdf1 /py-fake-service
parent58df33ff5dd0f1ac3e8e76938fba3e481ec691bf (diff)
search now working, plus lowercase support
Diffstat (limited to 'py-fake-service')
-rw-r--r--py-fake-service/app/search/search_query.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/py-fake-service/app/search/search_query.py b/py-fake-service/app/search/search_query.py
index e8da89d8..2d13851d 100644
--- a/py-fake-service/app/search/search_query.py
+++ b/py-fake-service/app/search/search_query.py
@@ -23,25 +23,26 @@ class SearchQuery:
@staticmethod
def compile(query):
- compiled = {"tags": [], "not_tags": []}
+ compiled = {"tags": [], "not_tags": [], "general":[]}
scanner = StringScanner(query.encode('utf8').replace("\"", ""))
first_token = True
- while not scanner.is_eos:
+ while not scanner.is_eos:
token = scanner.scan(_next_token())
if not token:
- scanner.skip(_separators())
+ scanner.skip(_separators())
continue
if ":" in token:
- compiled = _compile_tag(compiled, token)
+ compiled = _compile_tag(compiled, token)
elif first_token:
- compiled["general"] = token
+ compiled["general"].append(token)
if not first_token:
- first_token = True
+ first_token = True
+ compiled["general"] = ' '.join(compiled["general"])
return SearchQuery(compiled)
def __init__(self, compiled):
@@ -55,11 +56,11 @@ class SearchQuery:
return True
if self.compiled.get('general'):
- search_terms = re.compile(self.compiled['general'])
+ search_terms = re.compile(self.compiled['general'], flags=re.IGNORECASE)
if search_terms.match(mail.body) or search_terms.match(mail.subject):
return True
- if not self.compiled.get('tags') and not self.compiled.get('not_tags'):
+ if not [v for v in self.compiled.values() if v]:
return True