? .svn
Index: apachesolr_attachments.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr_attachments/apachesolr_attachments.admin.inc,v
retrieving revision 1.4.2.4
diff -u -p -r1.4.2.4 apachesolr_attachments.admin.inc
--- apachesolr_attachments.admin.inc	3 Feb 2010 18:51:35 -0000	1.4.2.4
+++ apachesolr_attachments.admin.inc	22 Apr 2010 12:05:12 -0000
@@ -59,6 +59,24 @@ function apachesolr_attachments_settings
     '#description' =>  t("The name of the tika CLI application jar file, e.g. tika-0.3.jar or tika-app-0.4.jar."),
     '#default_value' => variable_get('apachesolr_attachments_tika_jar', 'tika-0.3.jar'),
   );
+  $form['apachesolr_attachments-content_type-settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Per content type indexing settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  foreach (node_get_types('names') as $key => $name) {
+    $form['apachesolr_attachments-content_type-settings']['apachesolr_attachments_content_type_indexing_' . $key] = array(
+      '#type' => 'radios',
+      '#title' => t('@type', array('@type' => $name)),
+      '#default_value' => variable_get('apachesolr_attachments_content_type_indexing_' . $key, APACHESOLR_ATTACHMENTS_MODE_SEPARATE_ENTITY),
+      '#options' => array(
+        APACHESOLR_ATTACHMENTS_MODE_SEPARATE_ENTITY => t('Index attachments as separate entities.'),
+        APACHESOLR_ATTACHMENTS_MODE_ON_PARENT_NODE => t('Index attachments and attach to parent node.'),
+        APACHESOLR_ATTACHMENTS_MODE_DONT_INDEX => t("Don't index attachments."),
+      ),
+    );
+  }
   $form['apachesolr_attachments-cron-settings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Cron settings'),
@@ -224,7 +242,8 @@ function apachesolr_attachements_delete_
  */
 function apachesolr_attachments_add_documents(&$documents, $nid, $namespace = 'apachesolr_attachments') {
   $node = node_load($nid, NULL, TRUE);
-  if (!empty($node->nid)) {
+  $index_mode = variable_get('apachesolr_attachments_content_type_indexing_' . $node->type, APACHESOLR_ATTACHMENTS_MODE_SEPARATE_ENTITY);
+  if (!empty($node->nid) && $index_mode == APACHESOLR_ATTACHMENTS_MODE_SEPARATE_ENTITY) {
 
     $hash = apachesolr_site_hash();
 
@@ -378,6 +397,9 @@ function apachesolr_attachments_get_cck_
  * @throws Exception
  */
 function apachesolr_attachments_get_attachment_text($file) {
+  // We need the apachesolr_clean_text function so include this file:
+  module_load_include('inc', 'apachesolr', 'apachesolr.index');
+  
   // Any down-side to using realpath()?
   $filepath = realpath($file->filepath);
   // Check that we have a valid filepath.
@@ -478,4 +500,3 @@ function apachesolr_attachments_extract_
   $response = $solr->makeServletRequest(EXTRACTING_SERVLET, $params, 'POST', $headers, $data);
   return array($response->extracted, $response->extracted_metadata);
 }
-
Index: apachesolr_attachments.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr_attachments/apachesolr_attachments.module,v
retrieving revision 1.1.4.2
diff -u -p -r1.1.4.2 apachesolr_attachments.module
--- apachesolr_attachments.module	3 Feb 2010 18:44:02 -0000	1.1.4.2
+++ apachesolr_attachments.module	22 Apr 2010 12:05:13 -0000
@@ -8,6 +8,10 @@
 
 define (EXTRACTING_SERVLET, 'extract/tika');
 
+define('APACHESOLR_ATTACHMENTS_MODE_SEPARATE_ENTITY', 1);
+define('APACHESOLR_ATTACHMENTS_MODE_ON_PARENT_NODE', 2);
+define('APACHESOLR_ATTACHMENTS_MODE_DONT_INDEX', 3);
+
 /**
  * Implementation of hook_menu().
  */
@@ -138,6 +142,44 @@ function apachesolr_attachments_nodeapi(
       // Mark attachments for later re-deletion in case the query fails.
       db_query("UPDATE {apachesolr_attachments_files} SET removed = 1 WHERE nid = %d", $node->nid);
       break;
+    case 'update index':
+      $index_mode = variable_get('apachesolr_attachments_content_type_indexing_' . $node->type, APACHESOLR_ATTACHMENTS_MODE_SEPARATE_ENTITY);
+      if ($index_mode == APACHESOLR_ATTACHMENTS_MODE_ON_PARENT_NODE) {
+
+        module_load_include('inc', 'apachesolr_attachments', 'apachesolr_attachments.admin');
+        //include_once(drupal_get_path('module', 'apachesolr') .'/apachesolr.index.inc');
+
+        // 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'];
+        }
+
+        $files = apachesolr_attachments_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) {
+          watchdog('attachements', "my_attachments_nodeapi extracting content from: " . $file->filepath );
+          $rv .= "\r\n " . apachesolr_attachments_get_attachment_text($file);
+        }
+
+        return $rv;
+
+      }
+      break;
   }
 }
 
@@ -218,4 +260,3 @@ function apachesolr_attachments_remove_a
     watchdog('Apache Solr Attachments', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
   }
 }
-
