From dca88ab6261e44740106fc050cfce388a0aaa299 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 13 Aug 2014 18:53:28 -0300 Subject: search now working, plus lowercase support --- py-fake-service/app/search/search_query.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'py-fake-service') 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 -- cgit v1.2.3