You are here

function apachesolr_index_node_solr_reindex in Apache Solr Search 8

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

Reindexing callback for ApacheSolr, for nodes.

Parameters

string $env_id: The machine name of the environment.

string|null $bundle: (optional) The bundle type to reindex. If not used all bundles will be re-indexed.

Return value

null returns NULL if the specified bundle is not in the indexable bundles list

Throws

Exception

2 string references to 'apachesolr_index_node_solr_reindex'
apachesolr_entity_info_alter in ./apachesolr.module
Implements hook_entity_info_alter().
hook_apachesolr_entity_info_alter in ./apachesolr.api.php
Add information to index other entities. There are some modules in http://drupal.org that can give a good example of custom entity indexing such as apachesolr_user, apachesolr_term

File

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

Code

function apachesolr_index_node_solr_reindex($env_id, $bundle = NULL) {
  $indexer_table = apachesolr_get_indexer_table('node');
  $transaction = db_transaction();
  try {
    $indexable_bundles = apachesolr_get_index_bundles($env_id, 'node');
    if ($bundle && !empty($indexable_bundles) && !in_array($bundle, $indexable_bundles)) {

      // The bundle specified is not in the indexable bundles list.
      return NULL;
    }

    // Leave status 0 rows - those need to be
    // removed from the index later.
    $delete = db_delete($indexer_table);
    $delete
      ->condition('status', 1);
    if (!empty($bundle)) {
      $delete
        ->condition('bundle', $bundle);
    }
    elseif (!empty($indexable_bundles)) {
      $delete
        ->condition('bundle', $indexable_bundles, 'IN');
    }
    $delete
      ->execute();
    $select = db_select('node', 'n');
    $select
      ->condition('status', 1);
    $select
      ->addExpression("'node'", 'entity_type');
    $select
      ->addField('n', 'nid', 'entity_id');
    $select
      ->addField('n', 'type', 'bundle');
    $select
      ->addField('n', 'status', 'status');
    $select
      ->addExpression(REQUEST_TIME, 'changed');
    if ($bundle) {

      // Mark all nodes of the specified content type for reindexing.
      $select
        ->condition('n.type', $bundle);
    }
    elseif (!empty($indexable_bundles)) {

      // Restrict reindex to content types in the indexable bundles list.
      $select
        ->condition('n.type', $indexable_bundles, 'IN');
    }
    $insert = db_insert($indexer_table)
      ->fields(array(
      'entity_id',
      'bundle',
      'status',
      'entity_type',
      'changed',
    ))
      ->from($select)
      ->execute();
  } catch (Exception $e) {
    $transaction
      ->rollback();
    throw $e;
  }
}