? 2009-04-16-result.csv
? Cache-query-results.diff
? SolrPhpClient
? Zend
? apachesolr_search.css
? apachesolr_search.substitute.inc
? foo.diff
? mass-delete-561082-3.patch
? schema-cvs.xml
? stats.jsp
? stats.xml
? x.php
? y.php
? tests/404.data.txt
? tests/404.headers.txt
? tests/Mock_Apache_Solr_Service.php
? tests/delete.data.txt
? tests/delete.headers.txt
? tests/luke.data.txt
? tests/luke.headers.txt
? tests/search.data.txt
? tests/search.headers.txt
? tests/stats.data.txt
? tests/stats.headers.txt
? tests/update.data.txt
? tests/update.headers.txt
Index: apachesolr.index.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.index.inc,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 apachesolr.index.inc
--- apachesolr.index.inc	8 Oct 2009 11:53:57 -0000	1.1.2.10
+++ apachesolr.index.inc	13 Oct 2009 02:21:39 -0000
@@ -242,3 +242,88 @@ function apachesolr_add_tags_to_document
   }
 }
 
+/**
+ * Additional index utility functions
+ */
+
+function _apachesolr_cron_check_table() {
+  // Check for unpublished content that wasn't deleted from the index.
+  $result = db_query("SELECT n.nid, n.status FROM {apachesolr_search_node} asn INNER JOIN {node} n ON n.nid = asn.nid WHERE asn.status != n.status");
+  $node_lists = array();
+  // Update or delete at most this many in each Solr query.
+  $limit = variable_get('apachesolr_cron_mass_limit', 500);
+  while ($node = db_fetch_object($result)) {
+    $nodes[] = $node;
+    if (count($nodes) == $limit) {
+      $node_lists[] = $nodes;
+      $nodes = array();
+    }
+  }
+  foreach ($node_lists as $nodes) {
+    _apachesolr_nodeapi_mass_update($nodes);
+  }
+  // Check for deleted content that wasn't deleted from the index.
+  $result = db_query("SELECT asn.nid FROM {apachesolr_search_node} asn LEFT JOIN {node} n ON n.nid = asn.nid WHERE n.nid IS NULL");
+  $node_lists = array();
+  while ($node = db_fetch_object($result)) {
+    $nodes[] = $node;
+    if (count($nodes) == $limit) {
+      $node_lists[] = $nodes;
+      $nodes = array();
+    }
+  }
+  foreach ($node_lists as $nodes) {
+    _apachesolr_nodeapi_mass_delete($nodes);
+  }
+}
+
+function _apachesolr_nodeapi_mass_update($nodes) {
+  if (empty($nodes)) {
+    return TRUE;
+  }
+  $ids = array();
+  foreach ($nodes as $node) {
+    if (!$node->status) {
+      $ids[] = 'id:' . apachesolr_document_id($node->nid);
+    }
+  }
+  $time = time();
+  try {
+    $solr = apachesolr_get_solr();
+    $solr->deleteByQuery(implode(' ', $ids));
+    apachesolr_index_updated($time);
+    foreach ($nodes as $node) {
+      // There was no exception, so update the table.
+      db_query("UPDATE {apachesolr_search_node} SET changed = %d, status = %d WHERE nid  = %d", $time, $node->status, $node->nid);
+    }
+    return TRUE;
+  }
+  catch (Exception $e) {
+    watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
+    return FALSE;
+  }
+}
+
+function _apachesolr_nodeapi_mass_delete($nodes) {
+  if (empty($nodes)) {
+    return TRUE;
+  }
+  $ids = array();
+  $nids = array();
+  foreach ($nodes as $node) {
+    $ids[] = 'id:' . apachesolr_document_id($node->nid);
+    $nids[] = $node->nid;
+  }
+  try {
+    $solr = apachesolr_get_solr();
+    $solr->deleteByQuery(implode(' ', $ids));
+    apachesolr_index_updated($time);
+    // There was no exception, so update the table.
+    db_query("DELETE FROM {apachesolr_search_node} WHERE nid  IN (" . db_placeholders($nids) . ")", $nids);
+    return TRUE;
+  }
+  catch (Exception $e) {
+    watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
+    return FALSE;
+  }
+}
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.164
diff -u -p -r1.1.2.12.2.164 apachesolr.module
--- apachesolr.module	8 Oct 2009 18:51:37 -0000	1.1.2.12.2.164
+++ apachesolr.module	13 Oct 2009 02:21:43 -0000
@@ -339,7 +339,7 @@ function apachesolr_index_nodes($rows, $
     watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
     return FALSE;
   }
-  include_once(drupal_get_path('module', 'apachesolr') .'/apachesolr.index.inc') ;
+  include_once(drupal_get_path('module', 'apachesolr') .'/apachesolr.index.inc');
   $documents = array();
   $old_position = apachesolr_get_last_index($namespace);
   $position = $old_position;
@@ -394,6 +394,10 @@ function apachesolr_date_iso($date_times
 }
 
 function apachesolr_delete_node_from_index($node) {
+  static $failed = FALSE;
+  if ($failed) {
+    return FALSE;
+  }
   try {
     $solr = apachesolr_get_solr();
     $solr->deleteById(apachesolr_document_id($node->nid));
@@ -402,6 +406,8 @@ function apachesolr_delete_node_from_ind
   }
   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;
   }
 }
@@ -425,21 +431,11 @@ function apachesolr_index_updated($updat
  * Implementation of hook_cron().
  */
 function apachesolr_cron() {
+  // Mass update and delete functions are in the include file.
+  include_once(drupal_get_path('module', 'apachesolr') .'/apachesolr.index.inc');
+  _apachesolr_cron_check_table();
   try {
     $solr = apachesolr_get_solr();
-
-    // Check for unpublished content that wasn't deleted from the index.
-    $result = db_query("SELECT n.nid, n.status FROM {apachesolr_search_node} asn INNER JOIN {node} n ON n.nid = asn.nid WHERE asn.status != n.status");
-    while ($node = db_fetch_object($result)) {
-      _apachesolr_nodeapi_update($node, FALSE);
-    }
-
-    // Check for deleted content that wasn't deleted from the index.
-    $result = db_query("SELECT asn.nid FROM {apachesolr_search_node} asn LEFT JOIN {node} n ON n.nid = asn.nid WHERE n.nid IS NULL");
-    while ($node = db_fetch_object($result)) {
-      _apachesolr_nodeapi_delete($node, FALSE);
-    }
-
     // Optimize the index (by default once a day).
     $optimize_interval = variable_get('apachesolr_optimize_interval', 60 * 60 * 24);
     $last = variable_get('apachesolr_last_optimize', 0);
