You are here

function ds_search_process_results in Display Suite 7.2

Process results on behalf of Apache Solr.

1 call to ds_search_process_results()
ds_search_apachesolr_search_page_alter in modules/ds_search/ds_search.module
Implements hook_apachesolr_search_page_alter(&$build, $search_page).

File

modules/ds_search/ds_search.module, line 702
Display Suite search.

Code

function ds_search_process_results($results) {
  $processed_results = array();
  if (is_array($results) && !empty($results)) {
    foreach ($results as $result) {
      $load = entity_load($result['fields']['entity_type'], array(
        $result['fields']['entity_id'],
      ));
      $entity = reset($load);
      if (!$entity) {
        watchdog('ds_search', "Empty entity loaded from results, possibly corrupt solr index? (@entity_type, @id)", array(
          '@entity_type' => $result['fields']['entity_type'],
          '@id' => $result['fields']['entity_id'],
        ), WATCHDOG_DEBUG);
        continue;
      }

      // Add the snippet, url and extra info on the object.
      $entity->search_snippet = $result['snippet'];
      $entity->search_extra = $result['extra'];
      $entity->search_as_url = $result['fields']['url'];
      $entity->entity_type = $result['fields']['entity_type'];
      $entity->entity_id = $result['fields']['entity_id'];

      // Add the original result on the entity too in case this is a file
      // entity. Attachments have brittle support as the file entity only
      // exists in media 1.x or file entity 2.x. Because of that, we're
      // most likely will render files through theme('search_result').
      if ($result['fields']['entity_type'] == 'file') {
        $entity->original_result = $result;
      }

      // Apache Solr multisite support.
      if (variable_get('ds_search_apachesolr_multisite')) {

        // Pass along the uri path in case some people want to
        // do cool stuff themselves.
        $entity->uri['path'] = $entity->search_as_url;
        $entity->uri['options'] = array();

        // Prefix with site hash so we don't override same id's.
        $markup = $result['fields']['tm_ds_search_result'][0];
        $processed_results[$result['fields']['id'] . '-' . $result['fields']['entity_id']] = array(
          '#markup' => $markup,
          '#site_hash' => $result['fields']['hash'],
        );
      }
      else {
        $processed_results[$result['fields']['id'] . '-' . $result['fields']['entity_id']] = $entity;
      }
    }
  }
  return $processed_results;
}