You are here

function apachesolr_index_entities_document in Apache Solr Search 7

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

Convert a certain entity from the apachesolr index table to a set of documents. 1 entity can be converted in multiple documents if the apachesolr_index_entity_to_documents decides to do so.

Parameters

array $row: A row from the indexing table

string $entity_type: The type of the entity

string $env_id: The machine name of the environment.

Return value

array of ApacheSolrDocument(s)

1 call to apachesolr_index_entities_document()
apachesolr_index_entities in ./apachesolr.index.inc
Processes all index queues associated with the passed environment.

File

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

Code

function apachesolr_index_entities_document($row, $entity_type, $env_id) {
  $documents = array();
  if (!empty($row->status)) {

    // Let any module exclude this entity from the index.
    $build_document = TRUE;
    foreach (module_implements('apachesolr_exclude') as $module) {
      $exclude = module_invoke($module, 'apachesolr_exclude', $row->entity_id, $entity_type, $row, $env_id);

      // If the hook returns TRUE we should exclude the entity
      if (!empty($exclude)) {
        $build_document = FALSE;
      }
    }
    foreach (module_implements('apachesolr_' . $entity_type . '_exclude') as $module) {
      $exclude = module_invoke($module, 'apachesolr_' . $entity_type . '_exclude', $row->entity_id, $row, $env_id);

      // If the hook returns TRUE we should exclude the entity
      if (!empty($exclude)) {
        $build_document = FALSE;
      }
    }
    if ($build_document) {

      // TODO argument #2 is not an array
      $documents = array_merge($documents, apachesolr_index_entity_to_documents($row, $env_id));
    }
  }
  else {

    // Delete the entity from our index if the status callback returned 0
    apachesolr_remove_entity($env_id, $row->entity_type, $row->entity_id);
  }

  // Clear entity cache for this specific entity
  entity_get_controller($row->entity_type)
    ->resetCache(array(
    $row->entity_id,
  ));
  return $documents;
}