You are here

function apachesolr_index_delete_entity_from_index in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 apachesolr.index.inc \apachesolr_index_delete_entity_from_index()
  2. 7 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

File

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

Code

function apachesolr_index_delete_entity_from_index($env_id, $entity_type, $entity_id) {
  static $failed = FALSE;
  if ($failed) {
    return FALSE;
  }
  if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) {
    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.
    watchdog('Apache Solr', 'Deleted documents from index with query @query', array(
      '@query' => $query,
    ), WATCHDOG_INFO);
    apachesolr_set_last_index_updated($env_id, REQUEST_TIME);
    return TRUE;
  } catch (Exception $e) {
    watchdog('Apache Solr', nl2br(check_plain($e
      ->getMessage())), NULL, WATCHDOG_ERROR);

    // Don't keep trying queries if they are failing.
    $failed = TRUE;
    return FALSE;
  }
}