You are here

function apachesolr_entity_field_facets in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 apachesolr.module \apachesolr_entity_field_facets()
  2. 7 apachesolr.module \apachesolr_entity_field_facets()

Returns an array of facets for the provided entity type's fields.

Parameters

string $entity_type: An entity type machine name.

Return value

An array of facets for the fields of the requested entity type.

1 call to apachesolr_entity_field_facets()
apachesolr_default_node_facet_info in ./apachesolr.module
Returns an array of facets for node fields and attributes.

File

./apachesolr.module, line 372
Integration with the Apache Solr search application.

Code

function apachesolr_entity_field_facets($entity_type) {
  $facets = array();
  foreach (apachesolr_entity_fields($entity_type) as $field_nm => $entity_fields) {
    foreach ($entity_fields as $field_info) {
      if (!empty($field_info['facets'])) {
        $field = apachesolr_index_key($field_info);
        $facets[$field] = array(
          'label' => check_plain($field_info['display_name']),
          'dependency plugins' => $field_info['dependency plugins'],
          'field api name' => $field_info['field']['field_name'],
          'description' => t('Filter by field of type @type.', array(
            '@type' => $field_info['field']['type'],
          )),
          'map callback' => $field_info['map callback'],
          'map options' => $field_info,
          'hierarchy callback' => $field_info['hierarchy callback'],
        );
        if (!empty($field_info['facet mincount allowed'])) {
          $facets[$field]['facet mincount allowed'] = $field_info['facet mincount allowed'];
        }
        if (!empty($field_info['facet missing allowed'])) {
          $facets[$field]['facet missing allowed'] = $field_info['facet missing allowed'];
        }
        if (!empty($field_info['query types'])) {
          $facets[$field]['query types'] = $field_info['query types'];
        }
        if (!empty($field_info['allowed operators'])) {
          $facets[$field]['allowed operators'] = $field_info['allowed operators'];
        }

        // TODO : This is actually deprecated but we should still support
        // older versions of facetapi. We should remove once facetapi has RC1
        // For reference : http://drupal.org/node/1161444
        if (!empty($field_info['query type'])) {
          $facets[$field]['query type'] = $field_info['query type'];
        }
        if (!empty($field_info['min callback'])) {
          $facets[$field]['min callback'] = $field_info['min callback'];
        }
        if (!empty($field_info['max callback'])) {
          $facets[$field]['max callback'] = $field_info['max callback'];
        }
        if (!empty($field_info['map callback'])) {
          $facets[$field]['map callback'] = $field_info['map callback'];
        }
        if (!empty($field_info['alter callbacks'])) {
          $facets[$field]['alter callbacks'] = $field_info['alter callbacks'];
        }
      }
    }
  }
  return $facets;
}