Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.1074
diff -u -p -r1.1074 node.module
--- modules/node/node.module	27 Jun 2009 10:13:28 -0000	1.1074
+++ modules/node/node.module	27 Jun 2009 20:32:34 -0000
@@ -2027,7 +2027,7 @@ function node_update_index() {
   $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit);
 
   foreach ($result as $node) {
-    _node_index_node($node);
+    node_index_node($node);
   }
 }
 
@@ -2037,7 +2037,7 @@ function node_update_index() {
  * @param $node
  *   The node to index.
  */
-function _node_index_node($node) {
+function node_index_node($node) {
   $node = node_load($node->nid);
 
   // Save the changed time of the most recent indexed node, for the search
Index: modules/search/search.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/search/search.admin.inc,v
retrieving revision 1.8
diff -u -p -r1.8 search.admin.inc
--- modules/search/search.admin.inc	11 Jan 2009 21:19:18 -0000	1.8
+++ modules/search/search.admin.inc	27 Jun 2009 20:32:34 -0000
@@ -69,6 +69,12 @@ function search_admin_settings() {
     '#type' => 'fieldset',
     '#title' => t('Indexing settings')
   );
+  $form['indexing_settings']['search_index_content_insert'] = array(
+    '#title' => t('Index content when created'),
+    '#type' => 'checkbox',
+    '#default_value' => variable_get('search_index_content_insert', TRUE),
+    '#description' => t('Search module will index content as soon as it is created instead of waiting for a cron run. Not recommended for high traffic sites.'),
+  );
   $form['indexing_settings']['info'] = array(
     '#markup' => t('<p><em>Changing the settings below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.</em></p><p><em>The default settings should be appropriate for the majority of sites.</em></p>')
   );
Index: modules/search/search.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/search/search.module,v
retrieving revision 1.298
diff -u -p -r1.298 search.module
--- modules/search/search.module	3 Jun 2009 06:52:29 -0000	1.298
+++ modules/search/search.module	27 Jun 2009 20:32:35 -0000
@@ -512,11 +512,9 @@ function search_index($sid, $type, $text
               $linknid = $match[1];
               if ($linknid > 0) {
                 // Note: ignore links to uncacheable nodes to avoid redirect bugs.
-                $node = db_fetch_object(db_query('SELECT n.title, n.nid, n.vid, r.format FROM {node} n INNER JOIN {node_revision} r ON n.vid = r.vid WHERE n.nid = %d', $linknid));
-                if (filter_format_allowcache($node->format)) {
-                  $link = TRUE;
-                  $linktitle = $node->title;
-                }
+                $node = db_query('SELECT n.title, n.nid, n.vid FROM {node} n WHERE n.nid = %d', $linknid)->fetchObject();
+                $link = TRUE;
+                $linktitle = $node->title;
               }
             }
           }
@@ -655,6 +653,20 @@ function search_node_update_index($node)
 }
 
 /**
+ * Implement hook_node_insert().
+ */
+function search_node_insert($node) {
+  // Index nodes when first created so that the immediately show up in search
+  // results.
+  if (variable_get('search_index_content_insert', TRUE)) {
+    // Register a shutdown function for the search index update to ensure
+    // the node is added to the index. @see search_cron().
+    register_shutdown_function('node_index_node', $node);
+    register_shutdown_function('search_update_totals');;
+  }
+}
+
+/**
  * Implement hook_node_update().
  */
 function search_node_update($node) {
@@ -667,8 +679,19 @@ function search_node_update($node) {
  * Implement hook_comment_insert().
  */
 function search_comment_insert($form_values) {
-  // Reindex the node when comments are added.
-  search_touch_node($form_values['nid']);
+  // Re-index the node when comments are added.
+  if (variable_get('search_index_content_insert', TRUE)) {
+    // Add the comment to the search index immediately. Register a shutdown
+    // function for the search index update to ensure the comment is added to
+    // the index. @see search_cron().
+    $node = node_load($form_values['nid']);
+    register_shutdown_function('node_index_node', $node);
+    register_shutdown_function('search_update_totals');
+  }
+  else {
+    // Mark the node for re-indexing.
+    search_touch_node($form_values['nid']);
+  }
 }
 
 /**
