Drupal7: Customizing Search Results Page using Display Suite

David G - DrupalRecently I’ve been updating a Drupal 6 website to Drupal 7. One of the new features is to enable site-wide searching of content (in Drupal 6 a design oversight had not included themeing for search forms — so we’re rolling that in now). There are a plethora of searching modules — but I’ve always wanted to use built-in search but tweak (without much hassle!) how the results are displayed. Today I finally utitlized the Display Suite Search submodule. Since I’m using DS on my website already, all I had to do was familiarize myself with the options DS Search provides me.

By default the Drupal search page is rather blah:

The default drupal 7 site search gives you a functional search experience.

The default drupal 7 site search gives you a functional search experience.

I would love if the search page:

  • told the visitor how many results their search produced.
  • allowed me as a site manager to tweak how each result is rendered.
  • could control per item rendered what field(s) are shown per content type.

In general the DS Search module allows me to achieve all 3 customizations. DS Search integrates/extends the Core search module and supports Apache Solr Search. On my website I limit access to content using the Rabbit Hole module.

After applying our DS Search customization my site search page appears as follows:

Final search result output after customization.

Final search result output after customization.

The output contains:

  • A total results value count, and the keyword(s) searched for.
  • highlighted search term per result.
  • per-content type result display rules.
  • similar content type results are grouped per-page of the search results.

In order to achieve this I enabled the DS Search module and altered the default Search Settings of Drupal and also the DS:Search settings:

Drupal global search settings page.

Drupal global search settings page.

In the default site search settings for Drupal we tell Drupal to use DS:Search as the module and output mechanism for searches. At any time we may “go back” to the Core mechanism if we want by simply selecting Node here.

Then for Display Suite we configure it’s search options:

Display Suite global search options settings.

Display Suite global search options settings.

Using the DS:Search settings we can do many things such as:

  • tell Drupal how to render each result item (Teaser, Full Node, Trimmed, etc).
  • Should we show the title?
  • Should we include a total results count value?
  • How about keywords?
  • Do we group results per page?

… the list goes on! What I see as nice about this is as a site administrator I do not have to write any code and I’m getting alot of customization out of the box by leveraging Display Suite throughout my website.

Lastly, if I want to change how some piece of content is shown in Search Results I again make use of DS and override the view_mode for Search Result Highlighting Input to whatever I want to show. Here is an example for my Page content type, I don’t want to show attached files if any exist on the Node on the search results page:

Customize the output per content type of search results.

Customize the output per content type of search results.

These view_modes and overriding the output of these results should feel comfortable if you’re used to using Views or creating Content Types in Drupal.

I hope you can see how flexible and powerful DS:Search can be!

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , | Posted under Drupal, Uncategorized | RSS 2.0

Author Spotlight

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com

Leave a Reply

Your email address will not be published. Required fields are marked *