Tuesday, May 12, 2015

How to create a new result type in SharePoint Server 2013

copyright from: blogs.technet.com

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:
CategoryDefinition
TechNet contentArticles that have been published on the TechNet platform
MSDN contentArticles that have been published on the MSDN platform
Office.com contentArticles that have been published on the office.com platform
Images contentImages that are used in publications
Video contentVideos that are used in publications
Download contentDownloadable 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 Itemresult 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 tag.  Remember, the text in this tag is what will be shown when you do configurations in the SharePoint UI.</li> </ol> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> In my scenario, I changed the <title> tag to <em>TechNet content</em>.</p> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/1104.TechNetTitleTag.png" style="color: rgb(0, 116, 158); cursor: pointer; text-decoration: none; outline: none;"><img src="http://blogs.technet.com/resized-image.ashx/__size/350x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/1104.TechNetTitleTag.png" alt="TechNet content <title> tag" border="0" style="overflow: hidden; max-width: 100%;"></a></p> <ol start="4" style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <li style="margin-left: -10px;">Save the new item display template.</li> </ol> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> Now that we have created a new item display template, we can move on to creating a new result type.</p> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;">   </p> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <span style="font-size: medium;"><strong><span style="color: rgb(51, 51, 51);"><a name="CreateResultType" style="color: rgb(0, 116, 158); cursor: pointer; font-weight: normal;"></a>How to create a result type</span></strong></span></p> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> Depending on your permission level, you create a result type on two levels:</p> <table cellpadding="3" border="1" style="border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(225, 225, 225); margin-left: 1px; color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"><tbody> <tr><td style="vertical-align: top; color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0);"><strong>Permission level</strong></span></td><td style="vertical-align: top; color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0);"><strong>Where the result type will be added</strong></span></td></tr> <tr><td style="vertical-align: top;">Site collection administrator</td><td style="vertical-align: top;">To all sites within a site collection</td></tr> <tr><td style="vertical-align: top;">Site collection owner</td><td style="vertical-align: top;">To a single site</td></tr> </tbody></table> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> To save space, I will only show you how to create a result type as a Site collection administrator.</p> <ol style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <li style="margin-left: -10px;">Go to <strong>Site settings</strong> --> <strong>Search Result Types</strong>.</li> </ol> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/5287.SearchResultTypes.png" style="color: rgb(0, 116, 158); cursor: pointer; text-decoration: none; outline: none;"><img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/5287.SearchResultTypes.png" alt="Search Result Type on Site Settings page" border="0" style="overflow: hidden; max-width: 100%;"></a></p> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> 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. </p> <ol start="2" style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <li style="margin-left: -10px;"> On the <strong>Manage Result Types</strong> page, from the result type menu field, select <strong>Copy</strong>.</li> </ol> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> In my scenario, I wanted to customize search results for SharePoint list items, so I copied the <strong>SharePoint List Item</strong> result type.</p> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/0876.CopySharePointListItem.png" style="color: rgb(0, 116, 158); cursor: pointer; text-decoration: none; outline: none;"><img src="http://blogs.technet.com/resized-image.ashx/__size/400x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/0876.CopySharePointListItem.png" alt="Copy the SharePoint List Item result type" border="0" style="overflow: hidden; max-width: 100%;"></a></p> <ol start="3" style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <li style="margin-left: -10px;">On the Add Result Type page, here's what you need to do:</li> </ol> <ol type="a" style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <li style="margin-left: -10px;">In the <strong>Give it a name</strong> field, enter a name for your new result type.  <br><br>In my scenario, I entered T<em>echNet content.</em></li> <li style="margin-left: -10px;">From the <strong>Which source should results match</strong> menu, select the result source that you have used to configure the query in your Search Result Web Part.</li> <li style="margin-left: -10px;">In the <strong>What types of content should match? You can skip this rule to match all content</strong> menu, all the default result type are listed. <br>In my scenario, I chose <strong>Select a value</strong>.</li> <li style="margin-left: -10px;">Click <strong>Show more conditions</strong>.</li> </ol> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/1362.ShowMoreConditions.png" style="color: rgb(0, 116, 158); cursor: pointer; text-decoration: none; outline: none;"><img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/1362.ShowMoreConditions.png" alt="Show More Conditions on Add Result Type page" border="0" style="overflow: hidden; max-width: 100%;"></a></p> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> This opens up a menu where you can specify the result type based on managed property values.</p> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> In my scenario, all list items contain a site column called <em>Distribution Channel</em>. As I showed you at the beginning of this blog, this site column contains the publication platform value, for example <em>TechNet Library</em>. I wanted to use values from this site column to specify which list items should belong to my new result type</p> <ol style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"><ol start="5" type="a" style="list-style-type: lower-alpha;"> <li style="margin-left: -10px;">From the <strong>Which custom properties should match</strong> menu, I selected<em>DistributionChannelOWSCHCS</em>. <em>DistributionChannelOWSCHCS</em> is the managed property that represents the <em>Distribution Channel</em> site column. In the fields below, I entered all the values that should specify the new <em>TechNet content</em> result type.</li> </ol> </ol> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/6862.AddProperties.png" style="color: rgb(0, 116, 158); cursor: pointer; text-decoration: none; outline: none;"><img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/6862.AddProperties.png" alt="Add properties to specify the result type" border="0" style="overflow: hidden; max-width: 100%;"></a></p> <ol style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"><ol start="6" type="a" style="list-style-type: lower-alpha;"> <li style="margin-left: -10px;">From the <strong>What should these results look like</strong> menu, select the display template that should be used by this result type.<br><br>In my scenario, I selected my newly created <em>TechNet content</em> display template. </li> </ol> </ol> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/5852.ApplyTechNetDisplayTemplate.png" style="color: rgb(0, 116, 158); cursor: pointer; text-decoration: none; outline: none;"><img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/5852.ApplyTechNetDisplayTemplate.png" alt="Apply display template to new result type" border="0" style="overflow: hidden; max-width: 100%;"></a></p> <ol style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"><ol start="7" type="a" style="list-style-type: lower-alpha;"> <li style="margin-left: -10px;">Click <strong>Save</strong>.</li> </ol> </ol> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> Your newly created result type is now listed on the <strong>Managed Result Types</strong> page. <br><br>In my scenario, I could see that the <em>TechNet content</em> result type had been created.</p> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> <a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/0523.TechNetCreated.png" style="color: rgb(0, 116, 158); cursor: pointer; text-decoration: none; outline: none;"><img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-66-12/0523.TechNetCreated.png" alt="New result type shown on page" border="0" style="overflow: hidden; max-width: 100%;"></a></p> <p style="color: rgb(42, 42, 42); font-family: 'Segoe UI', 'Helvetica Neue Light', 'Helvetica Neue', Calibri, 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12.960000038147px; line-height: 19.4400005340576px;"> 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.</p> </div>

No comments: