You are here

public function SearchApiRange::build in Facets 8

Builds the facet information, so it can be rendered.

Overrides QueryTypeInterface::build

File

src/Plugin/facets/query_type/SearchApiRange.php, line 55

Class

SearchApiRange
Provides support for range facets within the Search API scope.

Namespace

Drupal\facets\Plugin\facets\query_type

Code

public function build() {
  $query_operator = $this->facet
    ->getQueryOperator();
  if (!empty($this->results)) {
    $facet_results = [];
    foreach ($this->results as $result) {
      if ($result['count'] || $query_operator == 'or') {
        $count = $result['count'];
        while (is_array($result['filter'])) {
          $result['filter'] = current($result['filter']);
        }
        $result_filter = trim($result['filter'], '"');
        $result = new Result($this->facet, $result_filter, $result_filter, $count);
        $facet_results[] = $result;
      }
    }
    $this->facet
      ->setResults($facet_results);
  }
  return $this->facet;
}