function apachesolr_index_delete_index in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr.index.inc \apachesolr_index_delete_index()
- 6.3 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.
Return value
bool TRUE for success, FALSE if an error occured.
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 547 - Functions related to Apache Solr indexing operations.
Code
function apachesolr_index_delete_index($env_id, $entity_type = NULL, $bundle = NULL) {
if (apachesolr_index_env_is_readonly($env_id)) {
apachesolr_index_report_readonly($env_id);
return FALSE;
}
// Instantiate a new Solr object.
try {
$solr = apachesolr_get_solr($env_id);
$query = '*:*';
if (!empty($entity_type)) {
if (!empty($bundle)) {
$query = "(bundle:{$bundle} AND entity_type:{$entity_type}) OR sm_parent_entity_bundle:{$entity_type}-{$bundle}";
}
else {
$query = "(entity_type:{$entity_type})";
}
}
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.
$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 (!empty($entity_type)) {
$reindex_callback = apachesolr_entity_get_callback($entity_type, 'reindex callback');
if (is_callable($reindex_callback)) {
$reindex_callback($env_id, $bundle, $entity_type);
}
}
else {
apachesolr_index_mark_for_reindex($env_id);
}
apachesolr_set_last_index_updated($env_id, REQUEST_TIME);
} catch (Exception $e) {
apachesolr_log_exception($env_id, $e);
return FALSE;
}
return TRUE;
}