Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 51a735972e |
@@ -42,4 +42,3 @@ and this project adheres to
|
||||
|
||||
- 🐛(backend) fix missing index creation in 'index/' view
|
||||
- 🐛(backend) fix parallel test execution issues
|
||||
- 🐛(backend) fix search type value #68
|
||||
|
||||
@@ -20,7 +20,7 @@ class SearchTypeEnum(str, Enum):
|
||||
"""Search type options"""
|
||||
|
||||
HYBRID = "hybrid"
|
||||
FULL_TEXT = "full-text"
|
||||
FULL_TEXT = "full_text"
|
||||
|
||||
|
||||
# Fields
|
||||
|
||||
@@ -18,7 +18,7 @@ from pydantic import (
|
||||
)
|
||||
|
||||
from . import enums
|
||||
from .services.opensearch import check_hybrid_search_enabled
|
||||
from .enums import SearchTypeEnum
|
||||
|
||||
|
||||
class DocumentSchema(BaseModel):
|
||||
@@ -119,22 +119,7 @@ class SearchQueryParametersSchema(BaseModel):
|
||||
order_by: Optional[Literal[enums.ORDER_BY_OPTIONS]] = Field(default=enums.RELEVANCE)
|
||||
order_direction: Optional[Literal["asc", "desc"]] = Field(default="desc")
|
||||
nb_results: Optional[conint(ge=1, le=300)] = Field(default=50)
|
||||
search_type: Optional[enums.SearchTypeEnum] = None
|
||||
|
||||
@model_validator(mode="after")
|
||||
def set_default_search_type(self):
|
||||
"""
|
||||
Set default search_type dynamically.
|
||||
If search_type is not provided, it will be set to hybrid if it is configured
|
||||
and fall back on full text otherwise.
|
||||
"""
|
||||
if self.search_type is None:
|
||||
self.search_type = (
|
||||
enums.SearchTypeEnum.HYBRID
|
||||
if check_hybrid_search_enabled()
|
||||
else enums.SearchTypeEnum.FULL_TEXT
|
||||
)
|
||||
return self
|
||||
search_type: Optional[SearchTypeEnum] = Field(default=None)
|
||||
|
||||
|
||||
class DeleteDocumentsSchema(BaseModel):
|
||||
|
||||
@@ -94,7 +94,7 @@ def test_api_documents_search_opensearch_env_variables_not_set(settings):
|
||||
|
||||
@responses.activate
|
||||
def test_api_documents_search_query_unknown_user(settings):
|
||||
"""Searching a document without an existing user should result in a 400 error"""
|
||||
"""Searching a document without an existing user should result in a 401 error"""
|
||||
setup_oicd_resource_server(
|
||||
responses,
|
||||
settings,
|
||||
|
||||
@@ -12,13 +12,14 @@ from rest_framework.response import Response
|
||||
|
||||
from . import schemas
|
||||
from .authentication import ServiceTokenAuthentication
|
||||
from .enums import SearchTypeEnum
|
||||
from .permissions import IsAuthAuthenticated
|
||||
from .services.indexing import (
|
||||
ensure_index_exists,
|
||||
get_opensearch_indices,
|
||||
prepare_document_for_indexing,
|
||||
)
|
||||
from .services.opensearch import opensearch_client
|
||||
from .services.opensearch import check_hybrid_search_enabled, opensearch_client
|
||||
from .services.search import search
|
||||
from .utils import get_language_value
|
||||
|
||||
@@ -305,6 +306,7 @@ class SearchDocumentView(ResourceServerMixin, views.APIView):
|
||||
- The search results can be sorted or filtered via querystring parameters.
|
||||
"""
|
||||
|
||||
authentication_classes = [ResourceServerAuthentication]
|
||||
permission_classes = [IsAuthAuthenticated]
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
@@ -363,13 +365,7 @@ class SearchDocumentView(ResourceServerMixin, views.APIView):
|
||||
audience = self._get_service_provider_audience()
|
||||
user_sub = self.request.user.sub
|
||||
groups = []
|
||||
|
||||
try:
|
||||
params = schemas.SearchQueryParametersSchema(**request.data)
|
||||
except PydanticValidationError as excpt:
|
||||
errors = {error["loc"][0]: error["msg"] for error in excpt.errors()}
|
||||
logger.error("Validation error: %s", errors)
|
||||
raise excpt
|
||||
params = schemas.SearchQueryParametersSchema(**request.data)
|
||||
|
||||
# Get index list for search query
|
||||
try:
|
||||
@@ -394,7 +390,11 @@ class SearchDocumentView(ResourceServerMixin, views.APIView):
|
||||
groups=groups,
|
||||
tags=params.tags,
|
||||
path=params.path,
|
||||
search_type=params.search_type,
|
||||
search_type=params.search_type
|
||||
if params.search_type
|
||||
else SearchTypeEnum.HYBRID
|
||||
if check_hybrid_search_enabled()
|
||||
else SearchTypeEnum.FULL_TEXT,
|
||||
)["hits"]["hits"]
|
||||
logger.info("found %d results", len(result))
|
||||
logger.debug("results %s", result)
|
||||
|
||||
+19
-19
@@ -23,31 +23,31 @@ description = "An application to print markdown to pdf from a set of managed tem
|
||||
keywords = ["Django", "Contacts", "Templates", "RBAC"]
|
||||
license = { file = "LICENSE" }
|
||||
readme = "README.md"
|
||||
requires-python = "~=3.12.0"
|
||||
requires-python = "~=3.14.3"
|
||||
dependencies = [
|
||||
"celery[redis]==5.6.2",
|
||||
"django-configurations==2.5.1",
|
||||
"django-cors-headers==4.9.0",
|
||||
"redis==5.3.1",
|
||||
"redis==7.3.0",
|
||||
"django-redis==6.0.0",
|
||||
"django==5.2.12",
|
||||
"django-lasuite[all]==0.0.22",
|
||||
"django==6.0.3",
|
||||
"django-lasuite[all]==0.0.25",
|
||||
"djangorestframework==3.16.1",
|
||||
"drf_spectacular==0.29.0",
|
||||
"dockerflow==2024.4.2",
|
||||
"dockerflow==2026.3.4",
|
||||
"factory_boy==3.3.3",
|
||||
"gunicorn==23.0.0",
|
||||
"gunicorn==25.1.0",
|
||||
"py3langid==0.3.0",
|
||||
"langchain-text-splitters==1.1.0",
|
||||
"langchain-text-splitters==1.1.1",
|
||||
"mozilla-django-oidc==5.0.2",
|
||||
"psycopg[binary]==3.3.2",
|
||||
"psycopg[binary]==3.3.3",
|
||||
"pydantic==2.12.5",
|
||||
"pyjwt==2.10.1",
|
||||
"requests==2.32.5",
|
||||
"sentry-sdk==2.48.0",
|
||||
"sentry-sdk==2.54.0",
|
||||
"url-normalize==2.2.1",
|
||||
"opensearch-py==3.1.0",
|
||||
"whitenoise==6.11.0",
|
||||
"whitenoise==6.12.0",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
@@ -59,21 +59,21 @@ dependencies = [
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"django-extensions==4.1",
|
||||
"drf-spectacular-sidecar==2026.1.1",
|
||||
"faker==40.1.0",
|
||||
"drf-spectacular-sidecar==2026.3.1",
|
||||
"faker==40.11.0",
|
||||
"ipdb==0.13.13",
|
||||
"ipython==9.8.0",
|
||||
"pyfakefs==6.0.0",
|
||||
"ipython==9.11.0",
|
||||
"pyfakefs==6.1.5",
|
||||
"pylint-django==2.7.0",
|
||||
"pylint==4.0.4",
|
||||
"pylint==4.0.5",
|
||||
"pytest-cov==7.0.0",
|
||||
"pytest-django==4.11.1",
|
||||
"pytest-django==4.12.0",
|
||||
"pytest==9.0.2",
|
||||
"pytest-icdiff==0.9",
|
||||
"pytest-xdist==3.8.0",
|
||||
"responses==0.25.8",
|
||||
"ruff==0.14.10",
|
||||
"types-requests==2.32.4.20250913",
|
||||
"responses==0.26.0",
|
||||
"ruff==0.15.6",
|
||||
"types-requests==2.32.4.20260107",
|
||||
]
|
||||
|
||||
[tool.setuptools]
|
||||
|
||||
Reference in New Issue
Block a user