def search(self, query, search_fields=None):
    '\n        Build a queryset matching words in the given search query,\n        treating quoted terms as exact phrases and taking into\n        account + and - symbols as modifiers controlling which terms\n        to require and exclude.\n        '
    if search_fields:
        self._search_fields = search_fields_to_dict(search_fields)
    if (not self._search_fields):
        return self.none()
    terms = ' '.join(query.split()).replace('+ ', '+').replace('+"', '"+').replace('- ', '-').replace('-"', '"-').split('"')
    terms = [(('' if (t[0:1] not in '+-') else t[0:1]) + t.strip(punctuation)) for t in (terms[1::2] + ''.join(terms[::2]).split())]
    terms_no_stopwords = [t for t in terms if (t.lower() not in settings.STOP_WORDS)]
    get_positive_terms = (lambda terms: [t.lower().strip(punctuation) for t in terms if (t[0:1] != '-')])
    positive_terms = get_positive_terms(terms_no_stopwords)
    if positive_terms:
        terms = terms_no_stopwords
    else:
        positive_terms = get_positive_terms(terms)
    if (not positive_terms):
        return self.none()
    else:
        self._search_terms.update(positive_terms)
    excluded = [reduce(iand, [(~ Q(**{('%s__icontains' % f): t[1:]})) for f in self._search_fields.keys()]) for t in terms if (t[0:1] == '-')]
    required = [reduce(ior, [Q(**{('%s__icontains' % f): t[1:]}) for f in self._search_fields.keys()]) for t in terms if (t[0:1] == '+')]
    optional = [reduce(ior, [Q(**{('%s__icontains' % f): t}) for f in self._search_fields.keys()]) for t in terms if (t[0:1] not in '+-')]
    queryset = self
    if excluded:
        queryset = queryset.filter(reduce(iand, excluded))
    if required:
        queryset = queryset.filter(reduce(iand, required))
    elif optional:
        queryset = queryset.filter(reduce(ior, optional))
    return queryset.distinct()
Build a queryset matching words in the given search query,
treating quoted terms as exact phrases and taking into
account + and - symbols as modifiers controlling which terms
to require and exclude.
def search(self, query, search_fields=None):
    '\n        Build a queryset matching words in the given search query,\n        treating quoted terms as exact phrases and taking into\n        account + and - symbols as modifiers controlling which terms\n        to require and exclude.\n        '
    if search_fields:
        self._search_fields = search_fields_to_dict(search_fields)
    if (not self._search_fields):
        return self.none()
    terms = ' '.join(query.split()).replace('+ ', '+').replace('+"', '"+').replace('- ', '-').replace('-"', '"-').split('"')
    terms = [(( if (t[0:1] not in '+-') else t[0:1]) + t.strip(punctuation)) for t in (terms[1::2] + .join(terms[::2]).split())]
    terms_no_stopwords = [t for t in terms if (t.lower() not in settings.STOP_WORDS)]
    get_positive_terms = (lambda terms: [t.lower().strip(punctuation) for t in terms if (t[0:1] != '-')])
    positive_terms = get_positive_terms(terms_no_stopwords)
    if positive_terms:
        terms = terms_no_stopwords
    else:
        positive_terms = get_positive_terms(terms)
    if (not positive_terms):
        return self.none()
    else:
        self._search_terms.update(positive_terms)
    excluded = [reduce(iand, [(~ Q(**{('%s__icontains' % f): t[1:]})) for f in self._search_fields.keys()]) for t in terms if (t[0:1] == '-')]
    required = [reduce(ior, [Q(**{('%s__icontains' % f): t[1:]}) for f in self._search_fields.keys()]) for t in terms if (t[0:1] == '+')]
    optional = [reduce(ior, [Q(**{('%s__icontains' % f): t}) for f in self._search_fields.keys()]) for t in terms if (t[0:1] not in '+-')]
    queryset = self
    if excluded:
        queryset = queryset.filter(reduce(iand, excluded))
    if required:
        queryset = queryset.filter(reduce(iand, required))
    elif optional:
        queryset = queryset.filter(reduce(ior, optional))
    return queryset.distinct()