diff --git a/apiserver/plane/api/views/search.py b/apiserver/plane/api/views/search.py index 35b75ce67..3c1b9c9d2 100644 --- a/apiserver/plane/api/views/search.py +++ b/apiserver/plane/api/views/search.py @@ -49,16 +49,24 @@ class GlobalSearchEndpoint(BaseAPIView): def filter_issues(self, query, slug, project_id, workspace_search): fields = ["name", "sequence_id", "project__identifier"] q = Q() + q_and = Q() for field in fields: - if field == "sequence_id": - sequences = re.findall(r"\d+\.\d+|\d+", query) - for sequence_id in sequences: - q |= Q(**{"sequence_id": sequence_id}) + if field in ["sequence_id", "project__identifier"]: + # Condition to check sequence + if field == "sequence_id": + sequences = re.findall(r"\d+\.\d+|\d+", query) + for sequence_id in sequences: + q_and &= Q(**{"sequence_id": int(sequence_id)}) + # Condition to check identifier + if field == "project__identifier": + identifiers = query.split("-") + if identifiers: + q_and &= Q(**{"project__identifier": identifiers[0]}) else: q |= Q(**{f"{field}__icontains": query}) - + final_q = q_and | q issues = Issue.issue_objects.filter( - q, + final_q, project__project_projectmember__member=self.request.user, workspace__slug=slug, ) diff --git a/apiserver/plane/utils/issue_search.py b/apiserver/plane/utils/issue_search.py index 40f85dde4..7779d25da 100644 --- a/apiserver/plane/utils/issue_search.py +++ b/apiserver/plane/utils/issue_search.py @@ -9,15 +9,27 @@ from plane.db.models import Issue def search_issues(query, queryset): - fields = ["name", "sequence_id"] + fields = ["name", "sequence_id", "project__identifier"] q = Q() + q_and = Q() # Q object for AND conditions + for field in fields: - if field == "sequence_id": - sequences = re.findall(r"\d+\.\d+|\d+", query) - for sequence_id in sequences: - q |= Q(**{"sequence_id": sequence_id}) + if field in ["sequence_id", "project__identifier"]: + # Condition to check sequence + if field == "sequence_id": + sequences = re.findall(r"\d+\.\d+|\d+", query) + for sequence_id in sequences: + q_and &= Q(**{"sequence_id": int(sequence_id)}) + # Condition to check identifier + if field == "project__identifier": + identifiers = query.split("-") + if identifiers: + q_and &= Q(**{"project__identifier": identifiers[0]}) else: q |= Q(**{f"{field}__icontains": query}) + + final_q = q_and | q + return queryset.filter( - q, + final_q, ).distinct()