You are here

function content_apachesolr_index_document_build in Apache Solr Search 6.3

Implements hook_apachesolr_index_document_build() on behalf of content module.

File

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

Code

function content_apachesolr_index_document_build(ApacheSolrDocument $document, $entity, $entity_type) {

  // Let field modules sanitize their data for output.
  _content_field_invoke('sanitize', $entity);
  $indexed_fields = apachesolr_entity_fields($entity_type);
  foreach ($indexed_fields as $index_key => $nodefields) {
    if (!empty($nodefields)) {
      foreach ($nodefields as $field_info) {
        if (is_array($field_info['field'])) {
          $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.
          $function = $field_info['indexing_callback'];
          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']);
            }
          }
        }
      }
    }
  }
}