-def parse_search_query(query):
- q = []
- for word in query.split():
- # Is this lexeme negated?
- negated = word.startswith("!")
-
- # Remove any special characters
- word = re.sub(r"\W+", "", word, flags=re.UNICODE)
- if not word:
- continue
-
- # Restore negation
- if negated:
- word = "!%s" % word
-
- q.append(word)
-
- return " & ".join(q)
-