X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Fbackend%2Futil.py;h=ff8248eaed4f1974308a48a3c79deaeef31efe90;hb=9523790aa2677f948653e0079c77fed1734fe977;hp=ea7692a0dab3cb20210c9bb27e667da63d782c25;hpb=b1bf7d4853f2a8ed15cd8ec57fb0db7d9e849202;p=ipfire.org.git diff --git a/src/backend/util.py b/src/backend/util.py index ea7692a0..ff8248ea 100644 --- a/src/backend/util.py +++ b/src/backend/util.py @@ -1,8 +1,28 @@ -#!/usr/bin/python +#!/usr/bin/python3 import random +import re import string +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) + def format_size(s, max_unit=None): units = ("B", "kB", "MB", "GB", "TB")