Between operator in search_api assumes include of lower and upper

Created on 25 March 2024, about 1 year ago

Problem/Motivation

Between operator in this module doesn't include lower and upper values. But search_api assumes they should be included see src/Plugin/views/filter/SearchApiString.php from search_api module:

  /**
   * {@inheritdoc}
   */
  protected function opBetween($field) {
    // The parent implementation in NumericFilter uses is_numeric() checks now,
    // so we need to override it to check for any values.
    if ($this->value['min'] != '' && $this->value['max'] != '') {
      $operator = $this->operator == 'between' ? 'BETWEEN' : 'NOT BETWEEN';
      $this->getQuery()->addWhere($this->options['group'], $field, [
        $this->value['min'],
        $this->value['max'],
      ], $operator);
    }
    elseif ($this->value['min'] != '') {
      $operator = $this->operator == 'between' ? '>=' : '<';
      $this->getQuery()->addWhere($this->options['group'], $field, $this->value['min'], $operator);
    }
    elseif ($this->value['max'] != '') {
      $operator = $this->operator == 'between' ? '<=' : '>';
      $this->getQuery()->addWhere($this->options['group'], $field, $this->value['max'], $operator);
    }
  }

Steps to reproduce

Create a query with between operator, for example use facet range slider. Observe that results with the max and min values from range are not included

Proposed resolution

Include lower and upper values in filter query statement.

🐛 Bug report
Status

Needs review

Version

7.0

Component

Code

Created by

🇩🇪Germany a.dmitriiev

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024