You are here

apachesolr_image.module in Apache Solr Search 6

File

contrib/apachesolr_image/apachesolr_image.module
View source
<?php

/**
 * Implementation of hook_apachesolr_update_index().
 */
function apachesolr_image_apachesolr_update_index(&$document, $node, $namespace) {
  if ($node->type == 'image' && $document->entity == 'node') {
    $areas = array();

    // A problem here - small images do not get a derived thumbnail.
    $sizes = image_get_derivative_sizes($node->images['_original']);
    foreach ($sizes as $name => $info) {
      $areas[$name] = $info['width'] * $info['height'];
    }
    asort($areas);
    $image_path = FALSE;
    foreach ($areas as $preset => $size) {
      $image_path = $node->images[$preset];
      break;
    }
    if ($image_path) {
      $document->ss_image_relative = $image_path;

      // Support multi-site too.
      $document->ss_image_absolute = file_create_url($image_path);
    }
  }
}

/**
 * Implementation of hook_apachesolr_modify_query().
 */
function apachesolr_image_apachesolr_modify_query(&$query, &$params, $caller) {

  // Also retrieve image thumbnail links.
  $params['fl'] .= ',ss_image_relative';
}

/**
 * Implementation of hook_apachesolr_process_results().
 */
function apachesolr_image_apachesolr_process_results(&$results) {
  foreach ($results as $index => $item) {
    if ($item['node']->type == 'image' && !empty($item['node']->ss_image_relative)) {
      $results[$index]['snippet'] = theme('apachesolr_image_snippet', $item);
    }
  }
}
function theme_apachesolr_image_snippet($item) {
  return '<span class="apachesolr-image-result">' . theme('image', $item['node']->ss_image_relative, $item['title'], $item['title'], array(
    'align' => 'left',
  )) . '</span>' . $item['snippet'] . '<br clear="all"/>';
}

/**
 * Implementation of hook_theme().
 */
function apachesolr_image_theme() {
  return array(
    'apachesolr_image_snippet' => array(
      'arguments' => array(
        'item' => NULL,
      ),
    ),
  );
}

/**
 * Implementation of hook_enable().
 */
function apachesolr_image_enable() {
  drupal_set_message(t('The Apache Solr image integration module will not have any apparent effect until Image type nodes are indexed or re-indexed.'));
}

Functions

Namesort descending Description
apachesolr_image_apachesolr_modify_query Implementation of hook_apachesolr_modify_query().
apachesolr_image_apachesolr_process_results Implementation of hook_apachesolr_process_results().
apachesolr_image_apachesolr_update_index Implementation of hook_apachesolr_update_index().
apachesolr_image_enable Implementation of hook_enable().
apachesolr_image_theme Implementation of hook_theme().
theme_apachesolr_image_snippet