Esempio n. 1
0
    def name_filter(self, queryset, name, value):
        stopwords = ["the", "The", "THE", "a", "A"]
        value_arr = value.split()
        if (len(value_arr) > 1) and (value_arr[0] in stopwords):
            del value_arr[0]
        value = " ".join(value_arr)
        reg_value = '(' + regexsub('s$', "'?s?", value).replace(
            " ", " ?").replace("s ", "'?s? ") + ')'

        puncstripper = str.maketrans('', '',
                                     string.punctuation.replace('-', ''))
        stripped = value.translate(puncstripper)

        return queryset.filter(
            Q(name__icontains=value.replace("and", "&"))
            | Q(name__icontains=value.replace("&", "and"))
            | Q(name__icontains=stripped.replace("&", "and"))
            | Q(name__icontains=stripped.replace("and", "&"))
            | Q(name__iregex=reg_value))
Esempio n. 2
0
def stripSymbols(text):
    return (regexsub('[^A-Za-z0-9\. ]+', '', text).replace(".", " "))
def stripSymbols(text):
    """
    Given a string, remove all symbols and replace fulls top with space.
    """
    return (regexsub('[^A-Za-z0-9\. ]+', '', text).replace(".", " "))