1

The scenario is to delete bulk documents from apache solr, without deleting the actual node from the database. I am aware that when the node is un-published it will be deleted from solr.

But as my node are very large containing 1000's of terms I don not want to use node-save to un-publish the node.

Is there any hook or function which un-publishes the node and deletes from solr by minimal load (definitely not node save) ?

UPDATE:

  • Drupal Version : 7.15
  • Modules: Apachesolr
1

I found the answer on exploring the apache solr module,

STEP 1

Select the nodes from the node table alone or by joining the apachesolr index entities table,

// Check for unpublished content that wasn't deleted from the index.
  $table = apachesolr_get_indexer_table('node');

 // Select the nids from the node table 
  $query = db_select($table, 'aien')
    ->fields('aien', array('entity_id'))
    ->condition('n.nid', 0);
  $query->leftJoin('node', 'n', 'n.nid = aien.entity_id');
  $nodes = $query->execute()->fetchAllAssoc('nid');

STEP 2

Chunk it to some limit and call the apachesolr_index_nodeapi_mass_delete function

      $node_lists = array_chunk($nodes, '100', TRUE);
  foreach ($node_lists as $nodes) {
    watchdog('Apache Solr', 'On cron running apachesolr_nodeapi_mass_delete() on nids @nids', array('@nids' => implode(',', array_keys($nodes))), WATCHDOG_WARNING);
    if (!apachesolr_index_nodeapi_mass_delete($nodes, $table)) {
      // Solr query failed - so stop trying.
      break;
    }
  }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.