You are here

function _apachesolr_index_process_entity_get_document in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr.index.inc \_apachesolr_index_process_entity_get_document()
  2. 6.3 apachesolr.index.inc \_apachesolr_index_process_entity_get_document()

Returns a generic Solr document object for this entity.

This function will do the basic processing for the document that is common to all entities, but virtually all entities will need their own additional processing.

Parameters

object $entity: The entity for which we want a document.

string $entity_type: The type of entity we're processing.

Return value

ApacheSolrDocument

1 call to _apachesolr_index_process_entity_get_document()
apachesolr_convert_entity_to_documents in ./apachesolr.index.inc
The given entity is converted to an array via the callback specified in the entity type's info array. The array that the entity is converted to is the model of the document sent to the Apache Solr server for indexing. This function allows…

File

./apachesolr.index.inc, line 438
Functions related to Apache Solr indexing operations.

Code

function _apachesolr_index_process_entity_get_document($entity, $entity_type) {
  list($entity_id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  $document = new ApacheSolrDocument();

  // Define our url options in advance. This differs depending on the
  // language
  $languages = language_list();
  $url_options = array(
    'absolute' => TRUE,
  );
  if (isset($entity->language) && isset($languages[$entity->language])) {
    $url_options['language'] = $languages[$entity->language];
  }
  $document->id = apachesolr_document_id($entity_id, $entity_type);
  $document->site = url(NULL, $url_options);
  $document->hash = apachesolr_site_hash();
  $document->entity_id = $entity_id;
  $document->entity_type = $entity_type;
  $document->bundle = $bundle;
  $document->bundle_name = entity_bundle_label($entity_type, $bundle);
  if (empty($entity->language)) {

    // 'und' is the language-neutral code in Drupal 7.
    $document->ss_language = LANGUAGE_NONE;
  }
  else {
    $document->ss_language = $entity->language;
  }
  $path = entity_uri($entity_type, $entity);

  // A path is not a requirement of an entity
  if (!empty($path)) {
    $document->path = $path['path'];
    $document->url = url($path['path'], $path['options'] + $url_options);

    // Path aliases can have important information about the content.
    // Add them to the index as well.
    if (function_exists('drupal_get_path_alias')) {

      // Add any path alias to the index, looking first for language specific
      // aliases but using language neutral aliases otherwise.
      $output = drupal_get_path_alias($document->path, $document->ss_language);
      if ($output && $output != $document->path) {
        $document->path_alias = $output;
      }
    }
  }
  return $document;
}