<commit_before># Copyright (C) 2014 <NAME> <<EMAIL>>
# Copyright (C) 2014 <NAME> <<EMAIL>>
# Copyright (C) 2014 <NAME> <<EMAIL>>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from django.apps import apps
from django.conf import settings


MAX_RESULTS = getattr(settings, "SEARCHES_MAX_RESULTS", 150)


def search_user_stories(project, text):
    model_cls = apps.get_model("userstories", "UserStory")
    where_clause = ("to_tsvector(coalesce(userstories_userstory.subject) || ' ' || "
                    "coalesce(userstories_userstory.description)) @@ plainto_tsquery(%s)")

    if text:
        return (model_cls.objects.extra(where=[where_clause], params=[text])
                                 .filter(project_id=project.pk)[:MAX_RESULTS])

    return model_cls.objects.filter(project_id=project.pk)[:MAX_RESULTS]


def search_tasks(project, text):
    model_cls = apps.get_model("tasks", "Task")
    where_clause = ("to_tsvector(coalesce(tasks_task.subject, '') || ' ' || coalesce(tasks_task.description, '')) "
                    "@@ plainto_tsquery(%s)")

    if text:
        return (model_cls.objects.extra(where=[where_clause], params=[text])
                                 .filter(project_id=project.pk)[:MAX_RESULTS])

    return model_cls.objects.filter(project_id=project.pk)[:MAX_RESULTS]


def search_issues(project, text):
    model_cls = apps.get_model("issues", "Issue")
    where_clause = ("to_tsvector(coalesce(issues_issue.subject) || ' ' || coalesce(issues_issue.description)) "
                    "@@ plainto_tsquery(%s)")

    if text:
        return (model_cls.objects.extra(where=[where_clause], params=[text])
                                 .filter(project_id=project.pk)[:MAX_RESULTS])

    return model_cls.objects.filter(project_id=project.pk)[:MAX_RESULTS]


def search_wiki_pages(project, text):
    model_cls = apps.get_model("wiki", "WikiPage")
    where_clause = ("to_tsvector(coalesce(wiki_wikipage.slug) || ' ' || coalesce(wiki_wikipage.content)) "
                    "@@ plainto_tsquery(%s)")

    if text:
        return (model_cls.objects.extra(where=[where_clause], params=[text])
                                 .filter(project_id=project.pk)[:MAX_RESULTS])

    return model_cls.objects.filter(project_id=project.pk)[:MAX_RESULTS]<commit_msg>Added Ref column into the list of columns that are searched<commit_after># Copyright (C) 2014 <NAME> <<EMAIL>>
# Copyright (C) 2014 <NAME> <<EMAIL>>
# Copyright (C) 2014 <NAME> <<EMAIL>>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from django.apps import apps
from django.conf import settings


MAX_RESULTS = getattr(settings, "SEARCHES_MAX_RESULTS", 150)


def search_user_stories(project, text):
    model_cls = apps.get_model("userstories", "UserStory")
    where_clause = ("to_tsvector(coalesce(userstories_userstory.subject) || ' ' || "
                    "coalesce(userstories_userstory.ref) || ' ' || "
                    "coalesce(userstories_userstory.description)) @@ plainto_tsquery(%s)")

    if text:
        return (model_cls.objects.extra(where=[where_clause], params=[text])
                                 .filter(project_id=project.pk)[:MAX_RESULTS])

    return model_cls.objects.filter(project_id=project.pk)[:MAX_RESULTS]


def search_tasks(project, text):
    model_cls = apps.get_model("tasks", "Task")
    where_clause = ("to_tsvector(coalesce(tasks_task.subject, '') || ' ' || "
                    "coalesce(tasks_task.ref) || ' ' || "
                    "coalesce(tasks_task.description, '')) @@ plainto_tsquery(%s)")

    if text:
        return (model_cls.objects.extra(where=[where_clause], params=[text])
                                 .filter(project_id=project.pk)[:MAX_RESULTS])

    return model_cls.objects.filter(project_id=project.pk)[:MAX_RESULTS]


def search_issues(project, text):
    model_cls = apps.get_model("issues", "Issue")
    where_clause = ("to_tsvector(coalesce(issues_issue.subject) || ' ' || "
                    "coalesce(issues_issue.ref) || ' ' || "
                    "coalesce(issues_issue.description)) @@ plainto_tsquery(%s)")

    if text:
        return (model_cls.objects.extra(where=[where_clause], params=[text])
                                 .filter(project_id=project.pk)[:MAX_RESULTS])

    return model_cls.objects.filter(project_id=project.pk)[:MAX_RESULTS]


def search_wiki_pages(project, text):
    model_cls = apps.get_model("wiki", "WikiPage")
    where_clause = ("to_tsvector(coalesce(wiki_wikipage.slug) || ' ' || coalesce(wiki_wikipage.content)) "
                    "@@ plainto_tsquery(%s)")

    if text:
        return (model_cls.objects.extra(where=[where_clause], params=[text])
                                 .filter(project_id=project.pk)[:MAX_RESULTS])

    return model_cls.objects.filter(project_id=project.pk)[:MAX_RESULTS]
{'fraction_non_alphanumeric': 0.12452455763188358, 'fraction_numerical': 0.005291880271208864, 'mean_word_length': 3.4536082474226806, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1653089', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1792, 'n_words': 416}