You are here

function field_apachesolr_index_document_build in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr.module \field_apachesolr_index_document_build()

Implements hook_apachesolr_index_document_build().

File

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

Code

function field_apachesolr_index_document_build(ApacheSolrDocument $document, $entity, $entity_type) {
  $info = entity_get_info($entity_type);
  if ($info['fieldable']) {

    // Handle fields including taxonomy.
    $indexed_fields = apachesolr_entity_fields($entity_type);
    foreach ($indexed_fields as $index_key => $nodefields) {
      foreach ($nodefields as $field_info) {
        $field_name = $field_info['field']['field_name'];

        // See if the node has fields that can be indexed
        if (isset($entity->{$field_name})) {

          // Got a field.
          $functions = $field_info['indexing_callback'];
          if (!is_array($functions)) {
            $functions = array(
              $functions,
            );
          }
          foreach ($functions as $function) {
            if ($function && function_exists($function)) {

              // NOTE: This function should always return an array.  One
              // entity field may be indexed to multiple Solr fields.
              $fields = $function($entity, $field_name, $index_key, $field_info);
              foreach ($fields as $field) {

                // It's fine to use this method also for single value fields.
                $document
                  ->setMultiValue($field['key'], $field['value']);
              }
            }
          }
        }
      }
    }
  }
}