Udostępnij za pośrednictwem


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

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:

Category Definition
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.

Distribution Channel value in a list item

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:

  1. 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.

Copy Item_Default display template

By refreshing Windows Explorer, I could see that SharePoint had automatically created an associated JavaScript file.

JavaScript file created for Item_Default display template

  1. Rename your newly created item display template.

In my scenario, I renamed it TechNet content. Again, I refreshed Windows Explorer to verify that the JavaScript file was updated accordingly.

TechNet content display templates

  1. 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.

TechNet content <title> tag

  1. 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.

  1. Go to Site settings --> Search Result Types.

Search Result Type on Site Settings page

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.

  1.  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.

Copy the SharePoint List Item result type

  1. On the Add Result Type page, here's what you need to do:
  1. In the Give it a name field, enter a name for your new result type.In my scenario, I entered TechNet content.
  2. 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.
  3. 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.
  4. Click Show more conditions.

Show More Conditions on Add Result Type page

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

    1. 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.

Add properties to specify the result type

    1. 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.

Apply display template to new result type

    1. 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.

New result type shown on page

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

 

Additional Resources Configure result sources for search in SharePoint Server 2013 Result types and display templates that are used to display search results in SharePoint Server 2013

Comments

  • Anonymous
    January 01, 2003
    Hi Michal,

    You're definitely not missing anything, rather you are completely correct. The table in was wrong, and I have now corrected it.

    Thanks a lot for letting me know :-)

    Bella

  • Anonymous
    January 01, 2003
    Hi Peter, Mmm, strange that it doesn't work.
    But yes, feel free to send me an e-mail :-) Bella

  • Anonymous
    January 01, 2003
    Hi Pablo,

    Please contact MS Support with this question.

    Thanks,
    Bella

  • Anonymous
    January 01, 2003
    Hi Hoan,

    It's difficult to say why your configuration isn't working the way you want it to work. But, if you want your custom search vertical to only show results from a particular list, you can try the following:

    - Create a custom result source for your list (http://blogs.technet.com/b/tothesharepoint/archive/2013/11/06/how-to-configure-the-search-results-web-part-to-use-a-new-result-source-in-sharepoint-2013.aspx#HowResultSource)
    - Configure your custom result type to only show search results from your newly created custom result source (on the Add Result Type page, in the Conditions section, select your custom result source)

    Hope this helps,
    Bella

  • Anonymous
    December 11, 2013
    The comment has been removed

  • Anonymous
    December 12, 2013
    Hi Peter, Yes, you can display Audio content differently in two verticals, but you have to use two result types. First you have to create: a result source for your Audio vertical.an item display template that you want to use to display items on your Audio vertical.Then you copy the Audio result type that you use in your Everything vertical, give it a new name, configure it to use your Audio vertical result source, and map it to your newly created Audio vertical item display template.   On your Audio vertical page, you map the Search Results Web Part to your Audio result source. Hope this helps. Bella

  • Anonymous
    December 12, 2013
    Bella, thank you for a quick reply. I think i have done already what you recommended, but i still don't see how my result type will only act upon a particular search vertical. Maybe i need a new approach. My actual need is to have a vertical that shows 3 media types ( Video, Audio and Images ). Lets call it "Media" vertical. I have a result source that searches for all three content types. On my Media vertical i set search result webpart to use this new result source. It works as in image here: social.msdn.microsoft.com/.../d02de983-ec36-4217-8189-7e378b8b94ad My end goal is for all three to have different display templates just on that vertical, but return their original display template everywhere else. Video --> item_video.html, copy/modify it and use in new vertical Picture --> item_picture.html, copy/modify it and use in new vertical Audio --> doesn't have one, i created an item_audio.html based on item_default.html I think it would be great if you can post a follow up article on how to accomplish this in your great series. Would it be ok to contact you directly through email, i have access to MS AD. Thank you.

  • Anonymous
    December 27, 2013
    Pingback from How to create a new result type in SharePoint Server 2013 | Office 365 Singapore for Business - Win-Pro

  • Anonymous
    July 09, 2014
    This series is excellent, the best introduction to the item templates I’ve seen.

    I’ve been working with result types a bit and I saw that you’ve said you can configure result types at the search application level:
    Search service application administrator - To all site collections within the farm

    Is this information correct? Unlike other search settings, I can’t see result types in the central administration. Actually, there seem to be a good reason for it – item templates depend on Design Manager, which is a part of a site collection. As far as I understand it, there are some build-in item templates and result types, which are deployed automatically to every site collection when one is created, but there is no place above a particular site collection – i.e. at the farm administration level – in which you can manage templates / result types, as there is no central design manager. Or am I missing something?

  • Anonymous
    December 16, 2014
    Hi Bella,
    Your articles have taught me a lot! Thanks!

    I'm having a problem with a display template that I customized. I'm using it on all search results to display specific managed properties inside a table. My problem now is that I created this template, which is working great in SharePoint 2013 O365, but the problem comes when I try to use it on a client server, on premises. I apply the display template and shows ok while in the page "edit mode", but when I hit "save" the display template goes away and sharepoint reverts it to the previous display template. I've tried a number of times and my customized template just doesn't stick! Any help or ideas will be greatly appreciated. Once again thanks for sharing your knowledge!

    Pablo

  • Anonymous
    March 24, 2015
    I have followed your guide from beginning with my JobName Site Column (JobNameOWSTEXT managed property) to distinguish from other result sources. I have 2 lists; the first one just has Title column and has one list item, the second has additionally JobName site column and has two list items. I have done as you did when configuring for new Result Type, and specific that the new Result Type should have JobNameOWSTEXT with value of "IT" or "Doctor".

    I tried searching and SharePoint returned 3 results on Everything; however, when click TechNet on Search Navigation, nothing changed that I expected It would return 2 results that belongs to the List having JobName site column.

    I also compare the settings for technetresult.aspx with peopleresults.asp and conversationresult.aspx that make the same settings for the OTB pages. Still, results is not as expected.

    Could you tell me how to make this work properly?

    Thanks,
    Hoan.