Use regexes to check if any explicit filters in query. Test can_filter

This commit is contained in:
Debanjum Singh Solanky
2022-09-03 23:47:28 +03:00
parent 546fad570d
commit 858d86075b
2 changed files with 10 additions and 2 deletions

View File

@@ -52,8 +52,8 @@ class ExplicitFilter:
def can_filter(self, raw_query):
"Check if query contains explicit filters"
# Extract explicit query portion with required, blocked words to filter from natural query
required_words = set([word[1:].lower() for word in raw_query.split() if word.startswith("+")])
blocked_words = set([word[1:].lower() for word in raw_query.split() if word.startswith("-")])
required_words = re.findall(self.required_regex, raw_query)
blocked_words = re.findall(self.blocked_regex, raw_query)
return len(required_words) != 0 or len(blocked_words) != 0