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	25 Jun 2009 23:55:36 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: apachesolr.admin.inc,v 1.1.2.25 2009/06/23 01:32:32 pwolanin Exp $
+// $Id: apachesolr.admin.inc,v 1.1.2.24 2009/06/18 08:01:15 jacobsingh Exp $
 
 /**
  * @file
@@ -82,10 +82,9 @@ function apachesolr_settings() {
   );
   $form['advanced']['apachesolr_read_only'] = array(
     '#type' => 'radios',
-    '#title' => t('Index write access'),
+    '#title' => t('Read-only index'),
     '#default_value' => variable_get('apachesolr_read_only', 0),
-    '#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.'),
+    '#options' => array(0 => t('Both update and search (normal)'), 1 => t('Only search (read-only)')),
   );
   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	25 Jun 2009 23:55:38 -0000
@@ -569,7 +569,7 @@ function apachesolr_block($op = 'list', 
         $sorts = $query->get_available_sorts();
 
         $solrsorts = array();
-        $sort_parameter = isset($_GET['solrsort']) ? check_plain($_GET['solrsort']) : FALSE;
+        $sort_parameter = $query->get_solrsort();
         foreach (explode(',', $sort_parameter) as $solrsort) {
           $parts = explode(' ', $solrsort);
           if (!empty($parts[0]) && !empty($parts[1])) {
@@ -1477,7 +1477,12 @@ interface Drupal_Solr_Query_Interface {
    * @param string raw string to set the sort to
    */
   function set_solrsort($sortstring);
-  
+
+  /**
+   * Get the solrsort.
+   */
+  function get_solrsort();
+
   /**
    * Return an array of all filters.
    */
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	25 Jun 2009 23:55:39 -0000
@@ -0,0 +1,60 @@
+<?php
+// $Id$
+
+/**
+ * Overrides taxonomy/term/X links
+ */
+function apachesolr_search_taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') {
+
+  $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 drupal_get_path('module', '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;
+    $_GET['retain-filters'] = 1;
+    
+    try {
+      //stolen from search.module (search_data)
+      $data = apachesolr_search_execute($keys, $filters, $solrsort, 'search/apachesolr_search', $page);
+      $results = theme('search_results', $data, $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()));
+    } 
+
+    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	25 Jun 2009 23:55:39 -0000
@@ -80,6 +80,13 @@ function apachesolr_search_menu_alter(&$
       $menu['search']['page arguments'] = array('apachesolr_search');
     }
   }
+  if (variable_get('apachesolr_search_taxonomy_links', 0)) {
+    if (isset($menu['taxonomy/term/%'])) {
+      $menu['taxonomy/term/%']['page callback'] = 'apachesolr_search_taxonomy_term_page';
+      $menu['taxonomy/term/%']['file path'] = drupal_get_path('module', 'apachesolr_search');
+      $menu['taxonomy/term/%']['file'] = 'apachesolr.taxonomy.inc';
+    }
+  }
 }
 
 /**
@@ -180,7 +187,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 +198,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 +770,33 @@ 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 = '';
+    if ($apachesolr_has_searched) {
+      $query = apachesolr_current_query();
+      $querystring = $query->get_url_querystring();
+    }
+
     $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' => (int) isset($_GET['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 +829,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.'));
   }
 }
@@ -844,6 +860,17 @@ function apachesolr_search_form_apacheso
     '#type' => 'value',
     '#value' => variable_get('apachesolr_search_make_default', 0),
   );
+  $form['advanced']['apachesolr_search_taxonomy_links'] = array(
+    '#type' => 'radios',
+    '#title' => t('Use Apache Solr for taxonomy links'),
+    '#default_value' => variable_get('apachesolr_search_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('Disabled'), 1 => t('Enabled')),
+  );
+  $form['advanced']['apachesolr_search_taxonomy_previous'] = array(
+    '#type' => 'value',
+    '#value' => variable_get('apachesolr_search_taxonomy_links', 0),
+  );
   $form['apachesolr_search_spellcheck'] = array(
     '#type' => 'checkbox',
     '#title' => t('Enable spellchecker and suggestions'),
@@ -865,7 +892,9 @@ function apachesolr_search_form_apacheso
  * @see apachesolr_search_form_apachesolr_settings_alter()
  */
 function apachesolr_search_make_default_submit($form, &$form_state) {
-  if ($form_state['values']['apachesolr_search_default_previous'] != variable_get('apachesolr_search_make_default', 0)) {
+  // We use variable_get() instead of the form values so as to also handle reset to defaults.
+  if ($form_state['values']['apachesolr_search_default_previous'] != variable_get('apachesolr_search_make_default', 0) ||
+      $form_state['values']['apachesolr_search_taxonomy_previous'] != variable_get('apachesolr_search_make_default', 0)) {
     // Take account of path changes
     menu_rebuild();
   }
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	25 Jun 2009 23:55:40 -0000
@@ -111,7 +111,7 @@ 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.
@@ -133,7 +133,7 @@ class Solr_Base_Query implements Drupal_
   function __clone() {
     $this->id = ++self::$idCount;
   }
-
+  
   public function add_filter($field, $value, $exclude = FALSE) {
     $this->fields[] = array('#exclude' => $exclude, '#name' => $field, '#value' => trim($value));
   }
@@ -237,6 +237,10 @@ class Solr_Base_Query implements Drupal_
     $this->solrsort = trim($sortstring);
   }
 
+  public function get_solrsort() {
+    return $this->solrsort;
+  }
+
   public function get_available_sorts() {
     return $this->available_sorts;
   }
