Understanding how search results are displayed 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 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

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.

Default display of search results

By hovering over the first result, more information about the search result is displayed.

Default PPT hover panel

By hovering over the fourth result, the information that is displayed is different from what you saw when you hovered over the first result.

Default PDF hover panel

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:

  1. Item display template - used to control how you want information in the body of the Search Results Web Part to be displayed.
  2. Hover display template - used to control how you want information in the hover panel to be displayed.

Display templates used to display search results

 

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.

When you go to this folder, you’ll see that there’s an HTML file, and a JavaScript file for each display template.

Display templates in Search folder

To view or edit a display template, use the HTML file. SharePoint automatically transforms the HTML file into an associated JavaScript file when you upload it. Because the two files are associated, any changes you make to the HTML file will be automatically updated in the associated JavaScript file.

I’ll explain how display templates work in later posts. For now, let’s move on to result types.

 

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

 

About the connections between a result type and display templates

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.

  1. Each result type contains a reference to an item display template, for example, Item_PowerPoint.
  2. Each item display template contains a reference to a hover panel display template, for example, Item_PowerPoint_HoverPanel.

Result type to display templates connections - 1

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.

View Microsoft PowerPoint result type

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.

URL to display template

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.

Item_PowerPoint display templates

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.

Reference from item display template to hover panel display template

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.

Hover panel display templates in Master Page Gallery

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.

 

About display templates that are used by all result types

To recap:

  1. Each result type contains a reference to an item display template.
  2. Each item display template contains a reference to a hover panel display template.

...and then we need to add:

  1. Each item display template contains a reference to a common item display template.
  2. Each hover panel display template contain references to three common hover panel display templates.

Result type to display templates connections - 2

These common display templates are located in the same Master Page Gallery folder as the display templates that are specific to individual result types.

Common display templates in Master Page Gallery

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.

Reference to Item_CommonItem_Body display template

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.

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

 

About display template settings in the Search Results Web Part

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.

Search Results Web Part configuration
You’ll see that the radio button Use result types to display items is selected by default. This means that search results will be displayed based on the result type that they belong to. That's it!

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

Comments (35)

  1. Anonymous says:

    Hi Craig,

    No. But if you want to only use one display template for all your search results, you can change the setting in the Search Results Web Part (SRWP) so that it uses a single display template (edit the SRWP -> Display Templates --> Use a single template to display items).

    Hope this helps,
    Bella

  2. Bella_Engen says:

    Hi Dan Gøran,

    Thanks for the positive feedback 🙂

    Bella

  3. Bella_Engen says:

    Hi Avinash ,

    I'm sorry, I don't know how you can do this.

    Bella

  4. Bella_Engen says:

    Hi Navaneetha,

    Thanks for the nice feedback 🙂

    Bella

  5. Bella_Engen says:

    Hi Anni,

    I don't have a blog post, but check out the sections Search service application, People search and Expertise search in this TechNet article: http://technet.microsoft.com/en-us/library/cc262500(v=office.15).aspx#relsvcapps

    Hope this helps.

    Bella

  6. Bella_Engen says:

    Hi mikef,

    No, you can’t edit the default search results page (the page that has osssearchresults.aspx in the URL).

    You’ll have to create a new search results page, and then go to Site settings --> Search Settings. On the Search Settings page, in the section Which search results page should queries be sent to, select Send queries to a custom results page URL, and enter the URL of your new search results page.

    Hope this helps,
    Bella

  7. Bella_Engen says:

    Hi David,

    Really happy to hear that the article was helpful 🙂

    Bella

  8. Bella_Engen says:

    Hi Rubens,

    If a document has a title, then the title should be displayed in the search results.

    It's difficult to say what could be the cause of this not happening for some of your documents. I suggest that you contact Microsoft Support with this issue.

    Bella

  9. Bella_Engen says:

    Hi Brian,

    Regarding your issue with the hover panel not showing up, it's difficult to say what your exact issue could be. I suggest that you contact Microsoft Support about this.

    Regarding the page layout, since you're not seeing a Search results page layout, I am assuming you're not using a Search Center Site Collection. If this is the case and your default page layouts are not what you're looking for, then you'll have to create a new page layout. For information about how to do that, see this article: http://msdn.microsoft.com/en-us/library/office/jj822368(v=office.15).aspx

    Bella

  10. Bella_Engen says:

    Hi Raj,

    You should be able to do that by using the managed property of your preview image. But I don't know which managed property that is.

    Bella

  11. Bella_Engen says:

    Hi Yvonne,

    osssearchresults.aspx is a systems page, so you shouldn't make any changes to this page.

    What you should do is create a new page, and set this to be your your search results page. To do this, go to Site settings --> Search settings. On the Search Settings page, in the Which search results page should queries be sent to section, select the Send queries to a custom results page URL, and enter the URL of your newly created page.

    Hope this helps.

    Bella

  12. Hi Bella,

    Yet another one. great article.. Explained neatly with images. thanks again.

    Navaneetha Krishnan D

  13. Bella_Engen says:

    Hi Olav,

    I'm sorry, but it's a bit difficult to understand your exact scenario, so I suggest you contact Microsoft Support. They'll be able to look into your situation in more detail.

    Bella

  14. Bella_Engen says:

    Hi Satya,

    It's difficult to say what is causing your problem. I suggest that you contact Microsoft Support.

    Thanks,
    Bella

  15. Dan Gøran Lunde says:

    Very good article.The best I've read on Display Templates so far.

  16. David Lightheart says:

    Excellent article! I finally got my custom display template working thanks to this article.

  17. Sreeharsha says:

    Handful information !! Thanks for the Post.

  18. Manuela says:

    Can you maybe tell me where do I find "Search Results Web Part" in SharePoint Online 2013? I cannot find this Web Part Tool Pane.

  19. Bella_Engen says:

    Hi Manuela,

    Which SharePoint Online plan do you have?

    Bella

  20. rafi says:

    Very {Good|Easy|Simple} Explanation.
    Thanks for posting such

  21. Mike F1 says:

    I have a very basic question. When i use 'search this site' the results are shown in a basic search results page that does not appear to be customizable (no 'edit this page'). I know i can use a customizable enterprise search site, but can i get the best
    of both worlds? The basic results page but customizable????

  22. Anni says:

    Hi Bella

    Do you have any blog post about what content from the My Site site collection (newsfeed, mentions, tags, etc) is indexed and shown in the search?
    I can't find anything about it.

  23. Yvonne Klomp says:

    Hi Bella,
    thanks for this very clear explanation.
    Could you tell me if it is possible to copy the default search results page (osssearchresults.aspx) so that I then can change the copy? I can't seem to find that page anywhere.

  24. Brian says:

    Having trouble getting a hover panel on the search results web part, hoping maybe you can help.

    I manually created a basic search results web part page by:
    1. creating a new web part page,
    2. adding a search results web part to the center zone
    setting the query to a result source I created.
    3. adding a search refinement web part to the left zone
    4. on a site page, added a search box web part and set the result page url to point to this new results page.

    The search box and results page work fine, but the results do not contain the nice hover like I get with the osssearchresults.aspx result page.

    Can you provide steps on how to get the hover panel working on the search results web part?
    Seems like this should be really simple, especially since it is the default behavior for the osssearchresults.aspx.

    I see the search results web part has a section for "Display Templates". I've spent hours trying to figure out how to use the "Display Template" to get the hover to show but can't get it going and it really doesn't make any sense to me.

    Currently the "Display Templates" section has the following:
    Results Control Display Template: "Default Result"
    Use result types to display items (selected):
    Result type for item: Use result type rules to decide

    Thanks, Brian

  25. Brian says:

    update on the issue I posted above about no hover panel with a search results web part. I think there is a bug. If I insert a search results web part on a page and the only thing I do is edit web part and change the query to my result source, then the hover panel is shown when mousing over an item in the search results. If I then edit the search result web part, and change anything, e.g. chrome type = title only, then the hover panel is not shown. I haven't verified if it is possible to unset the properties on the search results web part and get the hover panel back yet or if you have to delete and re-insert a new search results web part. While working on this another frustrating issue is that I have not been able to find a way to get a thin left column & main right column web part page layout, to hold the refinement and search results web parts, similar to the built in search result page. There is no web part page layout that has a thin left column and main content area to the right. I also tried using just a normal page and inserting a table with widths set to 15% and 85%, then inserting the refinement panel on the left and search result in right column. In both cases the quick launch was present & the only way I've found to hide/remove it is with an embedded script that sets the style, but even when hidden the space is not reclaimed and you are left with a big left margin where the quick launch used to be. Any suggestions on how to build a search results page that looks like the built in one but uses my own result source?

  26. Bhanu says:

    This blog is so good for everyone to read and understand things on the go.

  27. Joe says:

    Great article. I came here lookig for a solution on customizing the output of a search and got a much better understanding of how the output is generated. Looking forward to your next article!

  28. Craig says:

    Is there any way to change the display template being used by passing as a querystring parameter to the results page?
    Thanks,

  29. Olav says:

    Hi Bella,
    I have been having loads of fun looking at search and CSWPs. I am finding that SharePoint is doing some things behind the scenes that are not too clear to me when it comes to links. I have a document library that I am sharing as a catalog. On the publishing
    site I have a search centre that uses the catalog as a result source. Documents are returned with a "Title" as a link. This is where it gets somewhat strange: If I click on a docx, pptx or pdf, I am presented with a download box as I expect. However, for vsdx,
    clicking on the link first takes me to a new browser page and attempts to show me the Visio document in the browser. I have not enabled Visio Services, and so I then get a message that says sorry - this will not work - would I like to open it in Visio? Even
    more odd behaviour: If I click on a rtf or log file, I am first taken to the item display template for the document in the source library and from there I need to click another link to download it.
    Do you have a good reference for controlling the behaviour of links in display templates? I have tried both "Use result type rules to decide" and "SharePoint Document Library" in the Search Results WP - same behaviour. I would like every link to present a download
    box immediately.

    Thanks again for your wonderful blog posts!
    Olav

  30. Avi2112 says:

    Hi,

    Great post !!!

    I have requirement to localize web part titles in my projects using Display template.
    Could you please tell me how can be this done .

    Thanks in advance for your great help.

    Regards,
    Avinash Kumar

  31. Rubens_ghigo says:

    Hi,
    Sometimes "Item display template" of "Search Results" does not return title field of the Word document but the first line of text from the document instead. This happens only for a few documents. All of them have title field filled.
    Do you know what's happening?
    Thanks,
    Rubens

  32. Raj says:

    Hi Bella,

    Excellent articles on understanding the search display templates!
    I want to extract the preview image of the search results and use it in my display templates. Is there a way to do that ?

    Thanks!

  33. utham says:

    Excellent article. crystal clear 🙂

  34. Satya says:

    Hi Bella,
    I have created a page in one of the site collection,and when i am trying to find the page through the search box by providing the keyword in the page it is not displaying it.Can i know what all could be the reasons.I even tried to find from crawl but it did
    not result

  35. K R Nagendra says:

    Hi Bella,

    Good article on understanding search.

    Thanks,
    Nagendra

Skip to main content