From e7ec9c5d152f9ace1c79fe9c42efa5b804688d13 Mon Sep 17 00:00:00 2001 From: Haresh Kainth Date: Wed, 20 Nov 2024 01:07:48 +0000 Subject: [PATCH] chore:add logging for publisher_names and fix publisher filtering Added a log statement for `publisher_names` in the `config.py` to track incoming request data. Fixed an issue in `search.py` where the publisher filter was incorrectly using `type__icontains` instead of `publisher__icontains`. --- orp/orp_search/config.py | 1 + orp/orp_search/utils/search.py | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/orp/orp_search/config.py b/orp/orp_search/config.py index d80dd22..a1c4739 100644 --- a/orp/orp_search/config.py +++ b/orp/orp_search/config.py @@ -36,6 +36,7 @@ def __init__( self.id = id logger.info(f"document_types from request: {self.document_types}") + logger.info(f"publisher_names from request: {self.publisher_names}") def validate(self): """ diff --git a/orp/orp_search/utils/search.py b/orp/orp_search/utils/search.py index 4f59a00..0ed94b4 100644 --- a/orp/orp_search/utils/search.py +++ b/orp/orp_search/utils/search.py @@ -90,24 +90,20 @@ def search_database( # Filter by document types if config.document_types: - # Start with an empty Q object query = Q() + # Loop through the document types and add a Q object for each one for doc_type in config.document_types: query |= Q(type__icontains=doc_type) - - # Filter the queryset using the complex Q object queryset = queryset.filter(query) # Filter by publisher if config.publisher_names: - # Start with an empty Q object query = Q() + # Loop through the document types and add a Q object for each one for publisher in config.publisher_names: - query |= Q(type__icontains=publisher) - - # Filter the queryset using the complex Q object + query |= Q(publisher__icontains=publisher) queryset = queryset.filter(query) # Sort results based on the sort_by parameter (default) @@ -119,6 +115,8 @@ def search_database( calculate_score(config, queryset) return queryset.order_by("score") + return queryset + def search(context: dict, request: HttpRequest) -> dict: logger.info("received search request: %s", request)