Index: apachesolr.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.admin.inc,v
retrieving revision 1.1.2.25
diff -u -p -r1.1.2.25 apachesolr.admin.inc
--- apachesolr.admin.inc	23 Jun 2009 01:32:32 -0000	1.1.2.25
+++ apachesolr.admin.inc	24 Jun 2009 21:23:24 -0000
@@ -87,6 +87,13 @@ function apachesolr_settings() {
     '#options' => array(0 => t('Read and write (normal)'), 1 => t('Read only')),
     '#description' => t('<em>Read only</em> stops this site from sending updates to your search index. Useful for development sites.'),
   );
+  $form['advanced']['apachesolr_serve_taxonomy_links'] = array(
+    '#type' => 'radios',
+    '#title' => t('Use Apache Solr for taxonomy links'),
+    '#default_value' => variable_get('apachesolr_serve_taxonomy_links', 0),
+    '#description' => t('Note: Vocabularies that need this behavior need to be checked off on the <a href="@enabled_filters_url">enabled filters</a> settings page', array('@enabled_filters_url' => url('settings/apachesolr/enabled-filters'))),
+    '#options' => array(0 => t('Yes'), 1 => t('No')),
+  );
   return system_settings_form($form);
 }
 
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.148
diff -u -p -r1.1.2.12.2.148 apachesolr.module
--- apachesolr.module	19 Jun 2009 20:31:58 -0000	1.1.2.12.2.148
+++ apachesolr.module	24 Jun 2009 21:23:24 -0000
@@ -1057,12 +1057,12 @@ function apachesolr_static_response_cach
  * @param $base_path
  *   The search base path (without the keywords) for this query.
  */
-function apachesolr_drupal_query($keys = '', $filters = '', $solrsort = '', $base_path = '') {
+function apachesolr_drupal_query($keys = '', $filters = '', $solrsort = '', $base_path = '', $retain_filters = FALSE) {
   list($module, $class) = variable_get('apachesolr_query_class', array('apachesolr', 'Solr_Base_Query'));
   include_once drupal_get_path('module', $module) .'/'. $class .'.php';
   
   try {
-    $query = new $class(apachesolr_get_solr(), $keys, $filters, $solrsort, $base_path);
+    $query = new $class(apachesolr_get_solr(), $keys, $filters, $solrsort, $base_path, $retain_filters);
   }
   catch (Exception $e) {
     watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
Index: apachesolr.taxonomy.inc
===================================================================
RCS file: apachesolr.taxonomy.inc
diff -N apachesolr.taxonomy.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ apachesolr.taxonomy.inc	24 Jun 2009 21:23:25 -0000
@@ -0,0 +1,67 @@
+<?php
+// $Id$
+
+/**
+ * Overrides taxonomy/term/X links
+ */
+function apachesolr_taxonomy_override_taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') {
+  static $vids_to_override; 
+  if (!isset($vids_to_override)) {
+    $vids_to_override = apachesolr_get_enabled_facets('apachesolr_search');
+  }
+  
+  $terms = taxonomy_terms_parse_string($str_tids);
+  $redirect_to_apachesolr = TRUE;
+  
+  // Only support one term, only page callbacks, and only depth = 0 (because of way Solr indexing works)
+  if ( (count($terms['tids']) > 1 && $terms['operator'] != 'and') || ($op != 'page') || ($depth != 0) ) {
+    $redirect_to_apachesolr = FALSE;
+  }
+  else {
+    // Check if term belongs to vocabulary selected by admin as an available filter
+    $term = taxonomy_get_term($terms['tids'][0]);
+    $vocabulary_facet_name = 'im_vid_' . $term->vid;
+    
+    if (!in_array($vocabulary_facet_name, $vids_to_override)) {
+      $redirect_to_apachesolr = FALSE;
+    }
+  }
+
+  if ($redirect_to_apachesolr == FALSE) {
+    // Fallback to normal taxonomy/term page
+    require_once("modules/taxonomy/taxonomy.pages.inc");
+    return taxonomy_term_page($str_tids, $depth, $op);  
+  }
+  else {
+    $keys = "";
+    $filters = 'tid:' . array_pop($terms['tids']);
+    $solrsort = 'created desc';
+    $page = isset($_GET['page']) ? $_GET['page'] : 0;
+    
+    try {
+      //stolen from search.module (search_data)
+      $results = apachesolr_search_execute($keys, $filters, $solrsort, 'search/apachesolr_search', $page);
+      if (module_hook('apachesolr_search', 'search_page')) {
+        $results = module_invoke('apachesolr_search', 'search_page', $results);
+      }
+      else {
+        $results = theme('search_results', $results, $type);
+      }
+    } catch (Exception $e){
+      watchdog('apachesolr', t('Error running search'));
+    }
+    
+    //Set the title to the term name like taxonomy does.
+    drupal_set_title(check_plain($term->name));
+    
+    if ($results) {
+      $results = theme('box', t('Results within @term', array('@term' => $term->name)), $results);
+    }
+    else {
+      $results = theme('box', t('Your search yielded no results'), search_help('search#noresults', drupal_help_arg()));
+    } 
+    
+    //this sucks, but I don't know how we can add the retain filters box without using a global of some sort :(
+    return drupal_get_form('search_form', NULL, "", "apachesolr_search") . $results;
+  }
+}
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.104
diff -u -p -r1.1.2.6.2.104 apachesolr_search.module
--- apachesolr_search.module	22 Jun 2009 19:13:13 -0000	1.1.2.6.2.104
+++ apachesolr_search.module	24 Jun 2009 21:23:25 -0000
@@ -80,6 +80,13 @@ function apachesolr_search_menu_alter(&$
       $menu['search']['page arguments'] = array('apachesolr_search');
     }
   }
+  if (variable_get('apachesolr_serve_taxonomy_links', 0)) {
+    if (isset($menu['taxonomy/term/%'])) {
+      $menu['taxonomy/term/%']['page callback'] = 'apachesolr_override_taxonomy_term_page';
+      $menu['taxonomy/term/%']['file path'] = drupal_get_path('module', 'apachesolr_search');
+      $menu['taxonomy/term/%']['file'] = 'apachesolr.taxonomy.inc';
+    }
+  }
 }
 
 /**
@@ -121,8 +128,9 @@ function apachesolr_search_search($op = 
       $filters = isset($_GET['filters']) ? $_GET['filters'] : '';
       $solrsort = isset($_GET['solrsort']) ? $_GET['solrsort'] : '';
       $page = isset($_GET['page']) ? $_GET['page'] : 0;
+      $retain_filters = isset($_GET['retain-filters']);
       try {
-        $results = apachesolr_search_execute($keys, $filters, $solrsort, 'search/' . arg(1), $page);
+        $results = apachesolr_search_execute($keys, $filters, $solrsort, 'search/' . arg(1), $page, $retain_filters);
         return $results;
       }
       catch (Exception $e) {
@@ -180,7 +188,7 @@ function apachesolr_search_view($type = 
  *
  * @throws Exception
  */
-function apachesolr_search_execute($keys, $filters, $solrsort, $base_path = '', $page = 0, $caller = 'apachesolr_search') {
+function apachesolr_search_execute($keys, $filters, $solrsort, $base_path = '', $page = 0, $retain_filters = FALSE, $caller = 'apachesolr_search') {
   // Validate sort parameter
   // TODO: move this to the query class.
   if (strlen($solrsort) && preg_match('/^([a-z0-9_]+ (asc|desc)(,)?)+$/i', $solrsort)) {
@@ -191,7 +199,7 @@ function apachesolr_search_execute($keys
     $params = array();
   }
   // This is the object that knows about the query coming from the user.
-  $query = apachesolr_drupal_query($keys, $filters, $solrsort, $base_path);
+  $query = apachesolr_drupal_query($keys, $filters, $solrsort, $base_path, $retain_filters);
   if (empty($query)) {
     throw new Exception(t('Could not construct a Solr query in function apachesolr_search_search()'));
   }
@@ -763,24 +771,35 @@ function apachesolr_search_search_box_fo
  * This adds spelling suggestions, retain filters to the search form.
  */
 function apachesolr_search_form_search_form_alter(&$form, $form_state) {
-
   if ($form['module']['#value'] == 'apachesolr_search') {
-    $filters = isset($_REQUEST['filters']) ? trim($_REQUEST['filters']) : '';
+    $form['#submit'] = array('apachesolr_search_form_search_submit');
+    // No other modification make sense unless a query is active.
+    // Note - this means that the query must always be run before
+    // calling drupal_get_form('search_form').
+    $apachesolr_has_searched = apachesolr_has_searched();
+
+    $querystring = '';
+    $retain_filters = FALSE;
+    if ($apachesolr_has_searched) {
+      $query = apachesolr_current_query();
+      $querystring = $query->get_url_querystring();
+      $retain_filters = $query->retain_filters();
+    }
+
     $form['basic']['apachesolr_search']['#tree'] = TRUE;
-    if ($filters) {
+    $form['basic']['apachesolr_search']['querystring'] = array(
+      '#type' => 'hidden',
+      '#default_value' => $querystring,
+    );
+    if ($querystring || isset($form_state['post']['apachesolr_search']['retain-filters'])) {
       $form['basic']['apachesolr_search']['retain-filters'] = array(
         '#type' => 'checkbox',
         '#title' => t('Retain current filters'),
-        '#default_value' => !empty($_GET['retain-filters']), 
+        '#default_value' => $retain_filters, 
       );
     }
-    $form['filters'] = array(
-      '#type' => 'hidden',
-      '#default_value' => $filters,
-    );
 
-    $form['#submit'] = array('apachesolr_search_form_search_submit');
-    if (variable_get('apachesolr_search_spellcheck', FALSE) && apachesolr_has_searched() && ($response = apachesolr_static_response_cache())) {
+    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);
   
@@ -813,16 +832,16 @@ function apachesolr_search_form_search_f
 function apachesolr_search_form_search_submit($form, &$form_state) {
   $fv = $form_state['values'];
   $keys = $fv['processed_keys'];
-  $query = '';
+  $querystring = '';
   $base = 'search/'. $fv['module'] . '/';
   if (variable_get('clean_url', '0')) {
     $keys = str_replace('+', '%2B', $keys);
   }
-  if (!empty($fv['apachesolr_search']['retain-filters']) && $fv['filters']) {
-    $query = 'filters=' . rawurlencode($fv['filters']) . '&retain-filters=1';
+  if (!empty($fv['apachesolr_search']['retain-filters']) && $fv['apachesolr_search']['querystring']) {
+    $querystring = $fv['apachesolr_search']['querystring'] . '&retain-filters';
   }
-  $form_state['redirect'] = array($base . $keys, $query);
-  if ($keys == '' && $query == '') {
+  $form_state['redirect'] = array($base . $keys, $querystring);
+  if ($keys == '' && $querystring == '') {
     form_set_error('keys', t('Please enter some keywords.'));
   }
 }
Index: Solr_Base_Query.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/Solr_Base_Query.php,v
retrieving revision 1.1.4.36
diff -u -p -r1.1.4.36 Solr_Base_Query.php
--- Solr_Base_Query.php	18 Jun 2009 20:45:36 -0000	1.1.4.36
+++ Solr_Base_Query.php	24 Jun 2009 21:23:25 -0000
@@ -100,6 +100,7 @@ class Solr_Base_Query implements Drupal_
   protected $solr;
 
   protected $available_sorts;
+  protected $retain_filters;
 
   /**
    * @param $solr
@@ -111,20 +112,24 @@ class Solr_Base_Query implements Drupal_
    *   may come from search_get_keys().
    *
    * @param $filterstring
-   *   Key and value pairs that are applied as a filter query.
+   *   Key and value pairs that are applied as filter queries.
    *
    * @param $sortstring
    *   Visible string telling solr how to sort - added to output querystring.
    *
    * @param $base_path
    *   The search base path (without the keywords) for this query.
+   *
+   * @param $retain_filters
+   *   A boolean flag for post-query operations (e.g. form building).
    */
-  function __construct($solr, $keys, $filterstring, $sortstring, $base_path) {
+  function __construct($solr, $keys, $filterstring, $sortstring, $base_path, $retain_filters = FALSE) {
     $this->solr = $solr;
     $this->keys = trim($keys);
     $this->filterstring = trim($filterstring);
     $this->solrsort = trim($sortstring);
     $this->base_path = $base_path;
+    $this->retain_filters = $retain_filters;
     $this->id = ++self::$idCount;
     $this->parse_filters();
     $this->available_sorts = $this->default_sorts();
@@ -134,6 +139,10 @@ class Solr_Base_Query implements Drupal_
     $this->id = ++self::$idCount;
   }
 
+  public function retain_filters() {
+    return $this->retain_filters;
+  }
+  
   public function add_filter($field, $value, $exclude = FALSE) {
     $this->fields[] = array('#exclude' => $exclude, '#name' => $field, '#value' => trim($value));
   }
