forked from github/plane
fix: issue search when searching with identifiers
This commit is contained in:
parent
a243bb6a15
commit
0ab6621be3
@ -49,16 +49,24 @@ class GlobalSearchEndpoint(BaseAPIView):
|
|||||||
def filter_issues(self, query, slug, project_id, workspace_search):
|
def filter_issues(self, query, slug, project_id, workspace_search):
|
||||||
fields = ["name", "sequence_id", "project__identifier"]
|
fields = ["name", "sequence_id", "project__identifier"]
|
||||||
q = Q()
|
q = Q()
|
||||||
|
q_and = Q()
|
||||||
for field in fields:
|
for field in fields:
|
||||||
if field == "sequence_id":
|
if field in ["sequence_id", "project__identifier"]:
|
||||||
sequences = re.findall(r"\d+\.\d+|\d+", query)
|
# Condition to check sequence
|
||||||
for sequence_id in sequences:
|
if field == "sequence_id":
|
||||||
q |= Q(**{"sequence_id": 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:
|
else:
|
||||||
q |= Q(**{f"{field}__icontains": query})
|
q |= Q(**{f"{field}__icontains": query})
|
||||||
|
final_q = q_and | q
|
||||||
issues = Issue.issue_objects.filter(
|
issues = Issue.issue_objects.filter(
|
||||||
q,
|
final_q,
|
||||||
project__project_projectmember__member=self.request.user,
|
project__project_projectmember__member=self.request.user,
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
)
|
)
|
||||||
|
@ -9,15 +9,27 @@ from plane.db.models import Issue
|
|||||||
|
|
||||||
|
|
||||||
def search_issues(query, queryset):
|
def search_issues(query, queryset):
|
||||||
fields = ["name", "sequence_id"]
|
fields = ["name", "sequence_id", "project__identifier"]
|
||||||
q = Q()
|
q = Q()
|
||||||
|
q_and = Q() # Q object for AND conditions
|
||||||
|
|
||||||
for field in fields:
|
for field in fields:
|
||||||
if field == "sequence_id":
|
if field in ["sequence_id", "project__identifier"]:
|
||||||
sequences = re.findall(r"\d+\.\d+|\d+", query)
|
# Condition to check sequence
|
||||||
for sequence_id in sequences:
|
if field == "sequence_id":
|
||||||
q |= Q(**{"sequence_id": 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:
|
else:
|
||||||
q |= Q(**{f"{field}__icontains": query})
|
q |= Q(**{f"{field}__icontains": query})
|
||||||
|
|
||||||
|
final_q = q_and | q
|
||||||
|
|
||||||
return queryset.filter(
|
return queryset.filter(
|
||||||
q,
|
final_q,
|
||||||
).distinct()
|
).distinct()
|
||||||
|
Loading…
Reference in New Issue
Block a user