Index: contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module,v
retrieving revision 1.1.2.11.4.1
diff -u -p -r1.1.2.11.4.1 apachesolr_nodeaccess.module
--- contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module	22 Sep 2009 15:26:16 -0000	1.1.2.11.4.1
+++ contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module	26 Oct 2009 15:08:28 -0000
@@ -5,14 +5,18 @@
  * Implementation of apachesolr_update_index
  */
 function apachesolr_nodeaccess_apachesolr_update_index(&$document, $node) {
-  static $account;
-
-  if (!isset($account)) {
-    // Load the anonymous user.
-    $account = drupal_anonymous_user();
+  global $user;
+  
+  // We have to run as anonymous while node_access() doesn't take the $user as
+  // argument but we want to check the access as anonymous. We are using
+  // http://drupal.org/node/218104 as a trick to safe switch to anonymous.
+  if ($user->uid) {
+    $original_user = $user;
+    session_save_session(FALSE);
+    $user = drupal_anonymous_user();
   }
-
-  if (!node_access('view', $node, $account)) {
+  
+  if (!node_access('view', $node)) {
     // Get node access grants.
     $result = db_query('SELECT * FROM {node_access} WHERE (nid = 0 OR nid = %d) AND grant_view = 1', $node->nid);
     while ($grant = db_fetch_object($result)) {
@@ -25,6 +29,12 @@ function apachesolr_nodeaccess_apachesol
     // node access or the node is viewable by anonymous users.
     $document->setMultiValue('nodeaccess_all', 0);
   }
+
+  // Switch back the original user
+  if ($original_user->uid) {
+    $user = $original_user;
+    session_save_session(TRUE);
+  }
 }
 
 /**
@@ -47,7 +57,7 @@ function _apachesolr_nodeaccess_build_su
   }
   else {
     // Get node access grants.
-    $grants = node_access_grants('view', $account);
+    $grants = node_access_grants('view', $account->uid);
     foreach ($grants as $realm => $gids) {
       foreach ($gids as $gid) {
         $node_access_query->add_filter('nodeaccess_' . apachesolr_site_hash() . '_' . $realm, $gid);
