You are here

function apachesolr_index_delete_bundles in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 apachesolr.index.inc \apachesolr_index_delete_bundles()
  2. 7 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 612
Functions related to Apache Solr indexing operations.

Code

function apachesolr_index_delete_bundles($env_id, $entity_type, array $excluded_bundles) {

  // 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.
      watchdog('Apache Solr', 'Deleted documents from index with query @query', array(
        '@query' => $query,
      ), WATCHDOG_INFO);
    }
    if ($excluded_bundles) {
      $solr
        ->commit();
    }
    return TRUE;
  } catch (Exception $e) {
    watchdog('Apache Solr', nl2br(check_plain($e
      ->getMessage())), NULL, WATCHDOG_ERROR);
    return FALSE;
  }
}