Refining Search Results with View Modes

YaleSites utilizes the Drupal Core Search feature that allows site visitors to search using keywords that are found on your site. However, what if you want a specific page to display when a related keyword is used to Search but that keyword is not used on a page within the site? You can add a hidden field to any Content Type and expose that field only in the Search Results and Search Index View Modes. This will allow you to add terms that are not part of a page but related to the content to ensure that page displays in the search results if the keyword is used in the search.

What are View Modes?

View Modes is a Drupal Core feature that allows you to control what is seen or utilized on a page display based on the context in which it is viewed – i.e. full pages or teasers. Additional View Modes are available based on the Modules you have enabled.

Standard View Modes

The following lists the View Modes that are available as part of Drupal Core:

  • Full content: This is normally used only when visiting the URL for a particular node.
  • Teaser: This is used on two list types – the front page and taxonomy term lists.
  • RSS: These settings are used when including the node in RSS feeds.
  • Search index: This is used when Drupal’s Search module indexes content on the site. Fields that are hidden in this view mode will not be searchable.
  • Search result: This is used when presenting search results on the website.

In this tutorial we will focus on the Search Index and Search Result View Modes to optimize the search results for your site using the Search and Custom Search Modules.

Creating a Keywords Field

The first step to optimizing your search results is to create a Keywords field. Here you will place words that describe and give information about other data but are not found within that specific page.

  1. Structure > Content Types > choose a specific content type > Manage fields
  2. Add a Long Text type field, call it Keywords and use the default values.
    Add Keyword field

Configuring View Modes

Configuring View Modes is fairly straightforward regardless of the Module enabled. View Modes can be found as part of the structure of a Content Type in the Vertical Tile labeled Custom Display Settings.

View modes - custom display settings

Click on the Search Index and Search Result check boxes and save the configuration. You will notice new tabs at the top of your Manage Display configuration page.

View modes - search index settings

Click on each tab and drag the fields that you do not want in to search to the Hidden section. In this example, we will only display the Body and Keywords field, all the others are in the Hidden section. Save the configuration.

View modes - assign field settings

Do the same for the Search Results View Mode.

View modes - search only these field settings

Re-indexing your Site

The site will need to be re-indexed in order for the search results to display. This happens automatically overnight but may take more than one night depending on the size of your site.