How to create a new result type in SharePoint Server 2013
This is a blog post in the series "How to change the way search results are displayed in SharePoint Server 2013." To demonstrate how you can customize your search results, I'll use examples from an internal Microsoft Search Center.
For an overview of the blog posts in this series, go to How to change the way search results are displayed in SharePoint Server 2013.
In the previous blog post, I explained how item display templates and hit highlighting work. In this blog post we'll learn:
- About the Search Center example in this series
- How to copy a default item display template
- How to create a result type
About the Search Center example in this series
To help explain how you can customize the way search results are displayed, I’ll use examples from a tool that I use on a daily basis: an internal list of Microsoft publications.
As you know, Microsoft publishes thousands of articles across TechNet, MSDN and office.com. To assist in the publishing process, we use several SharePoint lists. Each item in a list represents an article or a media file. To make it easy to find information about a particular list item, we created a Search Center that searches across these lists.
In our first version of the Search Center, all the search results were displayed identically. This was because by default, all list items belonged to the same SharePoint List Item result type. We wanted to change this so that just by glancing at the search results, we could distinguish between an article published on TechNet and an article published on MSDN. We also wanted to add important information about each search result that would be visible without having to select and open it.
Before we did anything in SharePoint, we sat down for a planning session. The first step was to decide how we wanted to categorize our search results. We came up with the following categories:
|TechNet content||Articles that have been published on the TechNet platform|
|MSDN content||Articles that have been published on the MSDN platform|
|Office.com content||Articles that have been published on the office.com platform|
|Images content||Images that are used in publications|
|Video content||Videos that are used in publications|
|Download content||Downloadable content|
Once we had defined the categories, we then needed to distinguish the categories from each other. Items in our list contain a site column named Distribution Channel. This site column contains the value of the platform to which an article has been published, for example TechNet Library.
We decided that we would use values from the Distribution Channel site column to distinguish the categories from each other.
With these decisions in hand, I set out to create new result types for each of the categories. The procedure for creating a new result type is identical for all categories, so to save space, I will only show you how I created the TechNet content result type.
How to copy a default item display template
Before you create a new result type, you should create a new item display template that your new result type will use. To avoid having to create a new item display template from scratch, you can copy an existing one. Try to copy an item display template that is as close as possible to the type of content you have. Here's what you should do:
- Copy a default item display template.
In my scenario, I wanted to customize search results for SharePoint list items. From this reference table I was able to determine that the default item display template that is used by the SharePoint List Item result type is the file named Item_Default. Because I had mapped my network drive, I could easily copy the Item_Default file in Windows Explorer.
- Rename your newly created item display template.
- Open the new display template and change the <title> tag. Remember, the text in this tag is what will be shown when you do configurations in the SharePoint UI.
In my scenario, I changed the <title> tag to TechNet content.
- Save the new item display template.
Now that we have created a new item display template, we can move on to creating a new result type.
How to create a result type
Depending on your permission level, you create a result type on two levels:
|Permission level||Where the result type will be added|
|Site collection administrator||To all sites within a site collection|
|Site collection owner||To a single site|
To save space, I will only show you how to create a result type as a Site collection administrator.
- Go to Site settings --> Search Result Types.
Instead of creating a new result type from scratch, you could make your life a bit easier by copying an existing result type and modifying it to fit your new result type. If you do this, ensure that you copy a result type that closely resembles the new result type you want to create.
- On the Manage Result Types page, from the result type menu field, select Copy.
In my scenario, I wanted to customize search results for SharePoint list items, so I copied the SharePoint List Item result type.
- On the Add Result Type page, here's what you need to do:
- In the Give it a name field, enter a name for your new result type.In my scenario, I entered TechNet content.
- From the Which source should results match menu, select the result source that you have used to configure the query in your Search Result Web Part.
- In the What types of content should match? You can skip this rule to match all content menu, all the default result type are listed.
In my scenario, I chose Select a value.
- Click Show more conditions.
This opens up a menu where you can specify the result type based on managed property values.
In my scenario, all list items contain a site column called Distribution Channel. As I showed you at the beginning of this blog, this site column contains the publication platform value, for example TechNet Library. I wanted to use values from this site column to specify which list items should belong to my new result type
- From the Which custom properties should match menu, I selected DistributionChannelOWSCHCS. DistributionChannelOWSCHCS is the managed property that represents the Distribution Channel site column. In the fields below, I entered all the values that should specify the new TechNet content result type.
- From the What should these results look like menu, select the display template that should be used by this result type.In my scenario, I selected my newly created TechNet content display template.
- Click Save.
Your newly created result type is now listed on the Managed Result Types page.
In my scenario, I could see that the TechNet content result type had been created.
So now that we have a new result type, the next step is to modify the display template that is associated with this result type. There are different ways you can go about doing this, so in the next two blog posts, I'll explain two different options.
Next blog post in this series How to display values from custom properties in search results - option 1