You are here

function apachesolr_index_delete_index in Apache Solr Search 8

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

Delete the whole index for an environment.

Parameters

string $env_id: The machine name of the environment.

string $entity_type: (optional) specify to remove just this entity_type from the index.

string $bundle: (optional) also specify a bundle to remove just the bundle from the index.

2 calls to apachesolr_index_delete_index()
apachesolr_drush_solr_delete_index in drush/apachesolr.drush.inc
Selectively delete content from the apachesolr index.
apachesolr_index_action_form_delete_confirm_submit in ./apachesolr.admin.inc
Submit handler for the deletion form.

File

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

Code

function apachesolr_index_delete_index($env_id, $entity_type = NULL, $bundle = NULL) {

  // Instantiate a new Solr object.
  try {
    $solr = apachesolr_get_solr($env_id);
    $query = '*:*';
    if (!empty($entity_type) && !empty($bundle)) {
      $query = "(bundle:{$bundle} AND entity_type:{$entity_type}) OR sm_parent_entity_bundle:{$entity_type}-{$bundle}";
    }
    elseif (!empty($bundle)) {
      $query = "(bundle:{$bundle})";
    }

    // Allow other modules to modify the delete query.
    // For example, use the site hash so that you only delete this site's
    // content:  $query = 'hash:' . apachesolr_site_hash()
    drupal_alter('apachesolr_delete_by_query', $query);
    $solr
      ->deleteByQuery($query);
    $solr
      ->commit();

    // Log the query used for deletion.
    watchdog('Apache Solr', 'Deleted documents from index with query @query', array(
      '@query' => $query,
    ), WATCHDOG_INFO);
    if (!empty($entity_type)) {
      $rebuild_callback = apachesolr_entity_get_callback($entity_type, 'reindex callback');
      if (is_callable($rebuild_callback)) {
        $rebuild_callback($env_id, $bundle);
      }
    }
    else {
      apachesolr_index_mark_for_reindex($env_id);
    }
    apachesolr_set_last_index_updated($env_id, REQUEST_TIME);
  } catch (Exception $e) {
    watchdog('Apache Solr', nl2br(check_plain($e
      ->getMessage())), NULL, WATCHDOG_ERROR);
  }
}