--- /c/projects/drupal/cvs-head/drupal/modules/taxonomy/taxonomy.module	2006-08-19 18:03:32.562500000 -0400
+++ modules/taxonomy/taxonomy.module	2006-08-19 17:52:42.781250000 -0400
@@ -253,7 +253,51 @@ function taxonomy_form_vocabulary($edit 
     '#default_value' => $edit['weight'],
     '#description' => t('In listings, the heavier vocabularies will sink and the lighter vocabularies will be positioned nearer the top.'),
   );
-
+  $form['indexing'] = array('#type' => 'fieldset',
+    '#title' => t('Indexing options (advanced)'),
+    '#description' => t('These options let you define whether this vocabulary\'s terms should be stored in the search index when used on a node, and if so what kind of ranking they should get relative to various html tags. The <strong>search</strong> module must be enabled for these options to have any effect.'), 
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $rankings = array('h1' => t('Assign same ranking as <h1> text'),
+    'h2' => t('Assign same ranking as <h2> text'),
+    'h3' => t('Assign same ranking as <h3> text'),
+    'h4' => t('Assign same ranking as <h4> text'),
+    'h5' => t('Assign same ranking as <h5> text'),
+    'h6' => t('Assign same ranking as <h6> text'),
+    'a' => t('Assign same ranking as <a> text'),
+    'strong' => t('Assign same ranking as <strong> text'),
+    'p' => t('Assign same ranking as <p> text'),
+    0 => t('Do not index terms'),
+  );
+  $form['indexing']['term_ranking'] = array('#type' => 'select',
+    '#title' => t('Term ranking'),
+    '#description' => t('Defines the ranking of the terms being used.'),
+    '#default_value' => (isset($edit['term_ranking']) ? $edit['term_ranking'] : 'strong'),
+    '#options' => $rankings,
+  );
+  $rankings[0] = t('Do not index synonyms');
+  $form['indexing']['synonym_ranking'] = array('#type' => 'select',
+    '#title' => t('Synonym ranking'),
+    '#description' => t('Defines the ranking of synonyms of the terms being used.'),
+    '#default_value' => (isset($edit['synonym_ranking']) ? $edit['synonym_ranking'] : 0),
+    '#options' => $rankings,
+  );
+  $rankings[0] = t('Do not index parent terms');
+  $form['indexing']['parent_ranking'] = array('#type' => 'select',
+    '#title' => t('Parent term ranking'),
+    '#description' => t('Defines the ranking of terms that are parents of the terms being used.'),
+    '#default_value' => (isset($edit['parent_ranking']) ? $edit['parent_ranking'] : 0),
+    '#options' => $rankings,
+  );
+  $rankings[0] = t('Do not index parent synonyms');
+  $form['indexing']['parent_synonym_ranking'] = array('#type' => 'select',
+    '#title' => t('Parent synonym ranking'),
+    '#description' => t('Defines the ranking of the synonyms of parent terms. You <strong>must</strong> assign a ranking to parent terms for this option to have any effect.'),
+    '#default_value' => (isset($edit['parent_synonym_ranking']) ? $edit['parent_synonym_ranking'] : 0),
+    '#options' => $rankings,
+  );
+  
   $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
   if ($edit['vid']) {
     $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
@@ -284,7 +328,7 @@ function taxonomy_save_vocabulary(&$edit
   $edit['nodes'] = empty($edit['nodes']) ? array() : $edit['nodes'];
 
   if ($edit['vid'] && $edit['name']) {
-    db_query("UPDATE {vocabulary} SET name = '%s', description = '%s', help = '%s', multiple = %d, required = %d, hierarchy = %d, relations = %d, tags = %d, weight = %d, module = '%s' WHERE vid = %d", $edit['name'], $edit['description'], $edit['help'], $edit['multiple'], $edit['required'], $edit['hierarchy'], $edit['relations'], $edit['tags'], $edit['weight'], isset($edit['module']) ? $edit['module'] : 'taxonomy', $edit['vid']);
+    db_query("UPDATE {vocabulary} SET name = '%s', description = '%s', help = '%s', multiple = %d, required = %d, hierarchy = %d, relations = %d, tags = %d, weight = %d, term_ranking = '%s', synonym_ranking = '%s', parent_ranking = '%s', parent_synonym_ranking = '%s', module = '%s' WHERE vid = %d", $edit['name'], $edit['description'], $edit['help'], $edit['multiple'], $edit['required'], $edit['hierarchy'], $edit['relations'], $edit['tags'], $edit['weight'], $edit['term_ranking'], $edit['synonym_ranking'], $edit['parent_ranking'], $edit['parent_synonym_ranking'], isset($edit['module']) ? $edit['module'] : 'taxonomy', $edit['vid']);
     db_query("DELETE FROM {vocabulary_node_types} WHERE vid = %d", $edit['vid']);
     foreach ($edit['nodes'] as $type => $selected) {
       db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
@@ -1184,10 +1232,46 @@ function taxonomy_nodeapi($node, $op, $a
 function taxonomy_node_update_index(&$node) {
   $output = array();
   foreach ($node->taxonomy as $term) {
-    $output[] = $term->name;
+    $vocabulary = taxonomy_get_vocabulary($term->vid);
+    if ($vocabulary->term_ranking) {
+      $output[] = '<'. $vocabulary->term_ranking .'>'. $term->name .'</'. $vocabulary->term_ranking .'>';
+    }
+    if ($vocabulary->synonym_ranking) {
+      $synonyms = taxonomy_get_synonyms($term->tid);
+      if (count($synonyms)) {
+        $output[] = '<'. $vocabulary->synonym_ranking .'>'. implode(', ', $synonyms) .'</'. $vocabulary->synonym_ranking .'>';
+      }
+    }
+    if ($vocabulary->parent_ranking) {
+      // Collect all the parents of the term in order to index them
+      $parents = array(); // Array containing the parents' names
+      $parents_synonyms = array();
+      $tids = array(); // Array of tids whose parents have to be traversed
+      $tids[] = $term->tid;
+      while(count($tids) && count($immediate_parents = taxonomy_get_parents(array_shift($tids)))) {
+        foreach($immediate_parents as $parent) {
+          if (!isset($parents[$parent->tid])) {
+            $parents[$parent->tid] = $parent->name; // Using tid as key to avoid duplicates
+            $tids[] = $parent->tid;
+            if ($vocabulary->parent_synonym_ranking) {
+              $synonyms = taxonomy_get_synonyms($parent->tid);
+              foreach($synonyms as $synonym) {
+                $parents_synonyms[] = $synonym;
+              }
+            }
+          }
+        }
+      }
+      if (count($parents)) {
+        $output[] = '<'. $vocabulary->parent_ranking .'>'. implode(', ', $parents) .'</'. $vocabulary->parent_ranking .'>';
+      }
+      if (count($parents_synonyms)) {
+        $output[] = '<'. $vocabulary->parent_synonym_ranking .'>'. implode(', ', $parents_synonyms) .'</'. $vocabulary->parent_synonym_ranking .'>';
+      }
+    }
   }
   if (count($output)) {
-    return '<strong>('. implode(', ', $output) .')</strong>';
+    return '('. implode(', ', $output) .')';
   }
 }
 
--- /c/projects/drupal/cvs-head/drupal/modules/search/search.module	2006-08-19 14:39:36.406250000 -0400
+++ modules/search/search.module	2006-08-19 17:52:41.609375000 -0400
@@ -1122,7 +1122,7 @@ function search_excerpt($keys, $text) {
   $keys = array_merge($matches[2], $matches[3]);
 
   // Prepare text
-  $text = ' '. strip_tags(str_replace(array('<', '>'), array(' <', '> '), $text)) .' ';
+  $text = ' '. strip_tags($text) .' ';
   array_walk($keys, '_search_excerpt_replace');
   $workkeys = $keys;
 
--- /c/projects/drupal/cvs-head/drupal/modules/system/system.install	2006-08-19 14:39:36.937500000 -0400
+++ modules/system/system.install	2006-08-19 17:54:39.781250000 -0400
@@ -377,6 +377,10 @@ function system_install() {
         tags tinyint(3) unsigned NOT NULL default '0',
         module varchar(255) NOT NULL default '',
         weight tinyint(4) NOT NULL default '0',
+        term_ranking varchar(8),
+        synonym_ranking varchar(8),
+        parent_ranking varchar(8),
+        parent_synonym_ranking varchar(8),
         PRIMARY KEY (vid)
       ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 
@@ -3047,6 +3051,30 @@ function system_update_1005() {
   return $ret;
 }
 
+function system_update_1006() {
+  // Added taxonomy ranking for search index
+  $ret = array();
+
+  switch ($GLOBALS['db_type']) {
+    case 'mysqli':
+    case 'mysql':
+      $ret[] = update_sql("ALTER TABLE {vocabulary} ADD COLUMN term_ranking varchar(8)");
+      $ret[] = update_sql("ALTER TABLE {vocabulary} ADD COLUMN synonym_ranking varchar(8)");
+      $ret[] = update_sql("ALTER TABLE {vocabulary} ADD COLUMN parent_ranking varchar(8)");
+      $ret[] = update_sql("ALTER TABLE {vocabulary} ADD COLUMN parent_synonym_ranking varchar(8)");
+      break;
+
+    case 'pgsql':
+      db_add_column($ret, 'vocabulary', 'term_ranking', 'varchar(8)');
+      db_add_column($ret, 'vocabulary', 'synonym_ranking', 'varchar(8)');
+      db_add_column($ret, 'vocabulary', 'parent_ranking', 'varchar(8)');
+      db_add_column($ret, 'vocabulary', 'parent_synonym_ranking', 'varchar(8)');
+      break;
+  }
+
+  return $ret;
+}
+
 /**
  * @} End of "defgroup updates-4.7-to-x.x"
  * The next series of updates should start at 2000.
