apachesolr_image.module in Apache Solr Search 6
File
contrib/apachesolr_image/apachesolr_image.module
View source
<?php
function apachesolr_image_apachesolr_update_index(&$document, $node, $namespace) {
if ($node->type == 'image' && $document->entity == 'node') {
$areas = array();
$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;
$document->ss_image_absolute = file_create_url($image_path);
}
}
}
function apachesolr_image_apachesolr_modify_query(&$query, &$params, $caller) {
$params['fl'] .= ',ss_image_relative';
}
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"/>';
}
function apachesolr_image_theme() {
return array(
'apachesolr_image_snippet' => array(
'arguments' => array(
'item' => NULL,
),
),
);
}
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.'));
}