This is a blog post in the series "How to change the way search results are displayed in SharePoint Server 2013 and SharePoint Online."
For an overview of the blog post in this series, go to How to change the way search results are displayed in SharePoint Server 2013.
In this blog post, we’ll learn:
- How search results are displayed by default
- About controlling how search results are displayed
- About result types
- About the connections between a result type and display templates
- About display templates that are used by all result types
- About display template settings in the Search Results Web Part
When you search for something in a Search Center, your results are displayed differently. For example, in the screenshot below, notice how the icons for Word, PDF, and Excel are displayed for each results.
By hovering over the first result, more information about the search result is displayed.
By hovering over the fourth result, the information that is displayed is different from what you saw when you hovered over the first result.
What’s going on here, and what’s making the search results display so differently? Well, that’s what I’ll explain in this blog post.
About controlling how search results are displayed
Search results are displayed in a Search Results Web Part. The following screenshot shows how SharePoint uses two display templates to control how information about search results should be displayed:
- Item display template - used to control how you want information in the body of the Search Results Web Part to be displayed.
- Hover display template - used to control how you want information in the hover panel to be displayed.
There are 90 default search display templates available. This might seem like a lot, but I’ll explain why there are so many later. To see all the default search display templates, go to Site settings --> Master pages and page layouts. In the Master Page Gallery, click Display Templates --> Search.
I’ll explain how display templates work in later posts. For now, let’s move on to result types.
If a user is able to see information about search results directly on the search results page, this will save them the hassle of having to click and open each item to see what it’s about. If you look back at the example in the first section, you can easily see that the first two results are PowerPoint presentations, and that the third result is a Word document.
To display search results differently, search results have to be sorted into different result types. A result type distinguishes one search result from another. For example, if a search result is found in a Microsoft Word document, that search result belongs to the Microsoft Word result type. If a search result is found in a PDF file, that search result belongs to the PDF result type.
There are 31 default result types. To see them, go to Site Settings --> Result Types.
For an overview of the default result types, see this TechNet article. You needn’t worry about how default search results are specified; it’s something that happens "under the Hood" in SharePoint.
It’s not possible to edit any of the default result types. However, you can copy them, and add further configurations. I’ll show you how to do this in a later blog post, but first, it’s important that you understand how result types and display templates are connected.
The mechanics of these connections are not particularly straight forward and easy to understand, but let's take a look at it in a step-by-step manner.
- Each result type contains a reference to an item display template, for example, Item_PowerPoint.
- Each item display template contains a reference to a hover panel display template, for example, Item_PowerPoint_HoverPanel.
Let’s start with the first connection. To see the connection between a result type and an item display template, go to Site Settings --> Result Types. Select to view a result type, for example Microsoft PowerPoint.
On the Result Type page, in the Display template URL section, you’ll see that there’s a URL that points to a file named Item_PowerPoint.js.
This URL is a reference to an item display template. This means that all search results that belong to the Microsoft PowerPoint result type will be displayed by using the Item_PowerPoint.js display template.
If you look in the Master Page Gallery, you’ll see the Item_PowerPoint.js file and the associated Item_PowerPoint.html file.
Now for the second connection. To see the connection between an item display template and a hover panel display template, open Item_PowerPoint.html. You’ll see a reference to a hover panel display template, in this case, Item_PowerPoint_HoverPanel.js.
If you look in the Master Page Gallery, you’ll find the Item_PowerPoint_HoverPanel.js file and the associated Item_PowerPoint_HoverPanel.html file.
So now you can understand why there are so many search display templates. It’s because four display templates are connected to each result type.
For an overview of the connection between the default result types, item display templates, and hover panel display templates, see this TechNet article.
So, that was pretty straight forward. However, we’re not quite there yet. In addition to the display templates that are connected to a result type, there are additional display templates that are used by all result types.
- Each result type contains a reference to an item display template.
- Each item display template contains a reference to a hover panel display template.
...and then we need to add:
- Each item display template contains a reference to a common item display template.
- Each hover panel display template contain references to three common hover panel display templates.
These common display templates are located in the same Master Page Gallery folder as the display templates that are specific to individual result types.
Each item display template points to the common item display template. The following screenshot shows how the item display template used for the Microsoft Excel result type points to the common display template Item_CommonItem_Body.
Each hover panel display template points to three common hover panel display templates. The following screenshot shows how the hover display template used for the Microsoft Excel result type points to the three common hover panel display templates.
If all these references were a bit confusing, not to worry. In later blogs I’ll be using examples that will make it easier to understand. At this point, it’s important that you understand how result types are used to categorize different types of search results, and how result types are connected to different display templates.
Now for the easiest part of the puzzle: How does the Search Results Web Part know how to display search results based on the different result types?
On the search results page, click to edit the Search Results Web Part. In the Web Part Tool Pane, click to expand Display Templates.
So now you know about the mechanics of how search results are displayed. In my next blog post, I'll go into detail about the item display template, and I’ll also explain the magic of hit highlighting.
Next blog post in this series
Understand how item display templates and hit highlighting work