? formalter_fix.patch
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.11
diff -u -F^f -r1.1.2.11 apachesolr.module
--- apachesolr.module	20 Apr 2008 13:46:48 -0000	1.1.2.11
+++ apachesolr.module	20 Apr 2008 14:11:30 -0000
@@ -320,7 +320,7 @@ function apachesolr_block($op = 'list', 
       return $blocks;
 
     case 'view':
-      if (arg(0) == 'search') {
+      if (apachesolr_has_searched()) {
         // Get the query and response. Without these no blocks make sense.
         $query =& apachesolr_drupal_query();
         $response =& apachesolr_static_response_cache();
@@ -522,9 +522,15 @@ function apachesolr_block($op = 'list', 
 function apachesolr_form_alter($form_id, &$form) {
   $arg = arg(1);
   $alias = drupal_lookup_path('alias', "search/{$arg}");
-  if (preg_match("&/search/{$arg}&", $form['#action']) ||
+  // Ok, this really sucks. I want a way to know whether the action of the form
+  // is suposed to be handled by an ApacheSolr module or not. I manually
+  // exclude node and user here, but there are many other hook_search implementations
+  // in the wild and this code will potentially interfere with them. It also
+  // creates a Solr instance wasting resources.
+  if ($arg != 'node' && $arg != 'user' && (
+      preg_match("&/search/{$arg}&", $form['#action']) ||
       preg_match("&/{$alias}&", $form['#action'])  ||
-      strpos($form['#action'], $alias)) {
+      strpos($form['#action'], $alias))) {
     if (!isset($_POST['form_id'])) {
       // Set up our validation function
       $form['#validate']['apachesolr_search_validate'] = array();
@@ -543,6 +549,24 @@ function apachesolr_form_alter($form_id,
 }
 
 /**
+ * Semaphore that indicates whether a search has been done. Blocks use this
+ * later to decide whether they should load or not.
+ *
+ * @param $searched
+ *   A boolean indicating whether a search has been executed.
+ *
+ * @return
+ *   TRUE if a search has been executed.
+ *   FALSE otherwise.
+ */
+function apachesolr_has_searched($searched = NULL) {
+  static $_searched = FALSE;
+  if (is_bool($searched)) {
+    $_searched = $searched;
+  }
+  return $_searched;
+}
+/**
  * Factory method for solr singleton object. Structure allows for an arbitrary
  * number of solr objects to be used based on the host, port, path combination.
  * Get an instance like this:
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.5
diff -u -F^f -r1.1.2.5 apachesolr_search.module
--- apachesolr_search.module	20 Apr 2008 12:58:45 -0000	1.1.2.5
+++ apachesolr_search.module	20 Apr 2008 14:11:31 -0000
@@ -29,6 +29,7 @@ function apachesolr_search_search($op = 
       $solr =& apachesolr_get_solr(variable_get('apachesolr_host', 'localhost'), variable_get('apachesolr_port', 8983), variable_get('apachesolr_path', '/solr'));
       // This is the object that knows about the query coming from the user.
       $query =& apachesolr_drupal_query($keys);
+      
       try {
         $params = array(
           //'qt' => 'standard',
@@ -51,6 +52,7 @@ function apachesolr_search_search($op = 
         }
         $params['start'] = $_GET['page'] * $params['rows'];
         $response = $solr->search($query->get_query(), $params['start'], $params['rows'], $params);
+        apachesolr_has_searched(TRUE);
         $total = $response->numFound;
         // The response is cached so that it is accessible to the blocks and anything
         // else that needs it beyond the initial search.
