--- apachesolr_search.module	2009-05-14 08:27:27.000000000 -0700
+++ apachesolr_search2.module	2009-05-14 08:34:03.000000000 -0700
@@ -88,55 +88,60 @@ function apachesolr_search_search($op = 
       return apachesolr_index_status('apachesolr_search');
 
     case 'search':
+      $filters = isset($_GET['filters']) ? $_GET['filters'] : '';
+      $solrsort = isset($_GET['solrsort']) ? $_GET['solrsort'] : '';
+      $page = isset($_GET['page']) ? $_GET['page'] : 0;
+
+      return apachesolr_search_searchresults($keys, $filters, $solrsort, $page, 'apachesolr_search');
 
-      try {
-        $filters = isset($_GET['filters']) ? $_GET['filters'] : '';
-        $solrsort = isset($_GET['solrsort']) ? $_GET['solrsort'] : '';
-        // Validate sort parameter
-        if (strlen($solrsort) && preg_match('/^([a-z0-9_]+ (asc|desc)(,)?)+$/i', $solrsort)) {
-          $params['sort'] = $solrsort;
-        }
-        else {
-          $solrsort = '';
-        }
-        // This is the object that knows about the query coming from the user.
-        $query = apachesolr_drupal_query($keys, $filters, $solrsort, 'search/' . arg(1));
-        if (empty($query)) {
-          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_params_basic($query, $solr);
-        apachesolr_search_add_facet_params($params, $query, $solr);
-        apachesolr_search_add_boost_params($params, $query, $solr);
-
-        $page = isset($_GET['page']) ? $_GET['page'] : 0;
-        $params['start'] = $page * $params['rows'];
-
-        // Cache the built query. Since all the built queries go through
-        // this process, all the hook_invocations will happen later
-        apachesolr_current_query($query);
-        
-        // This hook allows modules to modify the query and params objects.
-        apachesolr_modify_query($query, $params, 'apachesolr_search');
-        if (!$query) {
-          return array();
-        }
-        $response = $solr->search($query->get_query_basic(), $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);
-        apachesolr_has_searched(TRUE);
-        return apachesolr_process_response($response, $query, $params);
-      } // try
-      catch (Exception $e) {
-        watchdog('Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR);
-        apachesolr_failure(t('Solr search'), empty($query) ? $keys : $query->get_query_basic());
-      }
       break;
   } // switch
 }
 
+function apachesolr_search_searchresults($keys, $filters = '', $solrsort = '', $page = 0, $caller = 'apachesolr_search') {
+  try {
+    // Validate sort parameter
+    if (strlen($solrsort) && preg_match('/^([a-z0-9_]+ (asc|desc)(,)?)+$/i', $solrsort)) {
+      $params['sort'] = $solrsort;
+    }
+    else {
+      $solrsort = '';
+    }
+    // This is the object that knows about the query coming from the user.
+    $query = apachesolr_drupal_query($keys, $filters, $solrsort, 'search/' . arg(1));
+    if (empty($query)) {
+      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_params_basic($query, $solr);
+    apachesolr_search_add_facet_params($params, $query, $solr);
+    apachesolr_search_add_boost_params($params, $query, $solr);
+
+    $params['start'] = $page * $params['rows'];
+
+    // Cache the built query. Since all the built queries go through
+    // this process, all the hook_invocations will happen later
+    apachesolr_current_query($query);
+    
+    // This hook allows modules to modify the query and params objects.
+    apachesolr_modify_query($query, $params, $caller);
+    if (!$query) {
+      return array();
+    }
+    $response = $solr->search($query->get_query_basic(), $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);
+    apachesolr_has_searched(TRUE);
+    return apachesolr_process_response($response, $query, $params);
+  } // try
+  catch (Exception $e) {
+    watchdog('Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR);
+    apachesolr_failure(t('Solr search'), empty($query) ? $keys : $query->get_query_basic());
+  }
+}
+
 function apachesolr_search_params_basic($query, $solr) {
   $params = array(
     'fl' => 'id,nid,title,comment_count,type,created,changed,score,path,url,uid,name',
