Index: apachesolr_attachments.module =================================================================== --- apachesolr_attachments.module (revision 15134) +++ apachesolr_attachments.module (working copy) @@ -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($node, $op // 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_attachments watchdog('Apache Solr Attachments', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); } } - Index: apachesolr_attachments.admin.inc =================================================================== --- apachesolr_attachments.admin.inc (revision 15134) +++ apachesolr_attachments.admin.inc (working copy) @@ -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_index() { */ 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(); @@ -478,4 +497,3 @@ function apachesolr_attachments_extract_using_solr $response = $solr->makeServletRequest(EXTRACTING_SERVLET, $params, 'POST', $headers, $data); return array($response->extracted, $response->extracted_metadata); } -