? 365901-node-type-weights.patch
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.99
diff -u -p -r1.1.2.12.2.99 apachesolr.module
--- apachesolr.module	28 Jan 2009 13:49:46 -0000	1.1.2.12.2.99
+++ apachesolr.module	29 Jan 2009 16:50:23 -0000
@@ -394,6 +394,11 @@ function apachesolr_node_to_document($ni
     foreach (module_implements('apachesolr_update_index') as $module) {
       $function = $module .'_apachesolr_update_index';
       $function($document, $node);
+      // Break there if the hook implementation decided not to index
+      // this document at all.
+      if (empty($document)) {
+        break;
+      }
     }
   }
   return $document;
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 16:50:23 -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_boost_form');
   return $output;
 }
 
@@ -33,7 +33,7 @@ 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');
-  
+
   $options = array(
     '10:2000.0' => '10',
     '8:1000.0' => '9',
@@ -134,3 +134,62 @@ function apachesolr_search_settings_form
   return system_settings_form($form);
 }
 
+/**
+ * Form builder function to set query type weights.
+ */
+function apachesolr_search_type_boost_form($form_state) {
+  $form = array();
+
+  // Get the current boost values.
+  $type_boosts = variable_get('apachesolr_search_type_boosts', array());
+
+  $form['apachesolr_search_type_boosts'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Type weights'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+    '#tree' => TRUE,
+    '#description' => t('Specify here which node types are more important when searching. Give a node type a greater numeric value to make it more important. If you omit a node type, it will not be indexed.'),
+  );
+
+  $weights = drupal_map_assoc(array('21.0', '13.0', '8.0', '5.0', '3.0', '2.0', '1.0', '0.8', '0.5', '0.3', '0.2', '0.1'));
+  $weights['0'] = t('Omit');
+
+  $names = node_get_types('names');
+
+  foreach ($names as $type => $name) {
+    $form['apachesolr_search_type_boosts'][$type] = array(
+      '#type' => 'select',
+      '#title' => t('Weight for %type', array('%type' => $name)),
+      '#options' => $weights,
+      '#default_value' => isset($type_boosts[$type]) ? $type_boosts[$type] : 5,
+    );
+  }
+
+  $form['#submit'][] = 'apachesolr_search_type_boost_form_submit';
+  return system_settings_form($form);
+}
+
+/**
+ * Submit callback for apachesolr_search_type_boost_form().
+ * 
+ * This is called before system_settings_form_submit().
+ */
+function apachesolr_search_type_boost_form_submit($form_id, &$form_state) {
+  $old_type_boosts = variable_get('apachesolr_search_type_boosts', array());
+  $new_type_boosts = $form_state['values']['apachesolr_search_type_boosts'];
+
+  foreach ($new_type_boosts as $type => $boost) {
+    // Remove newly omitted node types.
+    if (empty($new_type_boosts[$type]) && (!isset($old_type_boosts[$type]) || !empty($old_type_boosts[$type]))) {
+      // Get the $solr object
+      $solr = apachesolr_get_solr();
+      $solr->deleteByQuery("type:$type");
+    }
+
+    // Set no longer omitted node types for reindexing.
+    if (!empty($new_type_boosts[$type]) && (isset($old_type_boosts[$type]) && empty($old_type_boosts[$type]))) {
+      db_query("UPDATE {apachesolr_search_node} SET changed = %d WHERE nid = (SELECT nid FROM {node} WHERE type = '%s')", time(), $type);
+    }
+  }
+}
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 16:50:24 -0000
@@ -54,6 +54,17 @@ function apachesolr_search_update_index(
 }
 
 /**
+ * Implementations of hook_apachesolr_update_index.
+ */
+function apachesolr_search_apachesolr_update_index(&$document, $node) {
+  // Remove from processing node types we don't want.
+  $type_boosts = variable_get('apachesolr_search_type_boosts', array());
+  if (isset($type_boosts[$node->type]) && empty($type_boosts[$node->type])) {
+    $document = FALSE;
+  }
+}
+
+/**
  * Implementation of hook_search().
  */
 function apachesolr_search_search($op = 'search', $keys = NULL) {
@@ -181,6 +192,15 @@ 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 the node types.
+        $type_boosts = variable_get('apachesolr_search_type_boosts', array());
+        if (!empty($type_boosts)) {
+          foreach ($type_boosts as $type => $boost) {
+            $params['bq'][] = "type:$type^$boost";
+          }
+        }
+
         // This hook allows modules to modify the query and params objects.
         apachesolr_modify_query($query, $params, 'apachesolr_search');
         if (!$query) {
