Index: apachesolr_search.module
===================================================================
--- apachesolr_search.module	(revision 120)
+++ apachesolr_search.module	(working copy)
@@ -253,7 +253,7 @@
   foreach ($facet_info as $infos) {
     foreach ($infos as $delta => $facet) {
       if ($facet['operator'] == 'OR') {
-        $ors[] = $delta;
+        $ors[] = $facet['facet_field'];
       }
     }
   }
@@ -261,30 +261,51 @@
   if (isset($params['fq'])) {
     $filter_queries = $params['fq'];
     foreach ($filter_queries as $delta => $values) {
-      $fq = $tag = '';
-      $op = 'AND';
-      $fields = array($delta);
-      // CCK and taxonomy facet field block deltas are not the same as their Solr index field names.
-      if (strpos($delta, '_cck_') !== FALSE) {
-        $fields[] = trim(drupal_substr($delta, 7, drupal_strlen($delta)));
-      }
-      elseif ($delta == 'tid') {
+      // Handle taxonomy terms as a special case.
+      if ($delta == 'tid') {
         if (function_exists('taxonomy_get_term')) {
+          // Initialize storage of terms, per vocabulary.
+          $taxonomy_facets = array();
+          // Initialize final fq for field tid.
+          $tid_fq = array();
+          // Loop thru each term in query to determine vocabulary id.
           foreach ($values as $value) {
             $filters = $query->filter_extract($value, 'tid');
             $term = taxonomy_get_term($filters[0]['#value']);
-            $fields[] = 'im_vid_' . $term->vid;
+            //$fields[] = 'im_vid_' . $term->vid;
+            $taxonomy_facets[$term->vid][] = 'tid:' . $term->tid;
           }
+          // Determine OR/AND operator for each term set, per vid.
+          foreach ($taxonomy_facets as $vid => $values) {
+            if (in_array("im_vid_$vid", $ors)) {
+              $params['fq'][] = "{!tag=im_vid_$vid}" . implode(' OR ', $values);
+            }
+            else {
+              $params['fq'][] = implode(' AND ', $values);
+            }
+          }
         }
+        unset($params['fq'][$delta]);
       }
+      else {
+        // Handle non-taxonomy facets.
+        $fq = $tag = '';
+        $op = 'AND';
+        $facet_field = $delta;
+        $fields = array($delta);
+        // CCK and taxonomy facet field block deltas are not the same as their Solr index field names.
+        if (strpos($delta, '_cck_') !== FALSE) {
+          $fields[] = trim(drupal_substr($delta, 7, drupal_strlen($delta)));
+        }
 
-      if (array_intersect($fields, $ors)) {
-        $tag = "{!tag=$delta}";
-        $op = 'OR';
+        if (array_intersect($fields, $ors)) {
+          $tag = "{!tag=$delta}";
+          $op = 'OR';
+        }
+        $fq = implode(" $op ", $params['fq'][$delta]);
+        $params['fq'][] = $tag . $fq;
+        unset($params['fq'][$delta]);
       }
-      $fq = implode(" $op ", $params['fq'][$delta]);
-      $params['fq'][] = $tag . $fq;
-      unset($params['fq'][$delta]);
     }
   }
 }
