public function SearchApiGranular::build in Facets 8
Builds the facet information, so it can be rendered.
Overrides QueryTypeRangeBase::build
File
- src/
Plugin/ facets/ query_type/ SearchApiGranular.php, line 34
Class
- SearchApiGranular
- Basic support for numeric facets grouping by a granularity value.
Namespace
Drupal\facets\Plugin\facets\query_typeCode
public function build() {
// If there were no results or no query object, we can't do anything.
if (empty($this->results)) {
return $this->facet;
}
$supportedFeatures = array_flip($this->query
->getIndex()
->getServerInstance()
->getBackend()
->getSupportedFeatures());
// Range grouping is supported.
if (isset($supportedFeatures['search_api_granular'])) {
$query_operator = $this->facet
->getQueryOperator();
$facet_results = [];
foreach ($this->results as $result) {
if ($result['count'] || $query_operator == 'or') {
$result_filter = trim($result['filter'], '"');
$facet_results[] = new Result($this->facet, $result_filter, $result_filter, $result['count']);
}
}
$this->facet
->setResults($facet_results);
return $this->facet;
}
return parent::build();
}