You are here

public function ApacheSolrFacetapiTerm::build in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 plugins/facetapi/query_type_term.inc \ApacheSolrFacetapiTerm::build()
  2. 6.3 plugins/facetapi/query_type_term.inc \ApacheSolrFacetapiTerm::build()

Initializes the facet's build array.

Return value

array The initialized render array.

File

plugins/facetapi/query_type_term.inc, line 85
Term query type plugin for the Apache Solr adapter.

Class

ApacheSolrFacetapiTerm
Plugin for "term" query types.

Code

public function build() {
  $build = array();
  if ($response = apachesolr_static_response_cache($this->adapter
    ->getSearcher())) {
    $settings = $this->adapter
      ->getFacet($this->facet)
      ->getSettings();
    if (isset($response->facet_counts->facet_fields->{$this->facet['field']})) {
      $values = (array) $response->facet_counts->facet_fields->{$this->facet['field']};
      foreach ($values as $value => $count) {

        // Facet missing may return 0 even if mincount is 1.
        if (empty($settings->settings['facet_mincount']) || $count) {
          $build[$value] = array(
            '#count' => $count,
          );
        }
      }
    }
  }
  return $build;
}