You are here

function apachesolr_attachments_apachesolr_process_results in Apache Solr Attachments 6

Same name and namespace in other branches
  1. 5 apachesolr_attachments.module \apachesolr_attachments_apachesolr_process_results()
  2. 6.2 apachesolr_attachments.module \apachesolr_attachments_apachesolr_process_results()

Implementation of hook_apachesolr_process_results().

When using the Apache Solr search module, everything is treated as a node and as such values like the link and type won't be configured correctly if it is a file attachement. We override such values here as needed.

File

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

Code

function apachesolr_attachments_apachesolr_process_results(&$results) {
  foreach ($results as &$item) {
    if (isset($item['node']->ss_filemime)) {
      $nid = $item['node']->nid;
      $item['link'] = file_create_url($item['node']->path);
      $node_link = t('<em>attached to:</em> !node_link', array(
        '!node_link' => l($item['node']->ss_file_node_title, 'node/' . $nid),
      ));
      $icon = theme('filefield_icon', array(
        'filemime' => $item['node']->ss_filemime,
      ));
      $file_type = t('!icon @filemime', array(
        '@filemime' => $item['node']->ss_filemime,
        '!icon' => $icon,
      ));
      $item['snippet'] .= '<span>' . $file_type . ' ' . $node_link . '</span>';
      $item['extra'] = array();
      $item['type'] = t('File attachment');
    }
  }
}