Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have been banging my head on this for days now. I manage to get the images on my site indexed in solr using a custom module. Then I can add the image field in my custom solr view. So far so good.
The problem is that the field outputs as "public://folder/imagename.jpg" or so. How could I get the view to output not the link but the image itself? THis is probably some coding work but I cannot figure out how to do it. Any help very much appreciated.
Best,
Gerben
ps: this is connected to this D6 issue: http://drupal.org/node/576286
Comments
Comment #1
Gerben Zaagsma CreditAttribution: Gerben Zaagsma commentedWe 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:
my_module.module:
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:
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!
Comment #2
Gerben Zaagsma CreditAttribution: Gerben Zaagsma commentedclosing this, feel free to re-open if any issues arise.
Comment #3
sboutas CreditAttribution: sboutas commentedHi. I did all the above but in the fields in my solr view I don't see anywhere the ss_field_image_uri.
Why is that?
Comment #4
Gerben Zaagsma CreditAttribution: Gerben Zaagsma commentedCan you explain which steps you took and where it goes wrong? Did you create a custom module and enable it? And did you re-index solr after that?
Comment #4.0
Gerben Zaagsma CreditAttribution: Gerben Zaagsma commentedadded info
Comment #5
sboutas CreditAttribution: sboutas commentedI followed the first two steps of post #1. I created a custom module with the code provided and I named it apache_solr_image. Then I enabled the module, I cleared solr's index and reindex. Then I created a new view and when I press add field, I cannot find anywhere the ss_field_image_uri
Comment #6
sboutas CreditAttribution: sboutas commentedAlso, the modules that I am using are the following:
Apache Solr Access - 7.x-1.5
Apache Solr framework - 7.x-1.5
Apache Solr Image - My Custom Module
Apache Solr Link - 7.x-1.x-dev
Apache Solr Multisite Search - 7.x-1.0
Apache Solr search - 7.x-1.5
Apache Solr Views Integration - 7.x-1.0-beta2
Comment #7
sboutas CreditAttribution: sboutas commentedAny idea of how can I fix this?
Comment #8
Gerben Zaagsma CreditAttribution: Gerben Zaagsma commentedApologies for the late reply, haven't checked in for a while.
The problem could be that the module name is wrong, it should be apachesolr_image (not apache_solr_image). So you have a module folder named apachesolr_image with two files in it: apachesolr_image.info and apachesolr_image.module.
hope this helps,
Gerben
Comment #9
sboutas CreditAttribution: sboutas commentedHi Gerben. I did what you said and finally worked!!! Thank you very much for your help. Now I get the image field in the view but the image is not displayed. Maybe it has to do with the template. Where should I place this views-view-field--ss-field-image-uri.tpl.php template file? Inside the module or in another directory?
Comment #10
sboutas CreditAttribution: sboutas commentedUpdate:
I placed the template file inside the theme but now I get this error:
Notice: Undefined property: stdClass::$ss_field_image_uri in include()
Comment #11
Gerben Zaagsma CreditAttribution: Gerben Zaagsma commentedGood that you got the imahe field in the view. As for the template: you can actually check what it should be called by clicking Theme: Information in your view (bottom right of advanced section). You should place it in the templates folder inside your theme folder (where the other templates are). Also clean your caches after that.
Comment #12
sboutas CreditAttribution: sboutas commentedI checked in the Theme Information and the template is called:
Field Apache Solr: ss_field_image_uri (ID: ss_field_image_uri): views-view-field.tpl.php, views-view-field--ss-field-image-uri.tpl.php, views-view-field--multi-site.tpl.php, views-view-field--multi-site--ss-field-image-uri.tpl.php, views-view-field--page.tpl.php, views-view-field--page--ss-field-image-uri.tpl.php, views-view-field--multi-site--page.tpl.php, views-view-field--multi-site--page--ss-field-image-uri.tpl.php
But still when I am at the view the images are not loading and I get the error:
Notice: Undefined property: stdClass::$ss_field_image_uri in include()
Update:
Actually, I found out that this message is being displayed as many times as the nodes that they have empty field images. So, I have to modify somehow the template to be applied only when the field is not empty. Anyway, I still don't get thumbnails from the nodes that they actually have a field image. Below is the value example that I get from the image field:
public://image/experiment/2013/01/asacusa_0.jpg
Do you think that the problem might be the format?
I am using Apache Solr Multisite Search and the results are coming from three different sites.
Comment #13
sboutas CreditAttribution: sboutas commentedHi. Just to let you know that I have found a temporary solution.
It appears that the public://image/experiment/2013/01/asacusa_0.jpg that i get in the image field is a part of the uri, which normally is public/image/experiment/2013/01/asacusa_0.jpg
Anyway this isn't the full link to the image, so I exposed the site solr field to know from which site the image is coming from and then with the Views php I have added a php field where I wrote some code that checks the site and then creates a new image uri based on the site and part of the image field that I got from the ss_field_image_uri.
After that I rewrote the result from the php field in text to display it as a thumbnail with html code so I don't need to load any template.
As a result I got my images now displayed in solr search results :)
I believe it would be nice though if the ss_field_image could contain the complete image path in a multisite solr index.
Comment #14
Gerben Zaagsma CreditAttribution: Gerben Zaagsma commentedThe multisite thing is not something I am familiar with so can't help out there. Glad to hear you got it working anyway.
Comment #15
sboutas CreditAttribution: sboutas commented