Index: contrib/apachesolr_taxonomy/apachesolr_taxonomy.info
===================================================================
RCS file: contrib/apachesolr_taxonomy/apachesolr_taxonomy.info
diff -N contrib/apachesolr_taxonomy/apachesolr_taxonomy.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/apachesolr_taxonomy/apachesolr_taxonomy.info	25 May 2009 22:31:26 -0000
@@ -0,0 +1,7 @@
+; $Id$
+name = Apache Solr taxonomy integration
+description = Replaces taxonomy browse pages (taxonomy/term/XXX) with Apache Solr search result pages for vocabularies enabled as filters.
+dependencies[] = taxonomy
+dependencies[] = apachesolr
+package = Apache Solr
+core = "6.x"
Index: contrib/apachesolr_taxonomy/apachesolr_taxonomy.module
===================================================================
RCS file: contrib/apachesolr_taxonomy/apachesolr_taxonomy.module
diff -N contrib/apachesolr_taxonomy/apachesolr_taxonomy.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/apachesolr_taxonomy/apachesolr_taxonomy.module	25 May 2009 22:31:26 -0000
@@ -0,0 +1,49 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_menu_alter().
+ */
+function apachesolr_taxonomy_menu_alter(&$menu) {
+
+if (isset($menu['taxonomy/term/%'])) {
+    $menu['taxonomy/term/%']['page callback'] = 'apachesolr_taxonomy_override_taxonomy_term_page';
+    unset($menu['taxonomy/term/%']['file']);
+  }
+}
+
+/**
+ * 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 ( (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);
+  }
+}
