How to display values from custom managed properties in search results - option 1

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 introduced you to the Search Center example I am using in this series, and explained how you can create a new result type. In this blog post we'll learn:

 

How to display a custom icon

In a previous blog, I showed you how the icons Word, PDF and Excel are displayed for each search result. In my Search Center scenario, I wanted to add the following custom icon next to all search results that belong to the newly created TechNet content result type:

To display a custom icon for search results, here's what you should do:

  1. Add the custom icon to a SharePoint library.

    In my Search Center scenario, I added the custom icon to the Images library.

Icon in Images library

  1. Open the item display template that is referenced from the result type for which you want to display a custom icon.

    In my scenario, this was the TechNet content file.

  2. In the item display template, modify the value for ctx.CurrentItem.csr_Icon so that it points to the custom icon.

    In my scenario, I also removed the if statement, if(ctx.CurrentItem.IsContainer).

ctx.CurrentItem.csr_Icon points to custom icon

  1. On a search page, enter a query that will trigger the new result type.

    In my scenario, I entered "result type."  Search results that are TechNet publications now have a custom icon next to them. Great!

Custom icon displayed in search results

So users of our search center could now easily distinguish the search results that had been published on TechNet. However, I also wanted to add information from custom site columns so that users could see important information about each search result without having to click on it.

At the start of this series, I explained that site columns are “transformed” into managed properties during crawl. I also explained that only managed properties that are listed in an item display template can be displayed in search results. So, to display custom information in your search results, you need to add managed properties to an item display template. Hence, the next thing you should do is find the managed property name that corresponds to the custom site column that you want to use.

 

How to find a managed property name

Before you start searching for a managed property name, it’s important that you know a bit about the naming convention for managed properties. For more information about this, see Automatically created managed properties in SharePoint Server 2013.

Depending on your permission level, you can search for managed properties from three places:

Permission level From where you can search
Search service application administrator Central Administration --> Managed Service Application --> Search Service Application --> Search Schema
Site collection administrator Site Settings --> Search Schema (in the Site Collection Administration section)
Site collection owner Site Settings --> Schema (in the Search section)

To save space, I will only show you how to find a managed property name as a Site collection administrator.

Here’s what you should do:

  1. Go to Site settings --> Search Schema.

Search Schema on Site Settings page

  1. On the Managed Properties page, in the Managed property field, type the name of the site column that you want to find the managed property name of. Remember that managed property names don’t contain spaces, so if your site column name contains a space, leave it out.

    In my scenario, I wanted to find the managed property name for the site column Content Summary. I entered ContentSummary in the Managed property field, and clicked the green arrow icon.

Search for ContentSummary

One search result was returned: ContentSummaryOWSMTXT.

ContentSummaryOWSMTXT returned as search result

Since the Content Summary site column is of type Multiple lines of text, I knew that this was the managed property name that I wanted to use.

  1. Repeat the steps from this procedure to find the names of all of the managed properties that you want to display in your search results.

So now that you have found the names of the managed properties that you want to show in your search results, the next step is to modify the item display template.

 

 

How to modify an item display template to show values from custom managed properties - option 1

As I explained in the previous blog, there are different ways you can go about modifying an item display template to show values from custom managed properties. The first option I'll show you is very simple (I’ll cover the second option in the next blog). It does not include any if statements, and hit highlighting is not applied.

Here's what you should do:

  1. Open the item display template that belongs to the result type for which you want to customize search results.

    In my scenario, this was TechNet content.

  2. In the item display template, in the ManagedPropertyMapping tag, use the following syntax to add the custom managed properties that you want to display:
    '<Current item property name>':<Managed property name>'

    In my scenario, I wanted the values from the managed properties ContentSummaryOWSMTXT and owstaxIdTechnicalSubject to be displayed in the search result. To make the file easier to maintain, I named the current item properties the same as the managed properties.

Two managed Properties added to display template

  1. Inside the second <div> tag in the <body>, use the following syntax to add code that will display the value of the custom managed property:
    _#= ctx.CurrentItem.<Current item property name> =#_

    In my scenario, I added the following to the item display template:
    <div>_#= ctx.CurrentItem. ContentSummaryOWSMTXT =#_</div>
    <div>_#= ctx.CurrentItem. owstaxIdTechnicalSubject =#></div>

Add properties so that they display in search results

  1. Save the item display template.
  2. NOTE: You do not need to do this step if you are using SharePoint Online.
    Go to Site settings --> Search Result Types. Notice that a Property Sync alert is displayed.

Property Sync alert displayed

This alert is displayed because we added managed properties to an item display template (what we did in step 2). To update the result types with the newly added managed properties, click Update.

Update managed Properties from result types

IMPORTANT! If you don't do this update, the newly added managed properties will not display in your search results.

After I made this change, when users entered a query in our Search Center, both the value of ContentSummaryOWSMTXT and the value for owstaxIdTechnicalSubject were displayed in the search results.

Values of custom properties displayed in search results
But even though two custom properties were now displayed in our search results, I wasn’t quite happy with the result. For example, I wanted to display the two custom properties between the title and the link, and not below the link as was currently the case.

To better understand why the search results were displayed the way they were, let's take a closer look at the customized item display template:

How the display template displays content

  1. ctx.CurrentItem.csr_Icon points to the location of my custom icon. This variable is used by the Item_CommonItem_Body display template.
  2. _#=ctx.RenderBody(ctx)=#_ calls the Item_CommonItem_Body display template (remember, I talked about this in an earlier blog post). The Item_CommonItem_Body display template displays the custom icon, title and the link to the item.
  3. _#= ctx.CurrentItem.ContentSummaryOWSMTXT =#_ and _#= ctx.CurrentItem.owstaxIdTechnicalSubject =#_ display the values of the two managed properties, ContentSummaryOWSMTXT and owstaxIdTechnicalSubject.

To display the custom properties between the title and the link, you could simply take the Item_CommonItem_Body display template out of play by deleting the reference _#=ctx.RenderBody(ctx)=#_ from your custom display template. You could then add the properties in the order that you want them to display, for example like this:

Reference to _#=ctx.RenderBody(ctx)=#_ has been deleted

The search result would then look like this:

Search result displayed without Item_CommonItem_Body reference

By working a bit more on the styling, you could have a good enough result. However, by deleting the reference to _#=ctx.RenderBody(ctx)=#_ ,the Item_CommonItem_Body display template is no longer used to display results. The Item_CommonItem_Body display template contains some functionality that will automatically improve the relevancy of your search results. So, before you delete the _#=ctx.RenderBody(ctx)=#_ reference, you should consider if automatically improved relevancy is something that the users of your search site would benefit from.

 

About click tracking and automatically improved relevancy

The Item_CommonItem_Body display template contains an onlick method that tracks the click behavior of users. This tracking has an impact on the relevancy of search results. For example, a search result that is often clicked by users will automatically be displayed higher up in the search results. 

IMPORTANT: If you want your search results to receive automatically improved relevancy based on the click behavior of users, do not delete the reference to _#=ctx.RenderBody(ctx)=#_ from the item display template!

In the next blog post, I will show you how you can keep this reference, display custom properties between the title and link in the search results, and also apply hit highlighting to your custom properties.

  

Next blog post in this series
How to display values from custom properties in search results - option 2

Comments

  • Anonymous
    January 01, 2003
    Hi Gaurav,

    It depends on which Search Web Part you are using to display your results. For an overview of the default display templates, see this article:http://technet.microsoft.com/en-us/library/jj944947(v=office.15).aspx

    Hope this helps,
    Bella

  • Anonymous
    January 01, 2003
    Hi Thomas,

    Very interesting question! Unfortunately I don't know how you can remove this prefix.
    Sorry I couldn't be more helpful.

    Bella

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    Hi Matthew,

    Yes, you can display a picture in your search results. And yes, you do have to add the managed property of your image to your display template.

    In this blog post you can see another example of how this can be done:
    http://blogs.technet.com/b/speschka/archive/2012/07/23/using-query-rules-result-types-and-display-templates-for-a-custom-search-sales-report-in-sharepoint-2013.aspx

    Hope this helps.

    Bella

  • Anonymous
    January 01, 2003
    Hi SharePointer101, I am not sure I completely understand your scenario, but from what I understand, you should create a managed property that contains only the crawled property for “Department”, and use this in your display template. Bella

  • Anonymous
    January 01, 2003
    Hi Iranna, You can read about how to modify display templates in this article: http://msdn.microsoft.com/en-us/library/office/jj945138.aspx Bella

  • Anonymous
    January 01, 2003
    Hi Louie,

    Please contact MS Support with this issue.

    Bella

  • Anonymous
    January 01, 2003
    thank you

  • Anonymous
    January 01, 2003
    Great article! I've been bit by the property sync update problem more than once. I have managed to display custom string properties, but I would like to see an example of how to other datatypes and especially multi value properties. We have int32 int64, boolean, GUID, DateTime, Double, Decimal and byte array datatypes. And then there are single- and multi-value variants of each of these. Maybe something for a follow-up article?

  • Anonymous
    January 01, 2003
    Hi Gaurav,

    You should be able to make these changes to the Item_Powerpoint.html display template as well. It's difficult for me to say what your exact issue could be, so I suggest that you contact Microsoft Support.

    Bella

  • Anonymous
    January 01, 2003
    Hi Bhargav,

    The site column type should not matter.
    Are you seeing the Property sync alert for other site column values?

    Bella

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    Hi Dan, Thanks for the feedback. I will look into expanding with examples of other data types, but can’t promise anything. Bella

  • Anonymous
    January 01, 2003
    Hi Gaurav,

    It's difficult to say anything about your specific problem, but did you make sure to add valid managed properties to your custom display template?

    If so, then I suggest that you contact Microsoft Support for further assistance.

    Bella

  • Anonymous
    January 01, 2003
    Hi Avinash,

    The title gets truncated because of hit highlighting. To change this, you'll have to modify your display template.

    If you use the Item_CommonItemBody display template, in the var titleHtml, try to replace the Srch.U.trimTitle..... with title.

    Hope this helps.

    Bella

  • Anonymous
    January 01, 2003
    Hi Rupali,

    It’s a bit difficult to say why you are not seeing the Property sync alert, but have you verified that your custom managed property is added correctly to the display templates?

    Bella

  • Anonymous
    January 01, 2003
    Hi Olaf,

    Sorry, I don't have any ideas for how you can get around this.
    I suggest that you contact Microsoft Support.

    Bella

  • Anonymous
    January 01, 2003
    Hi Bella, thanks för a great article!
    I have a issue with the results and the managed property coming from a managed metadata site column. the result is showing the GUID number like this "GP0|#8bcf1be9-c29e-4e42-aefb-6e1e36dd950e;L0|#08bcf1be9-c29e-4e42-aefb-6e1e36dd950e|Flex;"
    Do you know if is posible to delete this?

    Thank you!
    Michel

  • Anonymous
    January 01, 2003
    Hi Petr,

    I'm still a bit unsure of what you're trying to achieve, but by modifying the display template, you should be able to use your managed metadata field as the "Title" of your search results.

    Bella

  • Anonymous
    January 01, 2003
    Hi Petr,

    I'm sorry, I don't quite understand your question. Do you want to display a managed property name in the search results? Could you maybe give me some more information about the scenario that you want to achieve?

    Bella

  • Anonymous
    January 01, 2003
    Hi AJ,

    I suggest that you contact Microsoft Support with your question.

    Thanks,
    Bella

  • Anonymous
    January 01, 2003
    Hi Adrian,

    Yes, you can modify display templates in SharePoint Online as well. You have to find the display template that your Search Results Web Part is using, and then modify its display template to show your property.

    Bella

  • Anonymous
    January 01, 2003
    Hi Mike,

    After you'd changed your display template, on your Manage Result Types page, was a Property Sync alert shown? If not, try to save your custom display template again, and check to see if the Property Sync alert is shown. When you see this alert, make sure that you click to update the properties.

    Hope this helps,
    Bella

  • Anonymous
    January 01, 2003
    Hi micmor81,

    I'm sorry, but I don't know the answer to your question :-(
    I suggest you contact Microsoft Support.

    Bella

  • Anonymous
    January 01, 2003
    Hi Rock,

    For a LIST column, you first have to create a manage property, and then map the correct crawled property. See this TechNet article for information on how you can do this:https://technet.microsoft.com/en-us/library/jj219667.aspx#proc2)

    Hope this helps,
    Bella

  • Anonymous
    January 01, 2003
    Hi Counie,

    I believe the web or site name is captured in a managed property, but I don't know the name of this managed property. Sorry!

    I suggest you contact Microsoft Support with your question.

    Bella

  • Anonymous
    November 05, 2013
    I have a question I would appreciate it if you can help me, how we can prevent displaying GUIDs within the hithighlightedsummary value in the search results page??

  • Anonymous
    November 06, 2013
    Hi ghazal, Unfortunately, this is currently not possible. Bella

  • Anonymous
    December 04, 2013
    I have a question. I have a problem with other column that I created. I think that the problem is the names. My question is: <Current item property name> is internal name of list? <Managed property name> is name of schema? Thanks!

  • Anonymous
    December 06, 2013
    Hi Rafael, I’m sorry, but I don’t quite understand your question. Could you give me some more details about your problem? Bella

  • Anonymous
    December 17, 2013
    Hi how to use jquery in item template say in Picture on left, 3 lines on right.Please suggest.

  • Anonymous
    December 17, 2013
    Thanks for quick reply and link

  • Anonymous
    February 16, 2014
    Hi, I have a managed property "Department" which is mapped to "Company" and "Department" crawled properties.Now when I add the managed property in a display template, the results display both the "Company" and "Department" values. I want it to return results that match either Company or department but display only the corresponding "Department". What should my item value be ? ctc.CurrentItem.Department.something?

  • Anonymous
    February 23, 2014
    The comment has been removed

  • Anonymous
    March 20, 2014
    Hi Bella,
    I have created the custom display template and referred it in the Search Results Web part.
    I am facing an issue with the Results icon when custom Display Template is applied.
    With default Display template , the results icons are coming OOB but for custom it’s not coming.
    Is there any configuration change or something needs to be added to the Custom Display Template to get the Results icon OOB?

  • Anonymous
    March 20, 2014
    In addition to the Results icon query, I have one more doubt regarding default Display Template. I unable to display custom managed property in Item_Default.html. I have added it in "ManagedPropertyMapping" tag also and trying to print the value as suggested by you in above post.

  • Anonymous
    March 21, 2014
    Thanks Bella for the quick reply.... I am able to add the custom icon but i wanted to know that why i am not getting the default icons which sharepoint 2013 provides. I am not changing anything on the custom display template still the icons are missing whereas if default display template is applied, the icons for pdf, word etc documents are coming by default. As you have described in the below blog:
    http://blogs.technet.com/b/tothesharepoint/archive/2013/09/04/understand-how-search-results-are-displayed-in-sharepoint-server-2013.aspx

    On managed Property part, the property value is coming blank with default Display Template even if the value is there in the particular manage property. Its not throwing any error.



  • Anonymous
    March 21, 2014
    Hi Bella, great article! I hope you have time to share your wisdom of why the following is happening:
    I have a calculated column with this formula: =TEXT(Created,"yyyymmddhhmmss").
    I have created a managed property that maps to the calculated columns crawled property.
    I use the managed property as a refiner in my search page.

    When values from the calculated column show up in the refiner, they are prefixed with "string;#". Is there any way to configure the managed properties to only hold the specific value (and not include the string:# prefix)?

  • Anonymous
    March 25, 2014
    I am using Sharepoint 2013 and sharepoint 2013 search.

    when i search for certain items i get results, but the title of certain items shows with a trailing dots after showing some characters of the title and truncating the rest.

    For example: let the title be "This is a sample title just for testing" and in the search result the title is shown as "This is a sample title just....". So aftre displaying some part of the title it is showing ... I need to hover over the item to see the full title.Is there any option to show the full title.

  • Anonymous
    April 30, 2014
    Hi Bella great article.
    As per mentioned steps I had added the '':' and also require div tag.
    But after changes it is not showing "Property Sync" alert. My Custom column type is "Person or Group" so any other configuration required for this type?

  • Anonymous
    May 13, 2014
    Bella, Thanks for your great blog posts. Is it possible to have a picture show up in the results? I have a thumbnail field in my list item, and would love to have that show up. Is it as simple as replacing that field with a managed property in the template?

  • Anonymous
    May 15, 2014
    Pingback from SharePoint Search | Share your knowledge

  • Anonymous
    June 05, 2014
    Hi Bella,
    I followed your article about how to display values from custom managed properties in search results
    but still in the search results I am not able to see the custom managed properties, it's showing blank.

    Thanks

  • Anonymous
    June 05, 2014
    Hi Bella,
    And also I am not able to see the sync update alert in the manage result type.

    Thanks

  • Anonymous
    June 05, 2014
    Hi Bella,
    I am editing the Item_Powerpoint.html display template and doing the changes that you have mention in the article, if I am going wrong then please suggest.

    Thanks

  • Anonymous
    July 09, 2014
    This is a blog post in the series "How to change the way search results are displayed in SharePoint

  • Anonymous
    July 21, 2014
    Hi Bella,

    Can you please tell us, the results which are coming from BCS in sharepoint 2013 search, for that which display template should be modified. Our aim is to display the custom icon with the results of BCS in search.

    Thanks

  • Anonymous
    December 10, 2014
    Very helpful and nicely illustrated.

  • Anonymous
    December 29, 2014
    Hi Bella!

    I have created a new field, added it to a new custom type then deployed the solution to a site collection. I created new managed properties mapped to the crawled properties in Central Admin and all the fields showed up. I then added new columns(URL's) to the custom content type, repeated the steps I took when I initially deployed the solution but the new properties do not show up as part of the ctx.CurrenItem object. I double-checked my Item display template to make sure that the new managed properties were declared, yet, the new properties will not show up as part of CurrentItem object.

    Any ideas why?

    Thanks in advance,
    Louie

  • Anonymous
    January 23, 2015
    Hi Bella,

    thank you for all the knowledge you are sharing!

    I have little question:
    Is there a way to display managed property name (managed metadata) instead of title?

    Thank you

  • Anonymous
    February 13, 2015
    Hi Bella,

    sorry for that. I want to display certain column value (with link to that file). For example: By default, results are displayed like Title, link etc. I have a column that is called "Metadata" that is populated with managed metadata like "Invoice". What I'm trying to achieve is to display in results on first place "Invoice" with link to that document instead of a title of the document.
    Is it possible?

    Thank you very much

    Petr

  • Anonymous
    February 13, 2015
    I'm using SharePoint online and using a search webpart on a specific sitepage. Now when I hit search I want the search results to show a property I have on a library right beside the document name. For example "Document Name - (Property Here)" is this possible with this solution ? I can't seem to find theon the I opened the sitepage I'm using in SP Designer

    Thanks in advance

  • Anonymous
    February 18, 2015
    Hi, I'm trying this solution to show a column value I have in a document library. The column is a choice and I added it to manage property and also mapped it to that specific column. I added_#= ctx.CurrentItem.CourseID =#_but it's not showing in the search :( What am I Missing ? I'm using office 365

  • Anonymous
    March 25, 2015
    Hi Bella,

    I try to modify a display template on a team site collection where the publishing infrastructure feature is not activated. Since there are no html files in the display templates folder, I changed the Item_CommonItem_Body.js.

    This is working so far as expected, with one exception: I added a ManagedPropertyMapping ('SiteTitle':['SiteTitle']) in the script and added it in the item property as well, but I am not able to retrieve the SiteTitle. I am not sure if I have to do a Search Result Types Property Sync - at least there is no warning (this probably is a publishing infrastructure feature?). Well, I'm a bit lost at the moment, maybe you have an idea to go on? Activating the publishing infrastructure feature is not an option, since it brings a lot of complexity we don't need at that point.

    Thanks in advance (and for your great series of articles)
    Olaf

  • Anonymous
    April 14, 2015
    Great article, I followed it to a tee. I updated the template to include my managed property in the #= ctx.CurrentItem.owstaxIdToolset =# and nothing shows up. I can do a metadata search toolset: html and it returns the documents I want but does not display the data in the body. Are there additional setup steps in Search Center or something that I may have missed?

    Mike-

  • Anonymous
    May 06, 2015
    The comment has been removed

  • Anonymous
    May 06, 2015
    Hi Bella, Great article. Question for you: Can you find a managed property value for a column from a LIST rather than a SITE column?