This is a fantastic module that really improves upon Drupal's built in search. But there is one thing that would be really handy, adding additional information to the results page of the search. For example, on my site, I have listings with featured images attached to them. I would like to show this featured image as a thumbnail to the side of the title and excerpt of text. How can I accomplish this with this module. All I see is options to enable display of the following:
Content type
User
Date
Comments
Uploads

I'm guessing others would like to control the look and feel of the results text on their site. Thanks!

Comments

gauravkhambhala’s picture

Following instruction are for Drupal 7.

Copy YOUR_DRUPAL/modules/search/search-result.tpl.php file to your theme. Add following code to the before printing title in the template. Make sure you replace "field_main_image" with your field's machine name.

  <?php $image = field_get_items('node', $node, 'field_main_image');
    $output = 0;
    if(!empty($image)) {
    $output = field_view_value('node', $node, 'field_main_image', $image[0], array( // 
      'type' => 'image',
      'settings' => array(
        'image_style' => 'search_page_images',
        'image_link' => 'content',
      ),
    ));
    }
  ?>
  <?php if ($output != 0): ?>
    <div class="search-snippet-image">
      <?php print render($output); ?>
    </div>
  <?php endif; ?>

Hope this helps.

drupalfan81’s picture

Thanks for posting this! Actually after I had posted this, I continued my search and came across a few ways of doing this and ended up customizing the template, but slightly different than the way you mentioned above. I'm not sure what the $output variable is, maybe thats a D7 thing. The below is what I did for D6. But just to share what I learned I will explain below what I did. I copied the search-result.tpl.php template file from drupal core as mentioned above and copied it into my themes folder.

In this file were basically a few variables that were being printed to the screen. $info, $snippet, $url, and $title. Basically I used the default <dt> and <dd> tags to format the output on the screen and then added my CCK fields as needed. The way I did this was as follows:

Basically I wanted to output a portion of the "about" section of each node. I have a cck field called field_about where my users write the main summary of that node (or in my site's case, a user review/listing). So to output this about section I used this code:

<?php 
	 if ($result['node']->field_about[0]['value']) {
     $about = $result['node']->field_about[0]['value']; 
     $about = strip_tags($about); ?>
     <p><b>About:</b> <?php print substr($about, 0, 250); ?> </p>
     <?php } ?>

Basically I only wanted to output at most 250 characters, so I used the php substr and I also stripped the tags to make sure I wouldn't have broken HTML code upon output.

Then since I figured that out, I thought it would be cool to output the country assigned to that listing, which is actually a content taxonomy term. So it's a bit different to output that, as just printing the value would give a number and not the term. To do this, I did:

$termid = $result['node']->field_country[0]['value'];    
  		$term = taxonomy_get_term($termid);
  		$name = $term->name;
  		print $name;

That solved that problem.

I also use the fivestar widget, so I wanted to display the widget with each node (listing). So I used this:

  <?php print fivestar_widget_form($result['node']);  ?>

I also wanted to output a thumbnail of the "featured photo" of each node (listing) which I had as a image field called featured_photo. To do this, I did this:

<?php if (isset($result['node']->field_featured_photo[0]['filepath'])) { ?>
  <span class="search-image"><?php print theme('imagecache', 'thumb-big', $result['node']->field_featured_photo[0]['filepath']); ?></span>
<?php 
}

I was able to use imagecache to properly resize the image on the screen to reduce filesize.

So basically I threw all those in and used some html css to format the look and feel. I absolutely love my search result page now. LOOKS SO MUCH better than the default drupal search results and offers so much more info to my users. I HIGHLY recommend customizing this template file and really get control over your results page. I should have done this a long time ago.

Hope others stumble upon this page and find it helpful. Any feedback or recommendations would be appreciated!

gauravkhambhala’s picture

Glad that you got it working. I know this issue is posted for Drupal 6 version but still those who are looking for D7, the appraoch remains the same. I would recommend using field_view_field to load fields instead of field_featured_photo[0]['filepath'].

Refer http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way for more explaination.

loon’s picture

Status: Needs work » Closed (outdated)

D6 reached its EOL, and there is no active release for D6 for this module anymore.
Development or support is not planned for D6. All D6-related issues are marked as outdated in a bunch.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.