You are here

function apachesolr_index_node_solr_reindex in Apache Solr Search 6.3

Same name and namespace in other branches
  1. 8 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 solr environment

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

Throws

Exception

2 string references to 'apachesolr_index_node_solr_reindex'
apachesolr_get_index_callbacks in ./apachesolr.module
Return a set of callbacks for indexing a node
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 880
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');
  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;
    }

    // in the 6.x-3.x version we are not very respective to what bundles we
    // keep or remove in contrary to the 7.x-1.x version. db layer makes our
    // life complicated
    if ($bundle) {

      // Leave status 0 rows - those need to be
      // removed from the index later.
      db_query("DELETE FROM {{$indexer_table}} WHERE entity_type = 'node' AND bundle = '%s' AND status = 1", $bundle);

      // Mark all nodes of the specified content type for reindexing.
      $query = "INSERT INTO {{$indexer_table}} (entity_id, bundle, status, entity_type, changed) (\n        SELECT n.nid AS entity_id, n.type AS bundle, n.status AS status, 'node' AS entity_type, %d AS changed\n        FROM {node} n WHERE n.type = '%s' AND status = 1)";
      db_query($query, APACHESOLR_REQUEST_TIME, $bundle);
    }
    else {

      // Leave status 0 rows - those need to be
      // removed from the index later.
      db_query("DELETE FROM {{$indexer_table}} WHERE entity_type = 'node' AND status = 1");
      $query = "INSERT INTO {{$indexer_table}} (entity_id, bundle, status, entity_type, changed) (\n        SELECT n.nid AS entity_id, n.type AS bundle, n.status AS status, 'node' AS entity_type, %d AS changed\n        FROM {node} n WHERE status = 1)";
      db_query($query, APACHESOLR_REQUEST_TIME);
    }
  } catch (Exception $e) {
    throw $e;
  }
}