You are here

function _apachesolr_index_process_entity_get_document in Apache Solr Search 6.3

Same name and namespace in other branches
  1. 8 apachesolr.index.inc \_apachesolr_index_process_entity_get_document()
  2. 7 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

stdClass $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 409
Functions related to Apache Solr indexing operations.

Code

function _apachesolr_index_process_entity_get_document($entity, $entity_type) {
  module_load_include('php', 'apachesolr', 'Apache_Solr_Document');
  $entity_id = $entity->nid;
  $bundle = $entity->type;
  $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 = 'und';
    $path_language = NULL;
  }
  else {
    $document->ss_language = $entity->language;
    $path_language = $entity->language;
  }

  // Hardcoded drupal 6 node path
  $path = 'node/' . $entity->nid;

  // A path is not a requirement of an entity
  if (!empty($path)) {
    $document->path = $path;
    $document->url = url($path, $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, $path_language);
      if ($output && $output != $document->path) {
        $document->path_alias = $output;
      }
    }
  }
  return $document;
}