Is there a way to prevent Drupal from truncating the search results?

That is, I do not want the search results shortened with a "..." added to the end of the result. I would like the full text.

Cheers in advance.

2 Answers 2


Yes, there is. Copy the /modules/search/search-result.tpl.php file into your theme directory. Then modify it like this:

  <?php /* this is just so it will be easier to access the body of the node */ ?>
  <?php $node = $variables['result']['node']; ?>
  <li class="<?php print $classes; ?>"<?php print $attributes; ?>>
  <?php print render($title_prefix); ?>
  <h3 class="title"<?php print $title_attributes; ?>>
    <a href="<?php print $url; ?>"><?php print $title; ?></a>
  <?php print render($title_suffix); ?>
  <div class="search-snippet-info">
  <?php if ($snippet): ?>
  <p class="search-snippet"<?php print $content_attributes; ?>>
    <?php /* this part is modified, you could display different data then the body */ ?>
    <?php print $node->body[$node->language][0]['safe_value']; ?>
  <?php endif; ?>
  <?php if ($info): ?>
    <p class="search-info"><?php print $info; ?></p>
  <?php endif; ?>

Note Like I said in the comment, it's easy to display content from some other field, not just the body. To see what data you have to play with do:

 <?php echo '<pre>';
       echo '</pre>';

You can rewrite the snippet by preprocessing the search results. Replace test in the module name below with the name of your module and you'll be good to go. I don't really know my way around D7 yet, but I think the 'und' part of the node array implies that you're only using one language on your site.

function test_preprocess_search_result(&$variables) {
  $variables['snippet'] = $variables['result']['node']->body['und'][0]['safe_value'];
  • Both are still valid @KristerAndersson sometimes people prefer a theme solution rather than a module solution.
    – Malks
    Dec 8, 2011 at 0:59
  • That's true, I actually tried the theme_preprocess_search_result at first but I like templates=) Dec 8, 2011 at 1:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.