Skip to content

Commit

Permalink
don't allow queries for both normal and advanced search to be combined
Browse files Browse the repository at this point in the history
fixes #1861
  • Loading branch information
longhotsummer committed Jul 12, 2024
1 parent 5fa737a commit 120e836
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions peachjam_search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,18 @@ def filter_queryset(self, request, queryset, view):
must_queries.extend(self.build_per_field_queries(request, view))

should_queries = []
should_queries.extend(self.build_basic_queries(request, view))
should_queries.extend(self.build_content_phrase_queries(request, view))
should_queries.extend(self.build_nested_page_queries(request, view))
should_queries.extend(self.build_nested_provision_queries(request, view))

# these handle advanced search
must_queries.extend(self.build_advanced_all_queries(request, view))
must_queries.extend(self.build_advanced_content_queries(request, view))
if self.is_advanced_search(request, view):
# these handle advanced search, and can't be combined with advanced search because they both
# build queries to return nested content, and ES complains if multiple queries try to return the
# same nested content fields
must_queries.extend(self.build_advanced_all_queries(request, view))
must_queries.extend(self.build_advanced_content_queries(request, view))
else:
# these handle basic search
should_queries.extend(self.build_basic_queries(request, view))
should_queries.extend(self.build_content_phrase_queries(request, view))
should_queries.extend(self.build_nested_page_queries(request, view))
should_queries.extend(self.build_nested_provision_queries(request, view))

return queryset.query(
"bool",
Expand All @@ -125,6 +129,13 @@ def filter_queryset(self, request, queryset, view):
minimum_should_match=1 if should_queries else 0,
)

def is_advanced_search(self, request, view):
# it's an advanced search if any of the search__* query parameters are present
return any(
request.query_params.get(self.search_param + "__" + field)
for field in list(view.search_fields.keys()) + ["all"]
)

def build_rank_feature_queries(self, request, view):
"""Apply a rank_feature query to boost the score based on the ranking field."""
if pj_settings().pagerank_boost_value:
Expand Down

0 comments on commit 120e836

Please sign in to comment.