Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.92
diff -u -F^function -r1.1.2.6.2.92 apachesolr_search.module
--- apachesolr_search.module	14 May 2009 23:10:19 -0000	1.1.2.6.2.92
+++ apachesolr_search.module	25 May 2009 21:36:26 -0000
@@ -614,31 +614,60 @@ function apachesolr_search_get_type($fac
  */
 function apachesolr_search_form_search_form_alter(&$form, $form_state) {
 
-  if (($form['module']['#value'] == 'apachesolr_search') && variable_get('apachesolr_search_spellcheck', FALSE) && apachesolr_has_searched() && ($response = apachesolr_static_response_cache())) {
-    //Get spellchecker suggestions into an array.
-    $suggestions = get_object_vars($response->spellcheck->suggestions);
-
-    if ($suggestions) {
-      //Get the original query and replace words.
-      $query = apachesolr_current_query();
+  if ($form['module']['#value'] == 'apachesolr_search') {
+    // If we're not on a fresh search, allow refining the search.
+    $keys = trim(search_get_keys());
+    $filters = trim(isset($_REQUEST['filters']) ? $_REQUEST['filters'] : '');
+    if ($filters) {
+      $form['basic']['refine'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Search within results'),
+        '#default_value' => 0, // TODO: Have the default value determined by a setting.
+      );
+      $form['filters'] = array(
+        '#type' => 'hidden',
+        '#value' => $filters,
+      );
+    }
+    $form['#submit'][] = 'apachesolr_search_form_submit';
 
-      foreach($suggestions as $word => $value) {
-        $replacements[$word] = $value->suggestion[0];
+    if (variable_get('apachesolr_search_spellcheck', FALSE) && apachesolr_has_searched() && ($response = apachesolr_static_response_cache())) {
+      // Get spellchecker suggestions into an array.
+      $suggestions = get_object_vars($response->spellcheck->suggestions);
+
+      if ($suggestions) {
+        // Get the original query and replace words.
+        $query = apachesolr_current_query();
+
+        foreach($suggestions as $word => $value) {
+          $replacements[$word] = $value->suggestion[0];
+        }
+        $new_keywords = strtr($query->get_query_basic(), $replacements);
+
+        $form['basic']['suggestion'] = array(
+          '#prefix' => '<div class="spelling-suggestions">',
+          '#suffix' => '</div>',
+          '#type' => 'item',
+          '#title' => t('Did you mean'),
+          '#value' => l($new_keywords, $query->get_path($new_keywords), $filters ? array('query' => 'filters='. $filters) : array()),
+        );
       }
-      $new_keywords = strtr($query->get_query_basic(), $replacements);
-
-      $form['basic']['suggestion'] = array(
-        '#prefix' => '<div class="spelling-suggestions">',
-        '#suffix' => '</div>',
-        '#type' => 'item',
-        '#title' => t('Did you mean'),
-        '#value' => l($new_keywords, $query->get_path($new_keywords)),
-      );
     }
   }
 }
 
 /**
+ * Submit handler for the search form.
+ */
+function apachesolr_search_form_submit($form, &$form_state) {
+  $query = array();
+  if ($form_state['values']['refine'] && !empty($form_state['values']['filters'])) {
+    // Change redirect url to preserve the current filters.
+    $form_state['redirect'] = array('search/apachesolr_search/'. $form_state['values']['keys'], array('filters' => $form_state['values']['filters']));
+  }
+}
+
+/**
  * Implementation of hook_form_[form_id]_alter().
  *
  * This adds spelling suggestions to the search form.
