The apachesolr module's drush command for deleting entities from the index is buggy.
Its documentation states the following commands are valid:
'drush solr-delete-index node' => 'Delete all node content from the index.',
'drush solr-delete-index node:article' => 'Delete all content of the article content type from the index.',
'drush solr-delete-index node:article node:blog' => 'Delete all content of the article and blog content types from the index.',
When the drush command is called with the syntax of the first example it calls
$success = apachesolr_index_delete_index($env_id, $type);
which calls
function apachesolr_index_delete_index($env_id, $entity_type = NULL, $bundle = NULL) {
if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) {
watchdog('Apache Solr', 'Trying to update the Solr index while the environment %env_id is read-only in function %function', array('%function' => __FUNCTION__, '%env_id' => $env_id), WATCHDOG_WARNING);
return FALSE;
}
// Instantiate a new Solr object.
try {
$solr = apachesolr_get_solr($env_id);
$query = '*:*';
if (!empty($entity_type) && !empty($bundle)) {
$query = "(bundle:$bundle AND entity_type:$entity_type) OR sm_parent_entity_bundle:{$entity_type}-{$bundle}";
}
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();
<SNIP>
The query isn't altered if only 'entity_type' is provided, causing the whole index to drop.
Comment | File | Size | Author |
---|---|---|---|
#2 | delete-by-entity-type-2635244-1.patch | 1.18 KB | Jon Nunan |
|
Comments
Comment #2
Jon Nunan CreditAttribution: Jon Nunan at Flight Centre Travel Group commentedJust adding another condition should do it.
Comment #3
Jon Nunan CreditAttribution: Jon Nunan at Flight Centre Travel Group commentedComment #5
Jon Nunan CreditAttribution: Jon Nunan at Flight Centre Travel Group commentedComment #7
janusman CreditAttribution: janusman at Acquia commentedFixed!