mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: search endpoint
This commit is contained in:
parent
f743386150
commit
edc1812ac0
@ -180,7 +180,8 @@ from .page.base import (
|
|||||||
PagesDescriptionViewSet,
|
PagesDescriptionViewSet,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .search import GlobalSearchEndpoint, IssueSearchEndpoint
|
from .search.base import GlobalSearchEndpoint
|
||||||
|
from .search.issue import IssueSearchEndpoint
|
||||||
|
|
||||||
|
|
||||||
from .external.base import (
|
from .external.base import (
|
||||||
|
@ -2,14 +2,17 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.db.models import Q, OuterRef, Exists
|
from django.db.models import Q, OuterRef, Subquery, Value, UUIDField, CharField
|
||||||
|
from django.contrib.postgres.aggregates import ArrayAgg
|
||||||
|
from django.contrib.postgres.fields import ArrayField
|
||||||
|
from django.db.models.functions import Coalesce
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from .base import BaseAPIView
|
from plane.app.views.base import BaseAPIView
|
||||||
from plane.db.models import (
|
from plane.db.models import (
|
||||||
Workspace,
|
Workspace,
|
||||||
Project,
|
Project,
|
||||||
@ -20,7 +23,6 @@ from plane.db.models import (
|
|||||||
IssueView,
|
IssueView,
|
||||||
ProjectPage,
|
ProjectPage,
|
||||||
)
|
)
|
||||||
from plane.utils.issue_search import search_issues
|
|
||||||
|
|
||||||
|
|
||||||
class GlobalSearchEndpoint(BaseAPIView):
|
class GlobalSearchEndpoint(BaseAPIView):
|
||||||
@ -146,29 +148,51 @@ class GlobalSearchEndpoint(BaseAPIView):
|
|||||||
for field in fields:
|
for field in fields:
|
||||||
q |= Q(**{f"{field}__icontains": query})
|
q |= Q(**{f"{field}__icontains": query})
|
||||||
|
|
||||||
pages = Page.objects.filter(
|
pages = (
|
||||||
q,
|
Page.objects.filter(
|
||||||
projects__project_projectmember__member=self.request.user,
|
q,
|
||||||
projects__project_projectmember__is_active=True,
|
projects__project_projectmember__member=self.request.user,
|
||||||
projects__archived_at__isnull=True,
|
projects__project_projectmember__is_active=True,
|
||||||
workspace__slug=slug,
|
projects__archived_at__isnull=True,
|
||||||
|
workspace__slug=slug,
|
||||||
|
)
|
||||||
|
.annotate(
|
||||||
|
project_ids=Coalesce(
|
||||||
|
ArrayAgg(
|
||||||
|
"projects__id",
|
||||||
|
distinct=True,
|
||||||
|
filter=~Q(projects__id=True),
|
||||||
|
),
|
||||||
|
Value([], output_field=ArrayField(UUIDField())),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.annotate(
|
||||||
|
project_identifiers=Coalesce(
|
||||||
|
ArrayAgg(
|
||||||
|
"projects__identifier",
|
||||||
|
distinct=True,
|
||||||
|
filter=~Q(projects__id=True),
|
||||||
|
),
|
||||||
|
Value([], output_field=ArrayField(CharField())),
|
||||||
|
),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if workspace_search == "false" and project_id:
|
if workspace_search == "false" and project_id:
|
||||||
|
project_subquery = ProjectPage.objects.filter(
|
||||||
|
page_id=OuterRef("id"),
|
||||||
|
project_id=project_id,
|
||||||
|
).values_list("project_id", flat=True)[:1]
|
||||||
|
|
||||||
pages = pages.annotate(
|
pages = pages.annotate(
|
||||||
project=Exists(
|
project_id=Subquery(project_subquery)
|
||||||
ProjectPage.objects.filter(
|
).filter(project_id=project_id)
|
||||||
page_id=OuterRef("id"),
|
|
||||||
project_id=self.kwargs.get("project_id"),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
).filter(project=True)
|
|
||||||
|
|
||||||
return pages.distinct().values(
|
return pages.distinct().values(
|
||||||
"name",
|
"name",
|
||||||
"id",
|
"id",
|
||||||
"project_id",
|
"project_ids",
|
||||||
"project__identifier",
|
"project_identifiers",
|
||||||
"workspace__slug",
|
"workspace__slug",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user