? 230412.patch_.txt
? taxonomy-hierarchy.patch
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.30
diff -u -p -r1.1.2.30 apachesolr.module
--- apachesolr.module	16 Sep 2008 09:25:44 -0000	1.1.2.30
+++ apachesolr.module	16 Sep 2008 11:00:08 -0000
@@ -330,15 +330,22 @@ class ApacheSolrUpdate {
           $document->stitle = $node->title;
           
           if (is_array($node->taxonomy)) {
-            foreach ($node->taxonomy as $term) {
-              $document->setMultiValue('tid', $term->tid);
-              
+            foreach ($node->taxonomy as $term) { 
               // Double indexing of tids lets us do effecient searches (on tid)
               // and do accurate per-vocabulary faceting.
-              $document->setMultiValue('imfield_vid' . $term->vid, $term->tid);
-              
-              $document->setMultiValue('vid', $term->vid);
-              $document->setMultiValue('taxonomy_name', $term->name);
+              $document->setMultiValue('imfield_vid' . $term->vid, $term->tid);    
+              $document->setMultiValue('vid', $ancestor->vid);
+                                                                       
+              // By including the ancestors to a term in the index we make 
+              // sure that searches for general categories match specific
+              // categories, e.g. Fruit -> apple, a search for fruit will find
+              // content categorized with apple.
+              $ancestors = taxonomy_get_parents_all( $term->tid );    
+              foreach( $ancestors as $ancestor ) {
+                $document->setMultiValue('tid', $ancestor->tid);
+                $document->setMultiValue('taxonomy_name', $ancestor->name);
+                $text .= ' ' . $ancestor->name;
+              }
             }
           }
           $document->text = $text;
