You are here

class SarniaFacetapiTerm in Sarnia 7

Plugin for "term" query types.

Hierarchy

Expanded class hierarchy of SarniaFacetapiTerm

1 string reference to 'SarniaFacetapiTerm'
sarnia_facetapi_query_types in ./sarnia.module
Implements hook_facetapi_query_types().

File

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

View source
class SarniaFacetapiTerm extends SearchApiFacetapiTerm implements FacetapiQueryTypeInterface {
  public static function getType() {
    return 'sarnia_term';
  }

  /**
   * Initializes the facet's build array.
   *
   * @return array
   *   The initialized render array.
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SarniaFacetapiTerm::build public function Initializes the facet's build array. Overrides SearchApiFacetapiTerm::build
SarniaFacetapiTerm::getType public static function Returns the query type associated with the plugin. Overrides SearchApiFacetapiTerm::getType
SearchApiFacetapiTerm::addFacetFilter protected function Helper method for setting a facet filter on a query or query filter object.
SearchApiFacetapiTerm::execute public function Adds the filter to the query object. 1