--- C:/Users/marc/AppData/Local/Temp/apachesolr_attachments.module-rev24.svn000.tmp.module	Fri Nov 13 16:51:40 2009
+++ C:/Users/marc/AppData/Local/Temp/apachesolr_attachments.module-rev35.svn000.tmp.module	Fri Nov 13 16:51:44 2009
@@ -176,6 +176,26 @@
 }
 
 /**
+ * Implementation of hook_apachesolr_document_handlers.
+ *
+ * @param string $type
+ *   Entity type. 'node', 'comment', and so forth. Used to evaluate whether this module
+ *   should be interested in creating documents.
+ * @param string $namespace
+ *   Usually the name of the module that is initiating indexing. In this case
+ *   we want to register a handler if the namespace is 'apachesolr_search'.
+ * @return array $handlers
+ *   An array of strings that are function names. Each function returns a $document from
+ *   an entity (of type $type).
+ */
+function apachesolr_attachments_apachesolr_document_handlers($type, $namespace) {
+  if ($type == 'node' && $namespace == 'apachesolr_attachments') {
+    return array('apachesolr_attachments_add_documents');
+  }
+}
+
+
+/**
  * Hook is called by search.module to add things to the search index.
  * In our case we will search content types and add any CCK type that
  * is a file type that we know how to parse and any uploaded file
@@ -192,7 +212,7 @@
   $num_tried = 0;
   do {
     $rows = apachesolr_get_nodes_to_index('apachesolr_attachments', $cron_try);
-    $success = apachesolr_index_nodes($rows, 'apachesolr_attachments', 'apachesolr_attachments_add_documents');
+    $success = apachesolr_index_nodes($rows, 'apachesolr_attachments');
     $num_tried += $cron_try;
   } while ($success && ($num_tried < $cron_limit) && (time() - $start < $cron_time_limit));
 }
@@ -202,75 +222,72 @@
  *
  * Adds a document for each indexable file attachment for the given node ID.
  */
-function apachesolr_attachments_add_documents(&$documents, $nid) {
-  $node = node_load($nid, NULL, TRUE);
-  if (!empty($node->nid)) {
+function apachesolr_attachments_add_documents($node, $namespace) {
+  $document = FALSE;
+  $hash = apachesolr_site_hash();
 
-    $hash = apachesolr_site_hash();
+  // Since there is no notification for an attachment being unassociated with a
+  // node (but that action will trigger it to be indexed again), we check for
+  // fids that were added before but no longer present on this node.
 
-    // Since there is no notification for an attachment being unassociated with a
-    // node (but that action will trigger it to be indexed again), we check for
-    // fids that were added before but no longer present on this node.
+  $fids = array();
+  $result = db_query("SELECT fid FROM {apachesolr_attachments_files} WHERE nid = %d", $node->nid);
+  while ($row = db_fetch_array($result)) {
+    $fids[$row['fid']] = $row['fid'];
+  }
 
-    $fids = array();
-    $result = db_query("SELECT fid FROM {apachesolr_attachments_files} WHERE nid = %d", $node->nid);
-    while ($row = db_fetch_array($result)) {
-      $fids[$row['fid']] = $row['fid'];
-    }
+  $files = _asa_get_indexable_files($node);
 
-    $files = _asa_get_indexable_files($node);
+  // Find deleted files.
+  $missing_fids = array_diff_key($fids, $files);
+  if ($missing_fids) {
+    db_query("UPDATE {apachesolr_attachments_files} SET removed = 1 WHERE fid IN (". db_placeholders($missing_fids) .")", $missing_fids);
+  }
+  $new_files = array_diff_key($files, $fids);
+  // Add new files.
+  foreach ($new_files as $file) {
+    db_query("INSERT INTO {apachesolr_attachments_files} (fid, nid, removed, sha1) VALUES (%d, %d, 0, '')", $file->fid, $node->nid);
+  }
+  foreach ($files as $file) {
+    $text = _asa_get_attachment_text($file);
 
-    // Find deleted files.
-    $missing_fids = array_diff_key($fids, $files);
-    if ($missing_fids) {
-      db_query("UPDATE {apachesolr_attachments_files} SET removed = 1 WHERE fid IN (". db_placeholders($missing_fids) .")", $missing_fids);
-    }
-    $new_files = array_diff_key($files, $fids);
-    // Add new files.
-    foreach ($new_files as $file) {
-      db_query("INSERT INTO {apachesolr_attachments_files} (fid, nid, removed, sha1) VALUES (%d, %d, 0, '')", $file->fid, $node->nid);
-    }
-    foreach ($files as $file) {
-      $text = _asa_get_attachment_text($file);
+    if ($text) {
+      $document = new Apache_Solr_Document();
+      // A single file might be attached to multiple nodes.
+      $document->id = apachesolr_document_id($file->fid .'-'. $node->nid, 'file');
+      $document->url = file_create_url($file->filepath);
+      $document->path = $file->filepath;
+      $document->hash = $hash;
+      $document->site = url(NULL, array('absolute' => TRUE));
+      $document->nid = $node->nid;
+      $document->title = $file->filename;
+      $document->created = apachesolr_date_iso($file->timestamp);
+      $document->changed = $document->created;
+      $document->status = $node->status;
+      $document->sticky = $node->sticky;
+      $document->promote = $node->promote;
+      $document->uid = $node->uid;
+      $document->name = apachesolr_strip_ctl_chars($node->name);
+      $document->body = apachesolr_clean_text($file->description) .' '. $text;
+      $document->bs_file = TRUE;
+      $document->ss_filemime = $file->filemime;
+      $document->ss_file_node_title = apachesolr_clean_text($node->title);
+      $document->ss_file_node_url = url('node/' . $node->nid, array('absolute' => TRUE));
 
-      if ($text) {
-        $document = new Apache_Solr_Document();
-        // A single file might be attached to multiple nodes.
-        $document->id = apachesolr_document_id($file->fid .'-'. $node->nid, 'file');
-        $document->url = file_create_url($file->filepath);
-        $document->path = $file->filepath;
-        $document->hash = $hash;
-        $document->site = url(NULL, array('absolute' => TRUE));
-        $document->nid = $node->nid;
-        $document->title = $file->filename;
-        $document->created = apachesolr_date_iso($file->timestamp);
-        $document->changed = $document->created;
-        $document->status = $node->status;
-        $document->sticky = $node->sticky;
-        $document->promote = $node->promote;
-        $document->uid = $node->uid;
-        $document->name = apachesolr_strip_ctl_chars($node->name);
-        $document->body = apachesolr_clean_text($file->description) .' '. $text;
+      apachesolr_add_taxonomy_to_document($document, $node);
 
-        $document->bs_file = TRUE;
-        $document->ss_filemime = $file->filemime;
-        $document->ss_file_node_title = apachesolr_clean_text($node->title);
-        $document->ss_file_node_url = url('node/' . $node->nid, array('absolute' => TRUE));
+      if (module_exists('apachesolr_nodeaccess')) {
+        apachesolr_nodeaccess_apachesolr_update_index($document, $node);
+      }
+      drupal_alter('apachesolr_attachment_index', $document, $node, $file);
 
-        apachesolr_add_taxonomy_to_document($document, $node);
-
-        if (module_exists('apachesolr_nodeaccess')) {
-          apachesolr_nodeaccess_apachesolr_update_index($document, $node);
-        }
-        drupal_alter('apachesolr_attachment_index', $document, $node, $file);
-
-        $documents[] = $document;
-      }
-      else {
-        watchdog('Apache Solr Attachments', t('Could not extract any indexable text from %filepath'), array('%filepath' => $file->filepath), WATCHDOG_WARNING);
-      }
+      $documents[] = $document;
     }
+    else {
+      watchdog('Apache Solr Attachments', t('Could not extract any indexable text from %filepath'), array('%filepath' => $file->filepath), WATCHDOG_WARNING);
+    }
   }
+    return $documents;
 }
 
 /**
