? .svn
? SolrPhpClient
? contrib/.svn
? contrib/apachesolr_image/.svn
? contrib/apachesolr_nodeaccess/.svn
? contrib/apachesolr_nodeaccess/tests/.svn
? contrib/apachesolr_og/.svn
? tests/.svn
Index: apachesolr.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.admin.inc,v
retrieving revision 1.1.2.28.2.5
diff -w -u -p -r1.1.2.28.2.5 apachesolr.admin.inc
--- apachesolr.admin.inc	13 Aug 2009 11:09:59 -0000	1.1.2.28.2.5
+++ apachesolr.admin.inc	13 Aug 2009 13:21:32 -0000
@@ -304,6 +304,11 @@ function apachesolr_delete_index_form() 
     '#value' => t('Index controls'),
     '#suffix' => '</h3>',
   );
+  $form['batch'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Reindex immediately'),
+    '#description' => t('If checked, the index will be rebuilt immediately in this browser session using the batch API. Depending on the size of your index it may take a while. Leave unchecked to reindex on cron runs.'),
+  );
   $form['reindex'] = array(
     '#type' => 'submit',
     '#value' => t('Re-index all content'),
@@ -341,8 +346,13 @@ function apachesolr_clear_index($form, &
  *
  */
 function apachesolr_clear_index_submit($form, &$form_state) {
+  if ($form_state['values']['batch']) {
+    $form_state['redirect'] = 'admin/settings/apachesolr/index/batch/confirm';
+  }
+  else {
   $form_state['redirect'] = 'admin/settings/apachesolr/index/clear/confirm';
 }
+}
 
 /**
  * Confirmation form for "Re-index all content" button
@@ -365,6 +375,25 @@ function apachesolr_clear_index_confirm_
 
 
 /**
+ * Confirmation form for "Batch re-index all content" button
+ * @see apachesolr_batch_index_confirm_submit()
+ */
+function apachesolr_batch_index_confirm() {
+  $form = array();
+  return confirm_form($form, t('Are you sure you want to batch re-index? This may take some time.'), 'admin/settings/apachesolr/index', NULL, t('Batch re-index'), t('Cancel'));
+}
+
+/**
+ * Submit function for the "Batch re-index all content" confirmation form.
+ *
+ * @see apachesolr_clear_index_confirm()
+ */
+function apachesolr_batch_index_confirm_submit($form, &$form_state) {
+  $form_state['redirect'] = 'admin/settings/apachesolr/index';
+  apachesolr_batch_reindex();
+}
+
+/**
  * Submit function for the "Delete the index" button
  * @see apachesolr_delete_index_form()
  *
@@ -656,3 +685,90 @@ function apachesolr_mlt_delete_block_for
   $form_state['redirect'] = 'admin/build/block';
 }
 
+/**
+ * Batch reindex functions.
+ */
+
+/**
+* Control a batch reindex operation using the batch API.
+*/
+function apachesolr_batch_reindex() {
+  $batch = array(
+    'operations' => array(
+      array('apachesolr_batch_reindex_process', array()),
+    ),
+    'finished' => 'apachesolr_batch_reindex_finished',
+    'title' => t('Reindexing'),
+    'init_message' => t('Batch reindexing is starting.'),
+    //'progress_message' => t('Reindexed @current out of @total.'),
+    'error_message' => t('Batch reindexing has encountered an error.'),
+  );
+  batch_set($batch);
+}
+
+/**
+* Batch Operation Callback
+*/
+function apachesolr_batch_reindex_process(&$context) {
+  if (empty($context['sandbox'])) {
+    try {
+      // Get the $solr object
+      $solr = apachesolr_get_solr();
+      // If there is no server available, don't continue.
+      if (!$solr->ping()) {
+        throw new Exception(t('No Solr instance available during indexing.'));
+      }
+    }
+    catch (Exception $e) {
+      watchdog('Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR);
+      return FALSE;
+    }
+
+    $context['sandbox']['progress'] = 0;
+    $context['sandbox']['current_node'] = 0;
+    apachesolr_rebuild_index_table();
+  }
+  // We can safely process the apachesolr_cron_limit nodes at a time without a timeout.
+  $limit = variable_get('apachesolr_cron_limit', 50);
+
+  // Pull the total and remaining variables using apachesolr_search status function.
+  // This is used to push the progress bar for each group of nodes being indexed.
+  // Must set progress before calling the apachesolr_index_nodes() function to properly increment
+  // the progress else progress and total will never equal.
+  $status = module_invoke('apachesolr_search', 'search', 'status');
+  $remaining = $status['remaining'];
+  $total = $status['total'];
+  $nodes_indexed = db_result(db_query('SELECT COUNT(nid) FROM {apachesolr_search_node}'));
+  $context['sandbox']['progress'] += min($limit, $remaining);
+  $number_indexed = min($limit, $remaining);
+  $context['message'] = t('Reindexing @current of @total.', array('@current' => $context['sandbox']['progress'], '@total' => $total));
+  $context['sandbox']['max'] = $total;
+
+  // With each pass through the callback, retrieve the next group of nids.
+  $result = apachesolr_get_nodes_to_index('apachesolr_search', $limit);
+  apachesolr_index_nodes($result, 'apachesolr_search');
+
+  // Inform the batch engine that we are not finished,
+  // and provide an estimation of the completion level we reached.
+  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
+    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
+  }
+}
+
+/**
+* Batch 'finished' callback
+*/
+function apachesolr_batch_reindex_finished($success, $results, $operations) {
+  if ($success) {
+    // Here we do something meaningful with the results.
+    $message = format_plural(count($results), '1 item successfully processed.', '@count items successfully processed.');
+    $message .= theme('item_list', $results);
+  }
+  else {
+    // An error occurred.
+    // $operations contains the operations that remained unprocessed.
+    $error_operation = reset($operations);
+    $message = t('An error occurred while processing @num with arguments :', array('@num' => $error_operation[0])) . print_r($error_operation[0], TRUE);
+  }
+  drupal_set_message($message, 'error');
+}
\ No newline at end of file
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.155.2.7
diff -w -u -p -r1.1.2.12.2.155.2.7 apachesolr.module
--- apachesolr.module	13 Aug 2009 11:09:59 -0000	1.1.2.12.2.155.2.7
+++ apachesolr.module	13 Aug 2009 13:21:32 -0000
@@ -52,6 +52,14 @@ function apachesolr_menu() {
     'file'               => 'apachesolr.admin.inc',
     'type'               => MENU_CALLBACK,
   );
+  $items['admin/settings/apachesolr/index/batch/confirm'] = array(
+    'title'              => 'Confirm the batch re-indexing of all content',
+    'page callback'      => 'drupal_get_form',
+    'page arguments'     => array('apachesolr_batch_index_confirm'),
+    'access arguments'   => array('administer search'),
+    'file'               => 'apachesolr.admin.inc',
+    'type'               => MENU_CALLBACK,
+  );
   $items['admin/settings/apachesolr/index/delete/confirm'] = array(
     'title'              => 'Confirm index deletion',
     'page callback'      => 'drupal_get_form',
