You are here

function apachesolr_attachments_test_tika_extraction in Apache Solr Attachments 7

Same name and namespace in other branches
  1. 6.3 apachesolr_attachments.admin.inc \apachesolr_attachments_test_tika_extraction()

Function to test if our extracting with tika succeeds

1 string reference to 'apachesolr_attachments_test_tika_extraction'
apachesolr_attachments_menu in ./apachesolr_attachments.module
Implements hook_menu().

File

./apachesolr_attachments.admin.inc, line 280
Provides a file attachment search implementation for use with the Apache Solr module

Code

function apachesolr_attachments_test_tika_extraction() {
  module_load_include('inc', 'apachesolr_attachments', 'apachesolr_attachments.index');
  $indexer_table = apachesolr_get_indexer_table('file');

  // Create new file
  $file = new stdClass();
  $file->uri = drupal_get_path('module', 'apachesolr_attachments') . '/tests/test-tika.pdf';
  $file->filemime = 'application/pdf';
  $file->fid = 0;
  $text = apachesolr_attachments_get_attachment_text($file);

  // Check if the text can be succesfully extracted. Only checking 1 word is
  // sufficient
  if (strpos($text, 'extraction')) {
    drupal_set_message(t('Text can be succesfully extracted'));
  }
  else {
    drupal_set_message(t('Text can not be succesfully extracted. Please check your settings'), 'error');
  }

  // Delete our test file from indexing table
  db_delete($indexer_table)
    ->condition('entity_id', $file->fid)
    ->execute();
  drupal_goto('admin/config/search/apachesolr/attachments');
}