Index: apachesolr.index.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.index.inc,v
retrieving revision 1.1.2.6.2.32
diff -u -p -r1.1.2.6.2.32 apachesolr.index.inc
--- apachesolr.index.inc	10 Dec 2010 03:43:45 -0000	1.1.2.6.2.32
+++ apachesolr.index.inc	13 Dec 2010 16:05:18 -0000
@@ -225,22 +225,25 @@ function apachesolr_add_taxonomy_to_docu
       $ancestors = taxonomy_get_parents_all($term->tid);
       foreach ($ancestors as $ancestor) {
         $document->setMultiValue('tid', $ancestor->tid);
-        $document->setMultiValue('im_vid_'. $ancestor->vid, $ancestor->tid);
+        $document->setMultiValue('im_vid_'. apachesolr_taxonomy_vocabulary_id($ancestor->vid), $ancestor->tid);
         $name = apachesolr_clean_text($ancestor->name);
-        $document->setMultiValue('vid', $ancestor->vid);
-        $document->{'ts_vid_'. $ancestor->vid .'_names'} .= ' '. $name;
+        $document->setMultiValue('vid', apachesolr_taxonomy_vocabulary_id($ancestor->vid));
+        $document->{'ts_vid_'. apachesolr_taxonomy_vocabulary_id($ancestor->vid) .'_names'} .= ' '. $name;
         // We index each name as a string for cross-site faceting
         // using the vocab name rather than vid in field construction .
-        $document->setMultiValue('sm_vid_'. apachesolr_vocab_name($ancestor->vid), $name);
+        $document->setMultiValue('sm_vid_'. apachesolr_vocab_name(apachesolr_taxonomy_vocabulary_id($ancestor->vid)), $name);
       }
     }
   }
 }
 
-/**
+ /**
  * Helper function - return a safe (PHP identifier) vocabulary name.
  */
 function apachesolr_vocab_name($vid) {
+  // No need to get vocabulary name if we are using machine name already.
+  if (!is_numeric($vid)) { return $vid; }
+
   static $names = array();
 
   if (!isset($names[$vid])) {
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.155.2.116
diff -u -p -r1.1.2.12.2.155.2.116 apachesolr.module
--- apachesolr.module	10 Dec 2010 03:43:45 -0000	1.1.2.12.2.155.2.116
+++ apachesolr.module	13 Dec 2010 16:05:19 -0000
@@ -1566,7 +1566,7 @@ function apachesolr_modify_query(&$query
           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_' . apachesolr_taxonomy_vocabulary_id($term->vid);
           }
         }
       }
@@ -1880,8 +1880,8 @@ function apachesolr_field_name_map($fiel
     );
     if (module_exists('taxonomy')) {
       foreach (taxonomy_get_vocabularies() as $vocab) {
-        $map['ts_vid_'. $vocab->vid .'_names'] = t('Taxonomy term names only from the %name vocabulary', array('%name' => $vocab->name));
-        $map['im_vid_'. $vocab->vid] = t('Taxonomy term IDs from the %name vocabulary', array('%name' => $vocab->name));
+        $map['ts_vid_'. apachesolr_taxonomy_vocabulary_id($vocab) .'_names'] = t('Taxonomy term names only from the %name vocabulary', array('%name' => $vocab->name));
+        $map['im_vid_'. apachesolr_taxonomy_vocabulary_id($vocab)] = t('Taxonomy term IDs from the %name vocabulary', array('%name' => $vocab->name));
       }
     }
     foreach (apachesolr_cck_fields() as $name => $field) {
@@ -2511,3 +2511,21 @@ function apachesolr_tt($name, $string, $
     return $string;
   }
 }
+
+/**
+ * Return the vocabulary identifier, the vocabulary's vid or module.
+ *
+ * @return
+ *   Vocabulary's module name if it is a features vocabulary (= exportable),
+ *   vocabulary's vid otherwise.
+ */
+function apachesolr_taxonomy_vocabulary_id($vocabulary) {
+  // Load vocab if only vid is handed.
+  if (!$vocabulary->module && is_numeric($vocabulary)) {
+    $vocabulary = taxonomy_vocabulary_load($vocabulary);
+  }
+  if (strpos($vocabulary->module, 'features_') === 0) {
+    return $vocabulary->module;
+  }
+  return $vocabulary->vid;
+}
Index: apachesolr.taxonomy.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/Attic/apachesolr.taxonomy.inc,v
retrieving revision 1.1.2.2.2.6
diff -u -p -r1.1.2.2.2.6 apachesolr.taxonomy.inc
--- apachesolr.taxonomy.inc	3 Nov 2010 14:31:03 -0000	1.1.2.2.2.6
+++ apachesolr.taxonomy.inc	13 Dec 2010 16:05:19 -0000
@@ -24,7 +24,7 @@ function apachesolr_search_taxonomy_term
   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;
+    $vocabulary_facet_name = 'im_vid_' . apachesolr_taxonomy_vocabulary_id($term->vid);
 
     if (!in_array($vocabulary_facet_name, $vids_to_override)) {
       $redirect_to_apachesolr = FALSE;
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.111.2.95
diff -u -p -r1.1.2.6.2.111.2.95 apachesolr_search.module
--- apachesolr_search.module	10 Dec 2010 03:43:45 -0000	1.1.2.6.2.111.2.95
+++ apachesolr_search.module	13 Dec 2010 16:05:19 -0000
@@ -672,7 +672,7 @@ function apachesolr_search_apachesolr_fa
     $vocabs = taxonomy_get_vocabularies();
     foreach ($vocabs as $vid => $vocab) {
       // In this case the delta and facet field are the same.
-      $delta = 'im_vid_' . $vid;
+      $delta = 'im_vid_' . apachesolr_taxonomy_vocabulary_id($vocab);
       $facets[$delta] = array(
         'info' => t('Taxonomy vocabulary: Filter by taxonomy @name', array('@name' => $vocab->name)),
         'facet_field' => $delta,
@@ -810,6 +810,12 @@ function apachesolr_search_collect_child
  */
 function apachesolr_search_taxonomy_facet_block($response, $query, $delta) {
   $vid = substr($delta, 7);
+
+  // Fetch vid if using vocabulary feature module name.
+  if (strpos($vid, 'features_') === 0) {
+    $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module = '%s'", $vid));
+  }
+
   if (!module_exists('taxonomy') || !is_numeric($vid)) {
     return;
   }
@@ -920,7 +926,7 @@ function apachesolr_search_nested_facet_
       if ($field_name == 'tid') {
         // Each taxonomy vocabulary in the Solr index uses its own field.
         $term = taxonomy_get_term($field['#value']);
-        $field_name = 'im_vid_' . $term->vid;
+        $field_name = 'im_vid_' . apachesolr_taxonomy_vocabulary_id($term->vid);
       }
     }
     $facet_definition = apachesolr_get_facet_definition_by_field_name($field_name);
