You are here

public function SearchFacetapiAdapter::getQueryInfo in Faceted Navigation for Search 7

Returns the query info for this facet field.

Parameters

array $facet: The facet definition as returned by facetapi_facet_load().

Return value

array An associative array containing:

  • fields: An array of field information, each of which are associative arrays containing:

    • table_alias: The table alias the field belongs to.
    • field: The name of the field containing the facet data.
    • joins: An array of join info, each of which are associative arrays containing:

      • table: The table being joined.
      • alias: The alias of the table being joined.
      • condition: The condition that joins the table.

File

plugins/facetapi/adapter.inc, line 75
Classes used by the Facet API module.

Class

SearchFacetapiAdapter
Facet API adapter for the Apache Solr Search Integration module.

Code

public function getQueryInfo(array $facet) {
  if (!$facet['field api name']) {
    $query_info = array(
      'fields' => array(
        'n.' . $facet['field'] => array(
          'table_alias' => 'n',
          'field' => $facet['field'],
        ),
      ),
    );
  }
  else {
    $query_info = array();

    // Gets field info, finds table name and field name.
    $field = field_info_field($facet['field api name']);
    $table = _field_sql_storage_tablename($field);

    // Iterates over columns, adds fields to query info.
    foreach ($field['columns'] as $column_name => $attributes) {
      $column = _field_sql_storage_columnname($field['field_name'], $column_name);
      $query_info['fields'][$table . '.' . $column] = array(
        'table_alias' => $table,
        'field' => $column,
      );
    }

    // Adds the join on the node table.
    $query_info['joins'] = array(
      $table => array(
        'table' => $table,
        'alias' => $table,
        'condition' => "n.vid = {$table}.revision_id",
      ),
    );
  }

  // Returns query info, makes sure all keys are present.
  return $query_info + array(
    'joins' => array(),
    'fields' => array(),
  );
}