You are here

public function SearchApiGranular::calculateResultFilter in Facets 8

Calculate the grouped facet filter for a given value.

Parameters

string $value: The raw value for the facet before grouping.

Return value

array Keyed by 'display' value to be shown to the user, and 'raw' to be used for the url.

Overrides QueryTypeRangeBase::calculateResultFilter

File

src/Plugin/facets/query_type/SearchApiGranular.php, line 67

Class

SearchApiGranular
Basic support for numeric facets grouping by a granularity value.

Namespace

Drupal\facets\Plugin\facets\query_type

Code

public function calculateResultFilter($value) {
  assert($this
    ->getGranularity() > 0);
  $min_value = (int) $this
    ->getMinValue();
  $max_value = $this
    ->getMaxValue();
  $granularity = $this
    ->getGranularity();
  if ($value < $min_value || !empty($max_value) && $value > $max_value + $granularity - 1) {
    return FALSE;
  }
  return [
    'display' => $value - fmod($value - $min_value, $this
      ->getGranularity()),
    'raw' => $value - fmod($value - $min_value, $this
      ->getGranularity()),
  ];
}