"show reset link" conflict with exposed sort

Created on 10 January 2023, almost 2 years ago
Updated 26 April 2023, over 1 year ago

Problem/Motivation

Under a certain set of conditions (listed below), when you select an exposed sort on the search api results view, no results are shown, due to the presence of {facet-condition}=reset_all in the search query.

Steps to reproduce

  1. Create a search API page view.
  2. Add two or more sort criteria to the view, making each one exposed.
  3. Make sure that "Exposed form in block" = No.
  4. Save the view.
  5. Add a facet to the view using the widget "List of checkboxes".
  6. Enable "Show reset link".
  7. Disable "Hide reset link when no facet item is selected".
  8. Disable "Ensure that only one result can be displayed" (I'm not sure if this makes a difference).
  9. Save the facet.
  10. Go to the page view of the search.
  11. You should see "All" at the top of the facet values and some values for the view.
  12. On the exposed sort form, choose a different sort order.
  13. The view will no longer show any results.

Proposed resolution

The problem here is in the Build function of the LinksWidget class, at:

$result_item = new Result($facet, 'reset_all', $this->getConfiguration()['reset_text'], $max_items);
$result_item->setActiveState(FALSE);
$result_item->setUrl($url);

The widget is adding {facet-condition}=reset_all to the query for the given facet condition, whenever the exposed search is selected (assuming you didn't already select a value for the facet). Since no values for the field meet that condition, the results are empty.

I tried fixing this function myself by working with those lines of code, to no avail. In particular, removing the last line that sets the URL works insofar as the query is no longer set with the the reset_all value, but then the "ALL" checkbox becomes incorrectly styled / handled by JS.

The request here is for this code to be fixed to not alter the query itself, but still let the ALL checkbox get styled and handled correctly.

Workaround

I am altering the search api query to alter the filter condition where the condition value is set to "reset_all" as follows:

/**
 * Implements hook_search_api_query_alter().
 */
function teradici_core_search_api_query_alter(QueryInterface $query) {
  $condition_groups = &$query->getConditionGroup()->getConditions();
  foreach ($condition_groups as &$condition_group) {
    if ($condition_group instanceof \Drupal\search_api\Query\ConditionGroupInterface) {
      foreach ( $condition_group->getConditions() as $condition) {
        $condition_value = $condition->getValue();
        if ($condition_value == 'reset_all') {
          $condition->setOperator('NOT IN'); // This is easier than trying to remove the condition altogether.
        }
      }
    }
  }
}

This works, but we are still left with condition in the query that ideally is not inserted in the first place. In my case this is worsened by the fact that the query parameters are shown in the URL to the user via the "Views AJAX history" module.

Thank you!

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada Shiraz Dindar Sooke, BC

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024