function apachesolr_index_delete_entity_from_index in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr.index.inc \apachesolr_index_delete_entity_from_index()
- 6.3 apachesolr.index.inc \apachesolr_index_delete_entity_from_index()
Delete an entity from the index.
Also deletes all documents that have the deleted document as a parent.
Parameters
string $env_id: The machine name of the environment.
string $entity_type:
string $entity_id:
Return value
true on success, false on failure.
1 call to apachesolr_index_delete_entity_from_index()
- apachesolr_remove_entity in ./
apachesolr.module - Remove a specific entity from a given Solr environment.
File
- ./
apachesolr.index.inc, line 709 - Functions related to Apache Solr indexing operations.
Code
function apachesolr_index_delete_entity_from_index($env_id, $entity_type, $entity_id) {
// Keep track of failures per environment.
static $failed = array();
if (!empty($failed[$env_id])) {
return FALSE;
}
if (apachesolr_index_env_is_readonly($env_id)) {
apachesolr_index_report_readonly($env_id);
return FALSE;
}
try {
$solr = apachesolr_get_solr($env_id);
$document_id = apachesolr_document_id($entity_id, $entity_type);
$query = "id:\"{$document_id}\" OR sm_parent_document_id:\"{$document_id}\"";
$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);
}
apachesolr_set_last_index_updated($env_id, REQUEST_TIME);
return TRUE;
} catch (Exception $e) {
apachesolr_log_exception($env_id, $e);
// Don't keep trying queries if they are failing for this environment.
$failed[$env_id] = TRUE;
return FALSE;
}
}