Skip to content

Commit

Permalink
chore:add logging for publisher_names and fix publisher filtering
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
hareshkainthdbt committed Nov 20, 2024
1 parent 8305d66 commit e7ec9c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions orp/orp_search/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
12 changes: 5 additions & 7 deletions orp/orp_search/utils/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit e7ec9c5

Please sign in to comment.