Firstly, thank you for all the work that has been going into this module - what a fantastic replacement for the core search!

Secondly, I would like to add images to the display of (some) our search results without having to consult MySQL at all. In order to so, would I need to add the actual 'filename' for the content type $node->field_playerimage[0]['filename'] to schema.xml:

<field name="filename" type="text" indexed="false" stored="true"/>

And then add them to the 'fl params?' (Where do I edit the 'fl params?'

Thank you again!

Comments

robertdouglass’s picture

fl can be modified using

function alzsearch_apachesolr_modify_query(&$query, &$params, $caller) {

You can also add stuff to be indexed using something like this:

function hook_apachesolr_update_index(&$document, $node) {
      if (isset($node->field_playerimage[0]['filename'])) {
          $field = array(
            'index_type' => 'string',
            'multiple' => FALSE,
            'name' => 'field_playerimage',
          );
          $index_name = apachesolr_index_key($field);
          $document->{$index_name} = $node->field_playerimage[0]['filename'];
        }
      }
}
reinholdlange’s picture

robertDouglass - this worked like the charm. The image field was indexed and is accessible via the Solr admin page (in the XML output. One remaining question is how would I display this field:

ss_field_playerimage

in the search results?

Thank you once more!

robertdouglass’s picture

Version: 6.x-1.0-rc2 » 6.x-2.x-dev
Component: schema.xml » Code

For that you need to theme the search results using theme('search_result') http://api.drupal.org/api/function/template_preprocess_search_result/6

In the override you munge the field name back (field_playerimage) and use content_format('field_rm_category', $fieldvalue); to display it.

The whole document (including the cck field that has been indexed) should be in the search results. Here's the pertinent code from apachesolr_search_process_response:

      // Allow modules to alter each document and its extra information.
      drupal_alter('apachesolr_search_result', $doc, $extra);
      $results[] = array(
        'link' => url($doc->path),
        'type' => apachesolr_search_get_type($doc->type),
        'title' => $doc->title,
        'user' => theme('username', $doc),
        'date' => $doc->created,
        'node' => $doc,
        'extra' => $extra,
        'score' => $doc->score,
        'snippet' => $snippet,
      );

So you can see that there is a drupal_alter for you to hook into, as well as the 'node' key in the search result.

By the way - the DRUPAL-6--2 branch is more developer friendly. This code I've pasted is from DRUPAL-6--2 and might not work on DRUPAL-6--1. I'm changing the version and component of the issue to reflect this.

reinholdlange’s picture

robertDouglass - thank you ever so much for taking the time to reply. This is really exciting stuff and I am pleased to be learning about it. - I am however not able to find the image field (field_playerimage) in the search results array...?

Thank you very much!

jpmckinney’s picture

Status: Active » Fixed

For ss_field_playerimage to show up in the search result array, you must add it to the fl parameter:

function hook_apachesolr_modify_query(&$query, &$params, $caller) {
  $params['fl'] .= ',ss_field_playerimage';
}

You can then access it in search-result.tpl.php at:

$result['node']->ss_field_playerimage;

Status: Fixed » Closed (fixed)

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