You are here

public function QueryTypeRangeBase::build in Facets 8

Builds the facet information, so it can be rendered.

Overrides QueryTypeInterface::build

1 call to QueryTypeRangeBase::build()
SearchApiGranular::build in src/Plugin/facets/query_type/SearchApiGranular.php
Builds the facet information, so it can be rendered.
1 method overrides QueryTypeRangeBase::build()
SearchApiGranular::build in src/Plugin/facets/query_type/SearchApiGranular.php
Builds the facet information, so it can be rendered.

File

src/QueryType/QueryTypeRangeBase.php, line 63

Class

QueryTypeRangeBase
A base class for query type plugins adding range.

Namespace

Drupal\facets\QueryType

Code

public function build() {

  // If there were no results or no query object, we can't do anything.
  if (empty($this->results)) {
    return $this->facet;
  }
  $query_operator = $this->facet
    ->getQueryOperator();
  $facet_results = [];
  foreach ($this->results as $result) {

    // Go through the results and add facet results grouped by filters
    // defined by self::calculateResultFilter().
    if ($result['count'] || $query_operator == 'or') {
      $count = $result['count'];
      if ($result_filter = $this
        ->calculateResultFilter(trim($result['filter'], '"'))) {
        if (isset($facet_results[$result_filter['raw']])) {
          $facet_results[$result_filter['raw']]
            ->setCount($facet_results[$result_filter['raw']]
            ->getCount() + $count);
        }
        else {
          $facet_results[$result_filter['raw']] = new Result($this->facet, $result_filter['raw'], $result_filter['display'], $count);
        }
      }
    }
  }
  $this->facet
    ->setResults($facet_results);
  return $this->facet;
}