You are here

public function FacetapiLuceneapiAdapter::getFacetData in Facet API 6

Returns a normalized array with facet counts included.

File

contrib/facetapi_luceneapi/facetapi_luceneapi.adapter.inc, line 169
Classes used by the Facet API module.

Class

FacetapiLuceneapiAdapter
Facet API adapter for Search Lucene API modules.

Code

public function getFacetData(array $facet) {

  // Opens the index, returns an empty index in it cannot be opened.
  if (!($this->_index = luceneapi_index_open($this
    ->getSearcher(), $errstr))) {
    luceneapi_throw_error($errstr);
    return array();
  }

  // Ugly. We have to re-build the query.
  // @todo Add an API function similar to apachesolr_current_query().
  // Gets query container, appends user query and facet queries.
  if (!($query = luceneapi_query_get('boolean'))) {
    throw new LuceneAPI_Exception(t('Error instantiating boolean query.'));
  }

  // Parses user query if a string was passed.
  $user_query = luceneapi_query_parse(search_get_keys(), $this
    ->getSearcher(), 'keys');
  if (!$user_query || form_get_errors()) {
    return array();
  }

  // Adds user query to query container, allows modules to alter the query.
  luceneapi_subquery_add($query, $user_query, 'required', TRUE);
  module_invoke_all('luceneapi_query_alter', $query, $this
    ->getSearcher(), $this
    ->getType());

  // Gets documents matched in the query.
  $this->_docs = facetapi_luceneapi_match_query($this->_index, $query);
  return parent::getFacetData($realm_name, $facets);
}