You are here

function apachesolr_index_delete_bundles in Apache Solr Search 7

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

Delete from the index documents with the entity type and any of the excluded bundles.

Also deletes all documents that have the entity type and bundle as a parent.

Parameters

string $env_id: The machine name of the environment.

string $entity_type:

array $excluded_bundles:

Return value

true on success, false on failure.

2 calls to apachesolr_index_delete_bundles()
apachesolr_index_config_form_submit in ./apachesolr.admin.inc
Submit handler for the bundle configuration form.
apachesolr_node_type_delete in ./apachesolr.module
Implements hook_node_type_delete().

File

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

Code

function apachesolr_index_delete_bundles($env_id, $entity_type, array $excluded_bundles) {
  if (apachesolr_index_env_is_readonly($env_id)) {
    apachesolr_index_report_readonly($env_id);
    return FALSE;
  }

  // Remove newly omitted bundles.
  try {
    $solr = apachesolr_get_solr($env_id);
    foreach ($excluded_bundles as $bundle) {
      $query = "(bundle:{$bundle} AND entity_type:{$entity_type}) OR sm_parent_entity_bundle:{$entity_type}-{$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);

      // Log the query used for deletion.
      $log_success = variable_get('apachesolr_watchdog_successes', TRUE);
      if ($log_success) {
        watchdog('Apache Solr', 'Environment @env_id: Deleted documents from index with query @query', array(
          '@env_id' => $env_id,
          '@query' => $query,
        ), WATCHDOG_INFO);
      }
    }
    if ($excluded_bundles) {
      $solr
        ->commit();
    }
    return TRUE;
  } catch (Exception $e) {
    apachesolr_log_exception($env_id, $e);
    return FALSE;
  }
}