diff --git a/apachesolr_attachments.admin.inc b/apachesolr_attachments.admin.inc index 7876473..287adc6 100644 --- a/apachesolr_attachments.admin.inc +++ b/apachesolr_attachments.admin.inc @@ -47,6 +47,13 @@ function apachesolr_attachments_settings($form, &$form_state, $env_id) { '#description' => t("Extraction will be faster if run locally using tika."), '#default_value' => variable_get('apachesolr_attachments_extract_using', 'tika'), ); + $form['apachesolr_attachments_filesize_limit'] = array( + '#type' => 'textfield', + '#title' => t('Filesize limit (in bytes) for files to be indexed'), + '#size' => 80, + '#description' => t('If a file is larger than this limit, do not index it. The default is no limit.'), + '#default_value' => variable_get('apachesolr_attachments_filesize_limit', -1), + ); $form['apachesolr_attachments_tika_path'] = array( '#type' => 'textfield', '#title' => t('Tika directory path'), @@ -81,6 +88,9 @@ function apachesolr_attachments_settings_validate($form, &$form_state) { form_set_error('apachesolr_attachments_tika_path', t('Tika jar file not found at this path.')); } } + if (!is_numeric($form_state['values']['apachesolr_attachments_filesize_limit'])) { + form_set_error('apachesolr_attachments_filesize_limit', t('Filesize limit must be a number.')); + } } /** diff --git a/apachesolr_attachments.module b/apachesolr_attachments.module index 6873306..d220c19 100644 --- a/apachesolr_attachments.module +++ b/apachesolr_attachments.module @@ -674,6 +674,23 @@ function apachesolr_attachments_theme() { } /** + * Implements hook_apachesolr_exclude(). + */ +function apachesolr_attachments_apachesolr_exclude($entity_id, $entity_type, $row, $env_id) { + if (!$entity_id) { + return TRUE; + } + $filesize_limit = variable_get('apachesolr_attachments_filesize_limit', -1); + // load the entity and reset cache + $entities = entity_load($entity_type, array($entity_id), NULL, TRUE); + $entity = reset($entities); + if (isset($entity->filesize) && $filesize_limit > 0 && $entity->filesize > $filesize_limit) { + return TRUE; + } + return FALSE; +} + +/** * Preprocess function for theme_apachesolr_search_snippets__file(). */ function apachesolr_attachments_preprocess_apachesolr_search_snippets__file(&$vars) {