You are here

function sarnia_facetapi_facet_info_alter in Sarnia 7

Implements hook_facetapi_info_alter().

Add displayable Solr properties from Sarnia as facets.

File

./sarnia.module, line 1142

Code

function sarnia_facetapi_facet_info_alter(&$facet_info, $searcher_info) {
  if ('search_api' == $searcher_info['adapter'] && ($sarnia_type = sarnia_entity_type_load_by_index($searcher_info['instance']))) {
    $index = search_api_index_load($searcher_info['instance']);
    $server = search_api_server_load($index->server);
    if ($server) {
      foreach ($server
        ->getDisplayFields() as $facet_name => $field) {

        // Do not overwrite facets that rely on Search API default facet
        // settings.
        if (in_array($field
          ->getType(), array(
          'tdate',
        ))) {
          continue;
        }
        $facet_info[$facet_name] = array(
          'name' => $facet_name,
          'label' => $facet_name,
          'description' => '',
          'field' => $facet_name,
          'field alias' => $facet_name,
          'field api name' => FALSE,
          'field api bundles' => array(),
          'query types' => array(
            'sarnia_term',
            'term',
          ),
          'alter callbacks' => array(),
          'dependency plugins' => array(
            'bundle',
            'role',
          ),
          'default widget' => FALSE,
          'allowed operators' => array(
            FACETAPI_OPERATOR_AND => TRUE,
            FACETAPI_OPERATOR_OR => TRUE,
          ),
          'facet missing allowed' => TRUE,
          'facet mincount allowed' => TRUE,
          'weight' => 0,
          'map callback' => FALSE,
          'map options' => array(),
          'hierarchy callback' => FALSE,
          'values callback' => FALSE,
          'min callback' => FALSE,
          'max callback' => FALSE,
          'default sorts' => array(
            array(
              'active',
              SORT_DESC,
            ),
            array(
              'count',
              SORT_DESC,
            ),
            array(
              'display',
              SORT_ASC,
            ),
          ),
        );
        if (module_exists('facetapi_bonus')) {
          $facet_info[$facet_name]['dependency plugins'] = array(
            'bundle',
            'role',
            'facet',
          );
        }
        foreach ($server
          ->getFulltextFields() as $key => $field) {
          unset($facet_info[$key]);
        }
      }
    }
  }
}