We managed to solve this with help from user Gaele Strootman.
There are three steps to solve this:
1) add the image to the solr index using a custom module
2) add the image field to your apache solr view
3) add a template file for the image field that displays the actual image
ad 1) create a custom module to add images to the solr index.
You only need two files, my_module.info and my_module.module. We name the image field ss_field_image_uri.
my.module.info:
name = Apache Solr Image
description = Add image field to the solr index so we can display images in search results
package = Apache Solr
core = 7.x
dependencies[] = apachesolr_search
my_module.module:
<?php
/**
* Add field_image uri to apache solr index, so that we can later display image in search results or custom apache solr views page.
* @see apachesolr.api.php
*/
function apachesolr_image_apachesolr_index_document_build($document, $node, $namespace) {
if (isset($node->field_image['und']['0']['uri'])) $document->addField('ss_field_image_uri', $node->field_image['und']['0']['uri']);
}
?>
ad 2) add the image field to your apache solr view
First re-index solr so the images actually get indexed and show up. Then add the image field to your view.
ad 3) add a template file for the image field that displays the actual image
This is the template we added. Since the field is called ss_field_image_uri the template name is: views-view-field--ss-field-image-uri.tpl.php. This is the code:
<?php
/**
* @file
* This template is used to print a single field in a view.
*
* It is not actually used in default Views, as this is registered as a theme
* function which has better performance. For single overrides, the template is
* perfectly okay.
*
* Variables available:
* - $view: The view object
* - $field: The field handler object that can process the input
* - $row: The raw SQL result that can be used
* - $output: The processed output that will normally be used.
*
* When fetching output from the $row, this construct should be used:
* $data = $row->{$field->field_alias}
*
* The above will guarantee that you'll always get the correct data,
* regardless of any changes in the aliasing that might happen if
* the view is modified.
*/
?>
<?php
/**
* For additional parameters see
* http://api.drupal.org/api/drupal/modules!image!image.field.inc/function/theme_image_formatter/7
*/
?>
<?php $variables = array('item' => array('uri' => $row->{$field->field_alias})); ?>
<?php $variables['image_style'] = 'thumbnail'; ?>
<?php print theme_image_formatter($variables); ?>
Now clean your caches and the images should show up in your apache solr view. Note that you can change the image style in the code from 'thumbnail' to whatever image style you like.
Hope this helps anyone!