Skip to content

馃悰(search) combine several values of a choices filter with OR - #2856

Open
Tiago-Salles wants to merge 1 commit into
openfun:masterfrom
Tiago-Salles:Tiago-Salles/issues/2532-pace-filter-or
Open

Tiago-Salles wants to merge 1 commit into
openfun:masterfrom
Tiago-Salles:Tiago-Salles/issues/2532-pace-filter-or

Conversation

@Tiago-Salles

Copy link
Copy Markdown
Collaborator

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:

Query Results
?pace=1h-2h 1
?pace=gt-2h 1
?pace=1h-2h&pace=gt-2h 0

The cause is in ChoicesQueryMixin.get_query_fragment: it returns one query fragment per selected value, and CourseSearchForm.build_es_query flattens every fragment into a single bool must clause. 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 TermsQueryMixin emits a single terms query, which is an OR by nature. Only the filters built on ChoicesQueryMixin (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 should clause with minimum_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 bool must.

  • Combine the fragments of several selected values with should in ChoicesQueryMixin.get_query_fragment; a single selected value keeps the exact previous output and the fragment key is unchanged, so the facet aggregations that exclude a filter's own fragments keep working
  • Add unit tests for StaticChoicesFilterDefinition.get_query_fragment with one and several values
  • Add an Elasticsearch test selecting two paces and expecting the union of both course sets
  • Add a changelog entry

Related to: #2532

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.
@Tiago-Salles

Copy link
Copy Markdown
Collaborator Author

Hey, @jonathanreveille and @liamls, could you please review this? Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant