Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't allow queries for both normal and advanced search to be combined #1903

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
longhotsummer marked this conversation as resolved.
Show resolved Hide resolved
# 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
Loading