You are here

function apachesolr_index_entities in Apache Solr Search 6.3

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

Processes all index queues associated with the passed environment.

An environment usually indexes one or more entity types. Each entity type stores its queue in a database table that is defined in the entity type's info array. This function processes N number of items in each queue table, where N is the limit passed as the second argument.

The indexing routine allows developers to selectively bypass indexing on a per-entity basis by implementing the following hooks:

Parameters

string $env_id: The machine name of the environment.

int $limit: The number of items to process per queue table. For example, if there are two entities that are being indexed in this environment and they each have their own queue table, setting a limit of 50 will send a maximum number of 100 documents to the Apache Solr server.

Return value

int The total numer of documents sent to the Apache Solr server for indexing.

See also

apachesolr_index_get_entities_to_index()

apachesolr_index_entity_to_documents()

apachesolr_index_send_to_solr()

2 calls to apachesolr_index_entities()
apachesolr_cron in ./apachesolr.module
Implements hook_cron(). Runs the indexing process on all writable environments or just a given environment. @todo See if we can add info to the content type array for the cron_check
apachesolr_index_batch_index_entities in ./apachesolr.admin.inc
Batch Operation Callback
4 string references to 'apachesolr_index_entities'
apachesolr_get_indexer_table in ./apachesolr.module
Retrieve the indexer table for an entity type.
apachesolr_schema in ./apachesolr.install
Implements hook_schema().
apachesolr_update_6301 in ./apachesolr.install
Remove status from the key.
_apachesolr_index_get_next_set_query in ./apachesolr.index.inc
Internal function that identifies entities that are still due to be indexed.

File

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

Code

function apachesolr_index_entities($env_id, $limit) {
  $documents_submitted = 0;
  $entity_type = 'node';

  // With each pass through the callback, retrieve the next group of nids.
  $rows = apachesolr_index_get_entities_to_index($env_id, $entity_type, $limit);

  // If there are none for this entity type - ignore it.
  if (count($rows)) {
    $documents = array();
    foreach ($rows as $row) {
      $row_documents = apachesolr_index_entities_document($row, $entity_type, $env_id);

      // TODO argument #1 is not an array
      $documents = array_merge($documents, $row_documents);
    }
    $indexed = apachesolr_index_send_to_solr($env_id, $documents);
    if ($indexed !== FALSE) {
      $documents_submitted += count($documents);

      // Check who's the last in line
      $last_row = end($rows);

      // set our last position to the entity id and changed value so we can
      // keep track where we left off
      if (!empty($last_row->changed) && !empty($last_row->entity_id)) {
        apachesolr_set_last_index_position($env_id, $entity_type, $last_row->changed, $last_row->entity_id);
      }
      else {
        $message = 'Failure recording indexing progress. Last entity id processed: %entity_id with timestamp %last_changed';
        $variables = array(
          '%entity_id' => $last_row->entity_id,
          '%last_changed' => $last_row->changed,
        );

        // Add it to watchdog
        watchdog('Apache Solr', $message, $variables, WATCHDOG_ERROR);
      }
      apachesolr_set_last_index_updated($env_id, APACHESOLR_REQUEST_TIME);
    }
  }
  return $documents_submitted;
}