? 267833_apachesolr_failure_fallback.patch
? fallback.patch
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.29
diff -u -p -r1.1.2.12.2.29 apachesolr.module
--- apachesolr.module	16 Sep 2008 11:25:38 -0000	1.1.2.12.2.29
+++ apachesolr.module	17 Sep 2008 08:03:02 -0000
@@ -59,11 +59,47 @@ function apachesolr_settings() {
     '#default_value' => variable_get('apachesolr_rows', 10),
     '#options' => $options,
     '#description' => t('The number of results that will be shown per page.'),
-    );
+  );
+  $form['apachesolr_failure'] = array(
+    '#type' => 'select',
+    '#title' => t('On failure'),
+    '#options' => array('show_error' => t('Show error'), 
+      'show_drupal_results' => t('Show core Drupal results'), 
+      'show_no_results' => t('Show no results')
+    ),
+    '#default_value' => variable_get('apachesolr_failure', 'show_error'),
+    '#description' => t('What to display if ApacheSolr search is not available.'),
+  );
   return system_settings_form($form);
 }
 
 /**
+ * Determines ApacheSolr's behavior when searching causes an exception (e.g. Solr isn't available.)
+ * Depending on the admin settings, possibly redirect to Drupal's core search.
+ *
+ * @param $search_name
+ *   The name of the search implementation.
+ *
+ * @param $querystring
+ *   The search query that was issued at the time of failure.                         
+ */
+function apachesolr_failure($search_name, $querystring) {
+  $fail_rule = variable_get('apachesolr_failure', 'show_error');
+  
+  switch ($fail_rule) {
+    case 'show_error':
+      drupal_set_message(t('The Apache Solr search engine is not available. Please contact your site administrator.'), 'error');
+      break;
+    case 'show_drupal_results': 
+      drupal_set_message(t("%search_name is not available. Your search is being redirected.", array('%search_name' => $search_name)));
+      drupal_goto('search/node/' . drupal_urlencode($querystring));
+      break;
+    case 'show_no_results':
+      return;
+  }
+}
+
+/**
  * Implementation of hook_requirements().
  */
 function apachesolr_requirements($phase) {
@@ -740,6 +776,7 @@ function apachesolr_has_searched($search
   }
   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.
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.16
diff -u -p -r1.1.2.6.2.16 apachesolr_search.module
--- apachesolr_search.module	14 Aug 2008 03:27:05 -0000	1.1.2.6.2.16
+++ apachesolr_search.module	17 Sep 2008 08:03:02 -0000
@@ -119,7 +119,8 @@ function apachesolr_search_search($op = 
 
       } // try
       catch (Exception $e) {
-        watchdog('Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR);
+        watchdog('Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR);   
+        apachesolr_failure(t('Search'), $query->get_query());
       }
       break;
 
