Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.845
diff -u -p -r1.845 comment.module
--- modules/comment/comment.module	17 Feb 2010 05:31:31 -0000	1.845
+++ modules/comment/comment.module	21 Feb 2010 07:11:36 -0000
@@ -1255,14 +1255,20 @@ function comment_node_delete($node) {
  * Implements hook_node_update_index().
  */
 function comment_node_update_index($node) {
-  $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
-  $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
-  if ($node->comment && $cids = comment_get_thread($node, $mode, $comments_per_page)) {
-    $comments = comment_load_multiple($cids);
-    comment_prepare_thread($comments);
-    $build = comment_view_multiple($comments, $node);
+  // Only add comments to the search index if anonymous users have permission
+  // to access comments.
+  $permissions = user_role_permission(DRUPAL_ANONYMOUS_RID);
+  if (in_array('access comments', $permissions)) {
+    $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
+    $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
+    if ($node->comment && $cids = comment_get_thread($node, $mode, $comments_per_page)) {
+      $comments = comment_load_multiple($cids);
+      comment_prepare_thread($comments);
+      $build = comment_view_multiple($comments, $node);
+    }
+    return drupal_render($build);
   }
-  return drupal_render($build);
+  return '';
 }
 
 /**
@@ -1277,9 +1283,12 @@ function comment_update_index() {
  * Implements hook_node_search_result().
  */
 function comment_node_search_result($node) {
-  if ($node->comment != COMMENT_NODE_HIDDEN) {
-    $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField();
-    return format_plural($comments, '1 comment', '@count comments');
+  $oermissions = user_role_permission(DRUPAL_ANONYMOUS_RID);
+  if (in_array('access comments', $permissions)) {
+    if ($node->comment != COMMENT_NODE_HIDDEN) {
+      $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField();
+      return format_plural($comments, '1 comment', '@count comments');
+    }
   }
   return '';
 }
