Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.183
diff -u -p -r1.1.2.12.2.183 apachesolr.module
--- apachesolr.module	4 Mar 2010 04:17:20 -0000	1.1.2.12.2.183
+++ apachesolr.module	1 Apr 2010 18:31:13 -0000
@@ -1146,16 +1146,80 @@ function apachesolr_get_solr($host = NUL
 }
 
 /**
+ * Execute a search based on a query object.
+ *
+ * Normally this function is used with the default (dismax) handler for keyword
+ * searches. The $final_query that's returned will have been modified by
+ * both hook_apachesolr_prepare_query() and hook_apachesolr_modify_query().
+ *
+ * @param $caller
+ *   String, name of the calling module or function for use as a cache namespace.
+ * @param $current_query
+ *   A query object from apachesolr_drupal_query().  It will be modified by
+ *   hook_apachesolr_prepare_query() and then cached in apachesolr_current_query().
+ * @param $params
+ *   Array of parameters to pass to Solr.  Must include at least 'rows'.
+ * @param $page
+ *   For paging into results, using $params['rows'] results per page.
+ *
+ * @return array($final_query, $response)
+ *
+ * @throws Exception
+ */
+function apachesolr_do_query($caller, $current_query, $params = array('rows' => 10), $page = 0) {
+  // Allow modules to alter the query prior to statically caching it.
+  // This can e.g. be used to add available sorts.
+  foreach (module_implements('apachesolr_prepare_query') as $module) {
+    $function_name = $module . '_apachesolr_prepare_query';
+    $function_name($current_query, $params, $caller);
+  }
+
+  // Cache the original query. Since all the built queries go through
+  // this process, all the hook_invocations will happen later
+  $query = apachesolr_current_query($current_query, $caller);
+
+  // This hook allows modules to modify the query and params objects.
+  apachesolr_modify_query($query, $params, $caller);
+  $params['start'] = $page * $params['rows'];
+
+  if (!$query) {
+    return array(NULL, array());
+  }
+
+  $keys = $query->get_query_basic();
+  if (('' == $keys) && isset($params['fq'])) {
+    // Move the fq params to the q.alt for better performance.
+    $params['q.alt'] = implode(' ', $params['fq']);
+    unset($params['fq']);
+  }
+  // This is the object that does the communication with the solr server.
+  $solr = apachesolr_get_solr();
+  // We must run htmlspecialchars() here since converted entities are in the index.
+  // and thus bare entities &, > or < won't match.
+  $response = $solr->search(htmlspecialchars($keys, ENT_NOQUOTES, 'UTF-8'), $params['start'], $params['rows'], $params);
+  // The response is cached so that it is accessible to the blocks and anything
+  // else that needs it beyond the initial search.
+  apachesolr_static_response_cache($response, $caller);
+  return array($query, $response);
+}
+
+
+/**
  * It is important to hold on to the Solr response object for the duration of the
  * page request so that we can use it for things like building facet blocks.
+ *
+ * @todo reverse the order of parameters in future branches.
  */
-function apachesolr_static_response_cache($response = NULL) {
-  static $_response;
+function apachesolr_static_response_cache($response = NULL, $namespace = 'apachesolr_search') {
+  static $_response = array();
 
-  if (!empty($response)) {
-    $_response = clone $response;
+  if (is_object($response)) {
+    $_response[$namespace] = clone $response;
   }
-  return $_response;
+  if (!isset($_response[$namespace])) {
+    $_response[$namespace] = NULL;
+  }
+  return $_response[$namespace];
 }
 
 /**
@@ -1191,14 +1255,17 @@ function apachesolr_drupal_query($keys =
 
 /**
  * Static getter/setter for the current query
+ *
+ * @todo reverse the order of parameters in future branches.
  */
-function apachesolr_current_query($query = NULL) {
-  static $saved_query = NULL;
+function apachesolr_current_query($query = NULL, $namespace = 'apachesolr_search') {
+  static $saved_query = array();
+
   if (is_object($query)) {
-    $saved_query = clone $query;
+    $saved_query[$namespace] = clone $query;
   }
 
-  return empty($saved_query) ? $saved_query : clone $saved_query;
+  return is_object($saved_query[$namespace]) ? clone $saved_query[$namespace] : NULL;
 }
 
 /**
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.133
diff -u -p -r1.1.2.6.2.133 apachesolr_search.module
--- apachesolr_search.module	24 Feb 2010 23:00:01 -0000	1.1.2.6.2.133
+++ apachesolr_search.module	1 Apr 2010 18:31:13 -0000
@@ -202,8 +202,6 @@ function apachesolr_search_execute($keys
     throw new Exception(t('Could not construct a Solr query in function apachesolr_search_search()'));
   }
 
-  // This is the object that does the communication with the solr server.
-  $solr = apachesolr_get_solr();
   $params += apachesolr_search_basic_params($query);
   if ($keys) {
     $params += apachesolr_search_highlighting_params($query);
@@ -214,45 +212,15 @@ function apachesolr_search_execute($keys
     $params['fl'] .= ',teaser';
   }
   apachesolr_search_add_facet_params($params, $query);
-  apachesolr_search_add_boost_params($params, $query, $solr);
+  apachesolr_search_add_boost_params($params, $query, apachesolr_get_solr());
 
-  // Allow modules to alter the query prior to statically caching it.
-  // This can e.g. be used to add available sorts.
-  foreach (module_implements('apachesolr_prepare_query') as $module) {
-    $function_name = $module . '_apachesolr_prepare_query';
-    $function_name($query, $params, $caller);
-  }
-
-  // Cache the built query. Since all the built queries go through
-  // this process, all the hook_invocations will happen later
-  $current_query = apachesolr_current_query($query);
-
-  // This hook allows modules to modify the query and params objects.
-  apachesolr_modify_query($query, $params, $caller);
-  $params['start'] = $page * $params['rows'];
-
-  if (!$query) {
-    return array();
-  }
-
-  if (('' == $keys) && isset($params['fq'])) {
-    // Move the fq params to the q.alt for better performance.
-    $params['q.alt'] = implode(' ', $params['fq']);
-    unset($params['fq']);
-  }
-
-  // We must run htmlspecialchars() here since converted entities are in the index.
-  // and thus bare entities &, > or < won't match.
-  $response = $solr->search(htmlspecialchars($query->get_query_basic(), ENT_NOQUOTES, 'UTF-8'), $params['start'], $params['rows'], $params);
-  // The response is cached so that it is accessible to the blocks and anything
-  // else that needs it beyond the initial search.
-  apachesolr_static_response_cache($response);
+  list($final_query, $response) = apachesolr_do_query($caller, $query, $params, $page);
   apachesolr_has_searched(TRUE);
   // Add search terms and filters onto the breadcrumb.
-  // We use $current_query to avoid exposing, for example, nodeaccess
+  // We use the original $query to avoid exposing, for example, nodeaccess
   // filters in the breadcrumb.
-  drupal_set_breadcrumb(array_merge(menu_get_active_breadcrumb(), $current_query->get_breadcrumb()));
-  return apachesolr_process_response($response, $query, $params);
+  drupal_set_breadcrumb(array_merge(menu_get_active_breadcrumb(), $query->get_breadcrumb()));
+  return apachesolr_process_response($response, $final_query, $params);
 }
 
 function apachesolr_search_basic_params($query) {
