You are here

function apachesolr_search_apachesolr_facets in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 5 apachesolr_search.module \apachesolr_search_apachesolr_facets()
  2. 6 apachesolr_search.module \apachesolr_search_apachesolr_facets()
  3. 6.2 apachesolr_search.module \apachesolr_search_apachesolr_facets()

Implementation of hook_apachesolr_facets().

Returns an array keyed by block delta.

1 call to apachesolr_search_apachesolr_facets()
apachesolr_search_block in ./apachesolr_search.module
Implementation of hook_block().

File

./apachesolr_search.module, line 439
Provides a content search implementation for node content for use with the Apache Solr search application.

Code

function apachesolr_search_apachesolr_facets() {
  $facets = array();
  $facets['type'] = array(
    'info' => t('Node attribute: Filter by content type'),
    'facet_field' => 'type',
  );
  $facets['uid'] = array(
    'info' => t('Node attribute: Filter by author'),
    'facet_field' => 'uid',
  );
  $facets['language'] = array(
    'info' => t('Node attribute: Filter by language'),
    'facet_field' => 'language',
  );
  $facets['changed'] = array(
    'info' => t('Node attribute: Filter by updated date'),
    'facet_field' => 'changed',
  );
  $facets['created'] = array(
    'info' => t('Node attribute: Filter by post date'),
    'facet_field' => 'created',
  );

  // A book module facet.
  if (module_exists('book')) {
    $facets['is_book_bid'] = array(
      'info' => t('Book: Filter by Book'),
      'facet_field' => 'is_book_bid',
    );
  }

  // Get taxonomy vocabulary facets.
  if (module_exists('taxonomy')) {
    $vocabs = taxonomy_get_vocabularies();
    foreach ($vocabs as $vid => $vocab) {

      // In this case the delta and facet field are the same.
      $delta = 'im_vid_' . $vid;
      $facets[$delta] = array(
        'info' => t('Taxonomy vocabulary: Filter by taxonomy @name', array(
          '@name' => $vocab->name,
        )),
        'facet_field' => $delta,
      );
    }
  }

  // Get CCK field facets.
  $fields = apachesolr_cck_fields();
  if ($fields) {
    foreach ($fields as $name => $field) {

      // $delta can only be 32 chars, and the CCK field name may be this
      // long also, so we cannot add anything to it.
      $facets[$field['field_name']] = array_merge($field, array(
        'info' => t('CCK @field_type field: Filter by @field (@field_name)', array(
          '@field_type' => $field['field_type'],
          '@field' => $field['label'],
          '@field_name' => $field['field_name'],
        )),
        'facet_field' => apachesolr_index_key($field),
      ));
    }
  }
  return $facets;
}