--- apachesolr.module.orig	2008-07-19 10:22:43.000000000 -0400
+++ apachesolr.module	2008-11-14 11:07:12.000000000 -0500
@@ -1,4 +1,8 @@
 <?php
+/**
+ * Tweaks:
+ * - Updated the class object to allow nid as a parameter in the update_index and getNodesToIndex methods
+ **/
 // $Id: apachesolr.module,v 1.1.2.18 2008/07/19 14:22:43 robertDouglass Exp $
 
 /**
@@ -149,18 +153,25 @@ class ApacheSolrUpdate {
    * Modules need to then call apache_update_success after each node is successfully
    * indexed.
    */
-  static function getNodesToIndex($namespace) {
+  static function getNodesToIndex($namespace, $nid = FALSE) {
     register_shutdown_function('apachesolr_shutdown');
 
-    $cron_change = self::get_change($namespace);
-    $cron_last = self::get_last($namespace);
-    $cron_limit = variable_get('search_cron_limit', 100);
-
-    $result = db_query_range('SELECT GREATEST(IF(c.last_comment_timestamp IS NULL, 0, c.last_comment_timestamp), n.changed) as last_change, n.nid '.
-                             'FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid '.
-                             'WHERE n.status = 1 '.
-                             '  AND ((GREATEST(n.changed, c.last_comment_timestamp) = %d AND n.nid > %d) OR (n.changed > %d OR c.last_comment_timestamp > %d)) '.
-                             'ORDER BY GREATEST(n.changed, c.last_comment_timestamp) ASC, n.nid ASC', $cron_change, $cron_last, $cron_change, $cron_change, $cron_change, 0, $cron_limit);
+    //if we want to index a specific node
+    if (is_numeric($nid) && $nid > 0) {
+      $result = db_query('SELECT GREATEST(IF(c.last_comment_timestamp IS NULL, 0, c.last_comment_timestamp), n.changed) as last_change, n.nid
+                               FROM {node} n
+                               LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid
+                               WHERE n.nid = %d ', $nid);
+    } else { //else - we are indexing all new/updated nodes
+      $cron_change = self::get_change($namespace);
+      $cron_last = self::get_last($namespace);
+      $cron_limit = variable_get('search_cron_limit', 100);
+
+      $result = db_query_range('SELECT GREATEST(IF(c.last_comment_timestamp IS NULL, 0, c.last_comment_timestamp), n.changed) as last_change, n.nid '.
+                               'FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid '.
+                               'WHERE ( n.status = 1 AND (GREATEST(n.changed, c.last_comment_timestamp) = %d AND n.nid > %d) OR (n.changed > %d OR c.last_comment_timestamp > %d)) '.
+                               'ORDER BY GREATEST(n.changed, c.last_comment_timestamp) ASC, n.nid ASC', $cron_change, $cron_last, $cron_change, $cron_change, $cron_change, 0, $cron_limit);
+    }//end - if we want to index a specific node
     return $result;
   }
 
@@ -168,7 +179,7 @@ class ApacheSolrUpdate {
     self::$_namespaces[$namespace] = array('last_change' => $last_change, 'last_id' => $last_id);
   }
 
-  static function update_index($namespace) {
+  static function update_index($namespace, $nid = FALSE) {
     $solr = FALSE;
     try {
       // Get the $solr object
@@ -186,7 +197,7 @@ class ApacheSolrUpdate {
     // Get CCK fields list
     $cck_fields = apachesolr_cck_fields();
 
-    $result = self::getNodesToIndex($namespace);
+    $result = self::getNodesToIndex($namespace, $nid);
     $count = 0;
     while ($row = db_fetch_object($result)) {
       // Variables to track the last item changed.
@@ -216,12 +227,21 @@ class ApacheSolrUpdate {
           module_invoke_all('apachesolr_update_index', &$document, $node);
 
           $fields = array('title', 'body', 'type', 'uid', 'changed', 'nid', 'comment_count', 'name');
+
+          // Determine what other fields that have been bound to the node that should be indexed and able to be queries against.
+          // This should be an array in the format of: array('<field_name>' => array('name' => '<field_name>', 'field_type' => '<field_type>'))
+          //  <field_name> = this would be the full name of the field
+          //  <field_type> should be a valid cck content type ... generally this is either 'text' or 'number_integer'
+          $addl_fields = module_invoke_all('apachesolr_node_fields');
+
           foreach ((array)$node as $key => $value) {
+            //node fields
             if (in_array($key, $fields)) {
               $document->$key = $value;
             }
 
-            if ($cck_fields && strpos($key, 'field_') === 0) {
+            //cck fields
+            if (($cck_fields && strpos($key, 'field_') === 0)) {
               // Got a CCK field. See if it is to be indexed.
               if (in_array($key, array_keys($cck_fields))) {
                 $function = $cck_fields[$key]['callback'];
@@ -243,10 +263,28 @@ class ApacheSolrUpdate {
                       }
                     }
                   }
-                }
+                }               
               }
-            }
-          }
+            }//end - cck
+            
+            //additional node fields
+            if (($addl_fields && count($addl_fields) > 0)) {
+              // Got a CCK field. See if it is to be indexed.
+              if (in_array($key, array_keys($addl_fields))) {
+                $function = $addl_fields[$key]['callback'];
+                if ($addl_fields[$key]['callback'] && function_exists($function)) {
+                  $dynamic_fields = call_user_func_array($function, array($node, $key));
+                }
+                else {
+                  $dynamic_fields = $node->$key;
+                }
+                $index_key = apachesolr_index_key($addl_fields[$key]);
+                $document->$index_key = $value;
+              }//end - if key in addl_fields
+            }//end - if addl_fields
+            
+          }//end - foreach
+          
           if (is_array($node->taxonomy)) {
             foreach ($node->taxonomy as $term) {
               $document->setMultiValue('tid', $term->tid);

