You are here

function _apachesolr_index_get_next_set_query in Apache Solr Search 6.3

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

Internal function that identifies entities that are still due to be indexed.

Parameters

string $env_id Environment ID:

string $entity_type:

Return value

SelectQuery

2 calls to _apachesolr_index_get_next_set_query()
apachesolr_index_get_entities_to_index in ./apachesolr.index.inc
Returns an array of rows from a query based on an indexing environment. @todo Remove the read only because it is not environment specific
apachesolr_index_status in ./apachesolr.index.inc
Returns the total number of documents that are able to be indexed and the number of documents left to be indexed.

File

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

Code

function _apachesolr_index_get_next_set_query($env_id, $entity_type, $count = NULL) {
  $table = apachesolr_get_indexer_table($entity_type);
  $last_index_position = apachesolr_get_last_index_position($env_id, $entity_type);
  $bundles = apachesolr_get_index_bundles($env_id, $entity_type);

  // Get $last_entity_id and $last_changed.
  $last_entity_id = $last_index_position['last_entity_id'];
  $last_changed = $last_index_position['last_changed'];

  // Build array of arguments for this query.
  $next_set['args'] = array_merge(array(
    $last_changed,
    $last_changed,
    $last_entity_id,
  ), $bundles);

  // Find the next batch of entities to index for this entity type.  Note that
  // for ordering we're grabbing the oldest first and then ordering by ID so
  // that we get a definitive order.
  // Also note that we fetch ALL fields from the indexer table
  $query = 'SELECT ';
  $query .= $count ? 'COUNT(*)' : '*';
  $query .= " FROM {{$table}} aie\n      WHERE aie.status = 1 AND ((aie.changed > %d) OR ((aie.changed = %d) AND (aie.entity_id > %d)))\n      AND (aie.bundle IN (" . db_placeholders($bundles, 'varchar') . "))";
  if ($table == 'apachesolr_index_entities') {

    // Other, entity-specific tables don't need this condition.
    $query .= " AND aie.entity_type = '%s'";
    $next_set['args'] = array_merge($next_set['args'], $entity_type);
  }

  // It is important that everything is indexed in order of changed date and then
  // on entity_id because otherwise the conditions above will not match correctly.
  $query .= ' ORDER BY aie.changed ASC, aie.entity_id ASC';
  $next_set['query'] = $query;
  return $next_set;
}