You are here

public function SarniaFacetapiTerm::build in Sarnia 7

Initializes the facet's build array.

Return value

array The initialized render array.

Overrides SearchApiFacetapiTerm::build

File

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

Class

SarniaFacetapiTerm
Plugin for "term" query types.

Code

public function build() {
  $facet = $this->adapter
    ->getFacet($this->facet);

  // The current search per facet is stored in a static variable (during
  // initActiveFilters) so that we can retrieve it here and get the correct
  // current search for this facet.
  $search_ids = drupal_static('search_api_facetapi_active_facets', array());
  $facet_key = $facet['name'] . '@' . $this->adapter
    ->getSearcher();
  if (empty($search_ids[$facet_key]) || !search_api_current_search($search_ids[$facet_key])) {
    return array();
  }
  $search_id = $search_ids[$facet_key];
  $search = search_api_current_search($search_id);
  $build = array();
  $results = $search[1];
  if (isset($results['search_api_facets']) && isset($results['search_api_facets'][$this->facet['field']])) {
    $values = $results['search_api_facets'][$this->facet['field']];
    foreach ($values as $value) {
      $filter = $value['filter'];
      $build[$filter] = array(
        '#count' => $value['count'],
        '#markup' => trim($filter, '"[]'),
      );
    }
  }
  return $build;
}