Drupal 6 – Theming search results to remove the cruft…

The default search page output contains an ‘info’ line below each result. This line contains the Author name – content type – last updated date – # comments – # attachments.

I wanted to hide most of these.
I have several contributors to the hr web site who maintain data for other folks so the default output on the search results page wasn’t ideal for us.
So displaying the name of the user who maintains the content but not the knowledgeable contact isn’t helpful. In addition, our audience doesn’t know what a ‘book page’ is. Lastly, displaying “0 attachments” or “0 comments” isn’t very helpful. Especially considering that comments are turned of on most of our pages.

So I set out to theme the search results. To do so I did a quick search on drupal.org and found that I need a local copy of /modules/search/search-result.tpl.php in my theme directory. From there I could override the search result output.

Here’s what I added above the output of the page:

    if($info_split_value == "0 comments" || $info_split_value == "0 attachments"){
    }//end if
  }//end for each

   #update the info string to hide user and content type
  //remove Author
  //remove Node type
  //rebuild the info string
  $info = implode(' - ', $info_split);?>

I essentially replaced the info line with updated data removing the cruft as it were.
The last line

$info = implode(' - ', $info_split);

I pulled from the search.module code.
Now our search results are clean.