You are here

function hook_apachesolr_field_mappings in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr.api.php \hook_apachesolr_field_mappings()
  2. 6.3 apachesolr.api.php \hook_apachesolr_field_mappings()

Add index mappings for Field API types. The default mappings array handles just list fields and taxonomy term reference fields, such as:

$mappings['list_text'] = array( 'indexing_callback' => array('apachesolr_fields_list_indexing_callback'), 'index_type' => 'string', 'map callback' => 'apachesolr_fields_list_display_callback', 'facets' => TRUE, ),

In your implementation you can add additional field types such as: $mappings['number_integer']['number'] = array(...);

You can also add mapping for a specific field. This will take precedence over any mapping for a general field type. A field-specific mapping would looks like: $mappings['per-field']['field_model_name'] = array(...);

Much more information can be found below in the example implementation or in facetapi.api.php. If you feel restricted with the options as set below there is nothing that stops you from implementing facetapi directly. However it is recommended to not directly talk to solr fields since this could break in the future.

Return value

array $mappings An associative array of mappings as defined by modules that implement hook_apachesolr_field_mappings().

5 functions implement hook_apachesolr_field_mappings()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

date_apachesolr_field_mappings in ./apachesolr.module
Implements hook_apachesolr_field_mappings() on behalf of date module.
entityreference_apachesolr_field_mappings in ./apachesolr.module
Implements hook_apachesolr_field_mappings() on behalf of EntityReferences (entityreference)
field_apachesolr_field_mappings in ./apachesolr.module
Implements hook_apachesolr_field_mappings().
node_reference_apachesolr_field_mappings in ./apachesolr.module
Implements hook_apachesolr_field_mappings() on behalf of References (node_reference).
user_reference_apachesolr_field_mappings in ./apachesolr.module
Implements hook_apachesolr_field_mappings() on behalf of References (user_reference).
1 invocation of hook_apachesolr_field_mappings()
apachesolr_get_field_mappings in ./apachesolr.module
Gets the Apache Solr field mappings.

File

./apachesolr.api.php, line 52
Exposed Hooks in 7.x:

Code

function hook_apachesolr_field_mappings() {
  $mappings = array(
    // Example for a field API type. See extensive documentation below
    'number_float' => array(
      'indexing_callback' => array(
        'apachesolr_fields_default_indexing_callback',
      ),
      'index_type' => 'tfloat',
      'facets' => TRUE,
      'query types' => array(
        'term',
        'numeric_range',
      ),
      'query type' => 'term',
      'facet mincount allowed' => TRUE,
    ),
    // Example for a field API field
    'per-field' => array(
      // machine name of the field in Field API
      'field_price' => array(
        // REQUIRED FIELDS //
        // Function callback to return the value that will be put in to
        // the solr index
        'indexing_callback' => array(
          'apachesolr_fields_default_indexing_callback',
        ),
        // NON REQUIRED FIELDS //
        // See apachesolr_index_key() for the correct type. Defaults string
        'index_type' => 'string',
        // How to display the values when they return as a facet
        'map callback' => 'apachesolr_fields_list_facet_map_callback',
        // Does your facet have a dynamic name? Add function call here and will
        // have the name of the return value
        'name callback' => FALSE,
        // If a custom field needs to be searchable but does not need to be faceted you
        // can change the 'facets' parameter to FALSE.
        'facets' => FALSE,
        // Do you want to allow items without value
        'facet missing allowed' => FALSE,
        // (optional)  Whether or not the facet supports the
        //    "minimum facet count" setting. Defaults to TRUE.
        'facet mincount allowed' => FALSE,
        // Field API allows any field to be multi-valued.
        // If we set this to false we are able to sort
        'dependency plugins' => array(
          'bundle',
          'role',
        ),
        // Does your solr index has a hierarchy?
        // See facetapi_get_taxonomy_hierarchy for details or
        // view the mapping of taxonomy_term_reference
        'hierarchy callback' => FALSE,
        // There are different query types to return information from Solr
        // term : Regular strings
        // date : Everything regarding dates
        // numeric_range : Useful when you have widgets that depend
        //   on statistics coming from Solr
        'query types' => array(
          'term',
          'numeric_range',
        ),
        // Backwards compatible with previous facetapi versions.
        // Pick the main query type
        'query type' => 'term',
        // What dependencies do you have (see facetapi)
        'multiple' => TRUE,
      ),
    ),
  );
  return $mappings;
}