Project:Apache Solr Search Integration
Version:6.x-2.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)
Issue tags:imagessearch, theme search results

Issue Summary

I just started to explore the great opportunities of solr. I'm looking for a way to provide a imagesearch, just like here:
http://www.mattel.com/search/apachesolr_search/ken
I'm already working with the views-integrations-module, but there seems no out-of-the-box way to theme the images that way. I found the ApacheSolr Image integration module but it seems to be under development and is not working at the moment. I even don't know if it is what I'm searching for. I'm afraid I might just have missed the easy solution, if not it might be great if someone could help me to find the difficult solution. Thank You in advance,

Comments

#1

Maybe checkout the node display module, which integrates with apachesolr.

I was able to get images to load in our search results by doing something like:

function theme_preprocess_search_result(&$variables) {}

and then in that function:

$node = node_load($result['node']->nid);

#2

Status:active» fixed

apachesolr_image.module offers theme_apachesolr_image_snippet($result). In search-result.tpl.php, you can call:

<?php
print theme_apachesolr_image_snippet($result);
?>

And it will print your image. You can, of course, override this theme function in your theme.

If you just want the path to your image, that is stored in (if being accessed from search-result.tpl.php):

<?php
$result
['node']->ss_image_relative;
?>

#3

What if you are not using the image module for images? I am using imagefield and cck, because it is easily compatible with Ubercart, and I have not seen any easy way to show an image.

#4

Status:fixed» active

Sorry, I just need a little bit of help with this.

#5

Well, do you know how to access your CCK image field with code? What does this output:

<?php
$node
= node_load($result['node']->nid);
print_r($node->field_NAME_OF_YOUR_FIELD[0]);
?>

#6

Hey, that is helpful... I think this gives me what I need. I don't know, but I have heard that node_load() is a little bit performance intensive. If I am adding this to show images on a listing page, am I not defeating some of the point of using apache solr in the first place, since I am touching the database every time I run that?

Thanks.
Sean

#7

Yes, there is a performance concern with using node_load(). Here's how to avoid a node_load():

Once you know your image field, you can add the value of that field to the Solr index:

<?php
function mymodule_apachesolr_update_index(&$document, $node, $namespace) {
 
$document->ss_image_path = $node->field_...;
}
?>

And in your search-result.tpl.php:

<?php
print theme('image', file_create_url($result['node']->ss_image_path));
?>

#8

Thank you very much... that is very helpful.

Sean

#9

Status:active» fixed

And I can set this back to fixed now.

#10

Hey JP,
Where should I put that code you mention on comment #7? :S

<?php
function mymodule_apachesolr_update_index(&$document, $node, $namespace) {
 
$document->ss_image_path = $node->field_...;
}
?>

#11

Hi pyrello!
Were you able to theme your search result to appear like the link you provided? If you did, please share how you achieved it.

#12

@gilcpd: that code should go in a custom module. The module developer's guide has instructions on how to create a custom module: http://drupal.org/developing/modules

Of course, that snippet of code will not work until you fill in the field_... part. In #5, I have some code that you can put in your search-result.tpl.php to help you find where your image path is stored.

#13

Hey JP,
Im sorry to bug you but I might be doing something wrong.. can you please help me out?
I created a module called "imageindexer":
I created a folder with the same name, a .info file:

;$Id: imageindexer.info $

name = Solr Image Indexer
package = Apache Solr
description = Updates Solr index with the indexed node's picture.
core = 6.x
dependencies[] = apachesolr

a imageindexer.module:
<?php
// $Id: solr_image_indexer.module,v 1.1 2010/01/13 23:02:14 gilcpd Exp $

function imageindexer_apachesolr_update_index(&$document, $node, $namespace) {
  $document->ss_image_path = $node->field_image;
}

I added the line:

<?php
print $result['node']->ss_image_path;
?>

to my result.tpl.php page

But nothing happends... I also have one question. I assume this module will add the pictures of nodes to the index, how can it be modified to also index the pictures of users?

Again thank you very very much.

#14

try with display suite , you can easily make with search results everything (out of box solution)
http://drupal.org/project/ds (something like panels)

i have attached my results page

(problem is, i you dont want use DS as solution for node display, it's not perhaps good to put this module only for use with apachesolr

AttachmentSizeStatusTest resultOperations
example.JPG106.04 KBIgnored: Check issue status.NoneNone

#15

<?php
function imageindexer_apachesolr_update_index(&$document, $node, $namespace) {
 
$document->ss_image_path = $node->field_image;
}
?>

field_image is an array. You need to index into it to get the path to the image.

You need something like this:

<?php
function imageindexer_apachesolr_update_index(&$document, $node, $namespace) {
 
$document->ss_image_path = $node->field_image[0]['value'];
}
?>

But I'm not sure how imagefield uses CCK. Maybe it's actually:

<?php
function imageindexer_apachesolr_update_index(&$document, $node, $namespace) {
 
$document->ss_image_path = $node->field_image[0]['src'];
}
?>

#16

Hey Val,
thanks for the tip! I used the display module and the search is just like I wanted.
http://www.rgreenroom.com/search/apachesolr_search/?filters=type%3Atheater

There is only one thing, but I believe it is a DS bug, I selected to deny the user tab but its now showing 2 search forms, otherwise perfect, even the speed is good.
Im heading to the DS project page to check that bug.

Thanks again.

#17

This is just not working for me. I am working on trying to get this to work for another issue that I am also working on (#801172: Show images in More Like This block). It is difficult because I am pretty sure that I am not getting that one to work because I am not getting this to work.

Here is the code from my custom apachesolr module:

<?php
function MYMODULE_apachesolr_apachesolr_update_index(&$document, $node, $namespace) {
 
$document->ss_image_path = $node->field_image_cache[0]['filepath'];
    if (
module_exists('ubercart')) {
        if(!empty(
$node->ordering)) {
           
$document->fs_uc_position = $node->ordering;
        }
    }
}
?>

I have verified that to get to the image path you need to use $node->field_image_cache[0]['filepath'] by putting

<?php
print_r
($node->field_image_cache[0]['filepath']);
?>

this in my MYTHEME_preprocess_search_result function. This shows a file path for each search result on the page. I have visited /admin/reports/apachesolr/index to verify that $document->ss_image_path is getting indexed (last count was 902 items).

I am also going to include the code I am using for the other issue:

<?php
function MYTHEME_apachesolr_mlt_recommendation_block($docs) {
 
$links = array();
  foreach (
$docs as $result) {
   
// Suitable for single-site mode.
   
dsm($result->ss_image_path);
   
$links[] = l(theme('image', $result->ss_image_path, $result->title, $result->title), $result->path, array('html' => TRUE));
  }
  return
theme('item_list', $links);
}
?>

As you can see, I am calling the dsm() function to show the value of $result->ss_image_path and what is returned is a bunch of empty list items.

I don't consider myself to be stupid, but this is making me feel kind of stupid. What am I doing wrong? From everything that is contained in this thread, and the other one, it looks like this should be working, but it is not.

Thanks very much in advance for any assistance!

Sean

#18

What do you see if you dsm($docs)?

#19

    * Caches cleared.
    *  ... (Array, 5 elements)

                  0 (Object) Apache_Solr_Document
             
                  1 (Object) Apache_Solr_Document
              
                  2 (Object) Apache_Solr_Document
             
                  3 (Object) Apache_Solr_Document
              
                  4 (Object) Apache_Solr_Document
        
            Krumo version 0.2a | http://krumo.sourceforge.net
            Called from /home/epicclic/public_html/sites/all/themes/epicclick_us/template.php, line 135 

I can't click into any of the Apache_Solr_Document items.

#20

I think you also have to modify the query in order to get the stored field back in the results.

Maybe this'll help:

/**
* Implementation of hook_apachesolr_modify_query().
*/
function mymodule_apachesolr_modify_query(&$query, &$params, $caller) {
  if ($caller == 'apachesolr_search') {
    $params['fl'] .= ',ss_image_path';
  }
}

#21

Is this something that requires me to reindex, or should it start working right away?

Sean

#22

Okay, once I dropped the if ($caller... it worked. I don't know if that is because I am calling it from a block embedded in a node display on the product page, or what.

Thanks very much for your help. This is one of the top requests by my client.

Sean

#23

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#24

Component:Images» Code

#7 is a good starting point, however i used this http://drupalconnect.com/blog/steve/adding-custom-fields-apache-solr-sea...
I needed MYMODULE_apachesolr_modify_query to add the new field to the $result object.

nobody click here