? 365901-node-type-weights.patch
Index: apachesolr_search.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.admin.inc,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 apachesolr_search.admin.inc
--- apachesolr_search.admin.inc	27 Jan 2009 20:12:51 -0000	1.1.2.10
+++ apachesolr_search.admin.inc	29 Jan 2009 00:59:43 -0000
@@ -22,7 +22,7 @@ function apachesolr_search_settings_page
     drupal_set_message($e->getMessage(), "warning");
     $output .= t('Cannot get information about the fields in the index at this time.');
   }
-
+  $output .= drupal_get_form('apachesolr_search_type_weight_form');
   return $output;
 }
 
@@ -33,7 +33,8 @@ function apachesolr_search_bias_form($fo
 
   $date_settings = variable_get('apachesolr_search_date_boost', '4:200.0');
   $comment_settings = variable_get('apachesolr_search_comment_boost', '4:200.0');
-  
+  $type_settings = variable_get('apachesolr_search_type_boost', '4:200.0');
+
   $options = array(
     '10:2000.0' => '10',
     '8:1000.0' => '9',
@@ -69,6 +70,13 @@ function apachesolr_search_bias_form($fo
     '#default_value' => $comment_settings,
     '#description' => t('This setting will change the result scoring so that nodes with more comments may appear before those with higher keyword matching.'),
   );
+  $form['biasing']['apachesolr_search_type_boost'] = array(
+    '#type' => 'select',
+    '#options' => $options,
+    '#title' => t("'Type' bias"),
+    '#default_value' => $comment_settings,
+    '#description' => t('This setting will change the result scoring so that node type weights have more or less influence on the ordering. Node type weights can be set below.'),
+  );
 
   return system_settings_form($form);
 }
@@ -134,3 +142,37 @@ function apachesolr_search_settings_form
   return system_settings_form($form);
 }
 
+/**
+ * Form builder function to set query type weights.
+ */
+function apachesolr_search_type_weight_form($form_state) {
+  $form = array();
+
+  // get the current weights
+  $type_weights = variable_get('apachesolr_search_type_weights', array());
+
+  $form['apachesolr_search_type_weights'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Type weights'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+    '#tree' => TRUE,
+  );
+
+  $weights = drupal_map_assoc(range(0, 10));
+  $weights['0'] = t('Omit');
+
+  $names = node_get_types('names');
+
+  foreach ($names as $type => $name) {
+    $form['apachesolr_search_type_weights'][$type] = array(
+      '#type' => 'select',
+      '#title' => t('Weight for %type', array('%type' => $name)),
+      '#options' => $weights,
+      '#default_value' => isset($type_weights[$type]) ? $type_weights[$type] : 5,
+    );
+  }
+
+  return system_settings_form($form);
+}
+
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.63
diff -u -p -r1.1.2.6.2.63 apachesolr_search.module
--- apachesolr_search.module	27 Jan 2009 21:32:34 -0000	1.1.2.6.2.63
+++ apachesolr_search.module	29 Jan 2009 00:59:44 -0000
@@ -54,6 +54,15 @@ function apachesolr_search_update_index(
 }
 
 /**
+ * Implementations of hook_apachesolr_update_index.
+ */
+function apachesolr_search_apachesolr_update_index(&$document, $node) {
+  // Alter the weight of documents per node type.
+  $type_weights = variable_get('apachesolr_search_type_weights', array());
+  $document->type_weight = (isset($type_weights[$node->type]) ? $type_weights[$node->type] : 5) / 10;
+}
+
+/**
  * Implementation of hook_search().
  */
 function apachesolr_search_search($op = 'search', $keys = NULL) {
@@ -181,6 +190,17 @@ function apachesolr_search_search($op = 
         if ($comment_boost) {
           $params['bf'][] = "recip(rord(comment_count),$comment_steepness,$total,$total)^$comment_boost";
         }
+
+        // Modify the weight of results according to node types.
+        $type_weights = variable_get('apachesolr_search_type_weights', array());
+        $type_boost = variable_get('apachesolr_search_type_boost', '200.0');
+        list($type_steepness, $type_boost) = explode(':', $type_boost);
+        if (!empty($type_weights)) {
+          foreach ($type_weights as $name => $weight) {
+            $params['bf'][] = "type_weight^$type_boost";
+          }
+        }
+
         // This hook allows modules to modify the query and params objects.
         apachesolr_modify_query($query, $params, 'apachesolr_search');
         if (!$query) {
Index: schema.xml
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/schema.xml,v
retrieving revision 1.1.2.1.2.20
diff -u -p -r1.1.2.1.2.20 schema.xml
--- schema.xml	14 Jan 2009 21:41:28 -0000	1.1.2.1.2.20
+++ schema.xml	29 Jan 2009 00:59:44 -0000
@@ -250,6 +250,7 @@
    <field name="body" type="text" indexed="true" stored="true" termVectors="true"/>
    <field name="type" type="string" indexed="true" stored="true"/>
    <field name="type_name" type="string" indexed="true" stored="true"/>
+   <field name="type_weight" type="float" indexed="true" stored="true"/>
    <field name="path" type="text" indexed="true" stored="true" termVectors="true"/>
    <field name="uid"  type="integer" indexed="true" stored="true"/>
    <field name="name" type="text" indexed="true" stored="true" termVectors="true"/>
