<commit_before>import re

from django.db import models
from django.db.models import Q


def normalize_query(query_string,
                    findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
                    normspace=re.compile(r'\s{2,}').sub):
    ''' Splits the query string in invidual keywords, getting rid of unecessary spaces
        and grouping quoted words together.
        Example:

        >>> normalize_query('  some random  words "with   quotes  " and   spaces')
        ['some', 'random', 'words', 'with quotes', 'and', 'spaces']

    '''
    return [normspace(' ', (t[0] or t[1]).strip()) for t in findterms(query_string)]


class SearchManager(models.Manager):
    search_fields = ()

    def _search(self, query):
        queryset = self.get_query_set()

        if not query or not self.search_fields:
            return queryset

        for keyword in normalize_query(query):
            negate = False
            if len(keyword)>1:
                if keyword[0] == '-':
                    keyword = keyword[1:]
                    negate = True
                elif keyword[0] == '+':
                    keyword = keyword[1:]

            if negate:<commit_msg>Add stupid default implementation of SearchManager.search<commit_after>import re

from django.db import models
from django.db.models import Q


def normalize_query(query_string,
                    findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
                    normspace=re.compile(r'\s{2,}').sub):
    ''' Splits the query string in invidual keywords, getting rid of unecessary spaces
        and grouping quoted words together.
        Example:

        >>> normalize_query('  some random  words "with   quotes  " and   spaces')
        ['some', 'random', 'words', 'with quotes', 'and', 'spaces']

    '''
    return [normspace(' ', (t[0] or t[1]).strip()) for t in findterms(query_string)]


class SearchManager(models.Manager):
    search_fields = ()

    def search(self, query):
        """
        This implementation stupidly forwards to _search, which does the gruntwork.

        Put your customizations in here.
        """

        return self._search(query)

    def _search(self, query):
        queryset = self.get_query_set()

        if not query or not self.search_fields:
            return queryset

        for keyword in normalize_query(query):
            negate = False
            if len(keyword)>1:
                if keyword[0] == '-':
                    keyword = keyword[1:]
                    negate = True
                elif keyword[0] == '+':
                    keyword = keyword[1:]

            if negate:
{'fraction_non_alphanumeric': 0.11922785768357305, 'fraction_numerical': 0.006056018168054504, 'mean_word_length': 2.034443168771527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3902350', 'n_tokens_mistral': 762, 'n_tokens_neox': 703, 'n_words': 208}