2026-01-27 08:24:22 +00:00
|
|
|
# Copyright (c) 2023-present Plane Software, Inc. and contributors
|
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
# See the LICENSE file for details.
|
|
|
|
|
|
2023-04-04 18:47:16 +00:00
|
|
|
# Python imports
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
# Django imports
|
|
|
|
|
from django.db.models import Q
|
|
|
|
|
|
|
|
|
|
# Module imports
|
|
|
|
|
|
|
|
|
|
|
2023-06-05 07:21:30 +00:00
|
|
|
def search_issues(query, queryset):
|
2024-02-27 11:25:00 +00:00
|
|
|
fields = ["name", "sequence_id", "project__identifier"]
|
2023-04-04 18:47:16 +00:00
|
|
|
q = Q()
|
|
|
|
|
for field in fields:
|
2024-01-08 17:56:32 +00:00
|
|
|
if field == "sequence_id" and len(query) <= 20:
|
2024-02-27 11:25:00 +00:00
|
|
|
sequences = re.findall(r"\b\d+\b", query)
|
2023-04-04 18:47:16 +00:00
|
|
|
for sequence_id in sequences:
|
|
|
|
|
q |= Q(**{"sequence_id": sequence_id})
|
|
|
|
|
else:
|
|
|
|
|
q |= Q(**{f"{field}__icontains": query})
|
2024-11-21 12:12:44 +00:00
|
|
|
return queryset.filter(q).distinct()
|