馃悰(search) combine several values of a choices filter with OR - #2856
Open
Tiago-Salles wants to merge 1 commit into
Open
Tiago-Salles wants to merge 1 commit into
Tiago-Salles wants to merge 1 commit into
Conversation
When several values of a choices filter (e.g. weekly pace) were selected, each value's query fragment was added to the global bool "must" clause, so the values were ANDed together and the search returned no results. Wrap the fragments of the selected values in a single "should" clause so they are ORed, while the filter as a whole is still ANDed with the other filters. Filters with a single selected value are unchanged.
Collaborator
Author
|
Hey, @jonathanreveille and @liamls, could you please review this? Thanks! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
When several values of a choices search filter are selected, the search returns no results. For example, on the demo site, selecting the weekly paces "One to two hours" and "More than two hours" returns nothing, while each of them alone returns courses:
?pace=1h-2h?pace=gt-2h?pace=1h-2h&pace=gt-2hThe cause is in
ChoicesQueryMixin.get_query_fragment: it returns one query fragment per selected value, andCourseSearchForm.build_es_queryflattens every fragment into a single boolmustclause. Each selected value therefore becomes an extra AND condition, and since a course run has a single pace, no document can match two of them.Terms based filters (subjects, levels, organizations, languages) are not affected because
TermsQueryMixinemits a singletermsquery, which is an OR by nature. Only the filters built onChoicesQueryMixin(pace, availability) have the problem.Proposal
When more than one value of a choices filter is selected, wrap the fragments of the selected values in a single bool
shouldclause withminimum_should_match: 1, so the values are ORed together while the filter as a whole is still ANDed with the other filters. Each value's fragment is a list of clauses that must all match (availability values have two range clauses), hence the inner boolmust.shouldinChoicesQueryMixin.get_query_fragment; a single selected value keeps the exact previous output and the fragmentkeyis unchanged, so the facet aggregations that exclude a filter's own fragments keep workingStaticChoicesFilterDefinition.get_query_fragmentwith one and several valuesRelated to: #2532