You are here

function apachesolr_attachments_remove_attachments_from_index in Apache Solr Attachments 7

Same name and namespace in other branches
  1. 6.3 apachesolr_attachments.module \apachesolr_attachments_remove_attachments_from_index()
  2. 6 apachesolr_attachments.module \apachesolr_attachments_remove_attachments_from_index()
  3. 6.2 apachesolr_attachments.module \apachesolr_attachments_remove_attachments_from_index()

For a particular entity, remove all file attachments from the Solr index. This function is not in use in the module but can come in handy for people that prefer to use functions

See also

apachesolr_delete_node_from_index()

File

./apachesolr_attachments.module, line 496
Provides a file attachment search implementation for use with the Apache Solr module

Code

function apachesolr_attachments_remove_attachments_from_index($parent_entity_type, $parent_entity) {
  static $failed = FALSE;
  if ($failed) {
    return FALSE;
  }
  try {

    // Retrieve the parent entity id and bundle
    list($parent_entity_id, $parent_entity_vid, $parent_entity_bundle) = entity_extract_ids($parent_entity_type, $parent_entity);
    $solr = apachesolr_get_solr();
    $solr
      ->deleteByQuery("sm_parent_entity:{$parent_entity_type}-{$parent_entity_bundle}-{$parent_entity_id} AND entity_type:file AND hash:" . apachesolr_site_hash());
    return TRUE;
  } catch (Exception $e) {
    watchdog('Apache Solr Attachments', nl2br(check_plain($e
      ->getMessage())), NULL, WATCHDOG_ERROR);

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