Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.90
diff -u -p -r1.1.2.6.2.90 apachesolr_search.module
--- apachesolr_search.module	6 May 2009 01:15:35 -0000	1.1.2.6.2.90
+++ apachesolr_search.module	7 May 2009 23:18:36 -0000
@@ -53,6 +53,83 @@ function apachesolr_search_menu() {
 }
 
 /**
+ * Implementation of hook_menu_alter().
+ */
+function apachesolr_search_menu_alter(&$menu) {
+  if (isset($menu['search/apachesolr_search/%menu_tail'])) {
+    $menu['search/apachesolr_search/%menu_tail']['page callback'] = 'apachesolr_search_view';
+    $menu['search/apachesolr_search'] = $menu['search/apachesolr_search/%menu_tail'];
+    unset($menu['search/apachesolr_search/%menu_tail']);
+  }
+  if (isset($menu['taxonomy/term/%'])) {
+    $menu['taxonomy/term/%']['page callback'] = 'apachesolr_search_override_taxonomy_term_page';
+    unset($menu['taxonomy/term/%']['file']);
+  }
+}
+
+/**
+ * Overrides taxonomy/term/X links
+ */
+function apachesolr_search_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 ( (sizeof($terms['tids'])>1 && $terms['operator'] != 'and') || $op != 'page' || $depth != 0) {
+    $redirect_to_apachesolr = FALSE;
+  } else {
+    // Check if term blongs 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) {
+    // Return an apachesolr search page
+    $_GET['q'] = 'search/apachesolr_search';
+    $_GET['filters'] = 'tid:' . implode(' tid:', $terms['tids']);
+    return apachesolr_search_view("apachesolr_search");
+  } else{
+    // Fallback to normal taxonomy/term page
+    require_once("modules/taxonomy/taxonomy.pages.inc");
+    taxonomy_term_page($str_tids, $depth, $op);
+  }
+}
+
+/**
+ * Re-implementation of search_view().
+ */
+function apachesolr_search_view($type) {
+  $keys = trim(search_get_keys());
+  $filters = isset($_GET['filters']) ? trim($_GET['filters']) : '';
+  // Only perform search if there is non-whitespace search term or filters:
+  $results = '';
+  if ($keys || $filters) {
+    // Log the search keys:
+    watchdog('search', '%keys filters=%filters (@type).', array('%keys' => $keys, '%filters' => $filters, '@type' => t('Search')), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys));
+  
+    // Collect the search results:
+    $results = search_data($keys, $type);
+  
+    if ($results) {
+      $results = theme('box', t('Search results'), $results);
+    }
+    else {
+      $results = theme('box', t('Your search yielded no results'), search_help('search#noresults', drupal_help_arg()));
+    }
+  }
+  // Construct the search form.
+  return drupal_get_form('search_form', NULL, $keys, $type) . $results;
+}
+
+/**
  * Implementation of hook_update_index().
  */
 function apachesolr_search_update_index() {
@@ -90,12 +167,8 @@ function apachesolr_search_search($op = 
     case 'search':
 
       try {
-        if (empty($filters) && !empty($_GET['filters'])) {
-          $filters = $_GET['filters'];
-        }
-        if (empty($solrsort) && !empty($_GET['solrsort'])) {
-          $solrsort = $_GET['solrsort'];
-        }
+        $filters = isset($_GET['filters']) ? $_GET['filters'] : '';
+        $solrsort = isset($_GET['solrsort']) ? $_GET['solrsort'] : '';
         // This is the object that knows about the query coming from the user.
         $query = apachesolr_drupal_query($keys, $filters, $solrsort, 'search/' . arg(1));
         if (empty($query)) {
