? access.patch
Index: apachesolr_nodeaccess.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module,v
retrieving revision 1.1.2.11.2.2
diff -u -p -r1.1.2.11.2.2 apachesolr_nodeaccess.module
--- apachesolr_nodeaccess.module	17 Sep 2009 17:14:06 -0000	1.1.2.11.2.2
+++ apachesolr_nodeaccess.module	18 Dec 2009 16:06:59 -0000
@@ -2,82 +2,50 @@
 // $Id: apachesolr_nodeaccess.module,v 1.1.2.11.2.2 2009/09/17 17:14:06 robertDouglass Exp $
 
 /**
- * Implementation of apachesolr_update_index
+ * Implementation of apachesolr_update_index.
+ * 
+ * The node_access table read grants are indexed along with each document.
  */
 function apachesolr_nodeaccess_apachesolr_update_index(&$document, $node) {
-  static $account;
-
-  if (!isset($account)) {
-    // Load the anonymous user.
-    $account = drupal_anonymous_user();
-  }
-
-  if (!node_access('view', $node, $account)) {
-    // 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)) {
-      $key = 'nodeaccess_' . apachesolr_site_hash() . '_' . $grant->realm;
-      $document->setMultiValue($key, $grant->gid);
-    }
-  }
-  else {
-    // Add the generic view grant if we are not using
-    // node access or the node is viewable by anonymous users.
-    $document->setMultiValue('nodeaccess_all', 0);
+  // Get node access grants.
+  $result = db_query('SELECT * FROM {node_access} WHERE (nid = 0 OR nid = %d) AND grant_view = 1', $node->nid);
+  $hash = apachesolr_site_hash();
+  while ($grant = db_fetch_object($result)) {
+    $key = 'nodeaccess_' . $hash . '_' . $grant->realm;
+    $document->setMultiValue($key, $grant->gid);
   }
 }
 
 /**
- * Creates a Solr query for a given user
- *
- * @param $account an account to get grants for and build a solr query
- */
-function apachesolr_nodeaccess_build_subquery($account) {
-  if (!user_access('access content', $account)) {
-    throw new Exception('No access');
-  }
-  $node_access_query = apachesolr_drupal_query();
-  if (empty($node_access_query)) {
-    throw new Exception('No query object in apachesolr_nodeaccess');
-  }
-  if (user_access('administer nodes', $account)) {
-    // Access all content from the current site, or public content.
-    $node_access_query->add_filter('nodeaccess_all', 0);
-    $node_access_query->add_filter('hash', apachesolr_site_hash());
-  }
-  else {
-    // Get node access grants.
-    $grants = node_access_grants('view', $account);
-    foreach ($grants as $realm => $gids) {
-      foreach ($gids as $gid) {
-        $node_access_query->add_filter('nodeaccess_' . apachesolr_site_hash() . '_' . $realm, $gid);
-      }
-    }
-    $node_access_query->add_filter('nodeaccess_all', 0);
-  }
-  return $node_access_query;
-}
-
-/**
  * Implementation of hook_apachesolr_modify_query().
+ * 
+ * Add the 'view' grants for the current user
  */
 function apachesolr_nodeaccess_apachesolr_modify_query(&$query, &$params, $caller = 'apachesolr_search') {
   if ($caller == 'apachesolr_views_query') {
     return;
   }
-  global $user;
-  try {
-    $subquery = apachesolr_nodeaccess_build_subquery($user);
+  if (user_access('administer nodes')) {
+    return;
   }
-  catch (Exception $e) {
+  // If the user can't access content then we destroy the query.
+  if (!user_access('access content')) {
     $query = NULL;
-    watchdog("apachesolr_nodeaccess", 'User %name (UID:!uid) cannot search: @message', array('%name' => $user->name, '!uid' => $user->uid, '@message' => $e->getMessage()));
     return;
   }
-
-  if (!empty($subquery)) {
-    $query->add_subquery($subquery, 'OR');
+  global $user;
+ 
+  $subquery = apachesolr_drupal_query();
+  $hash = apachesolr_site_hash();
+
+  // Get node access grants for the current user.
+  $grants = node_access_grants('view', $user);
+  foreach ($grants as $realm => $gids) {
+    foreach ($gids as $gid) {
+      $subquery->add_filter('nodeaccess_' . $hash . '_' . $realm, $gid);
+    }
   }
+  $query->add_subquery($subquery);
 }
 
 /**
