SharePoint 2013: Remove from the search result "You have seen this before" Recommendation Part 2

This post continue form my last post,  as I described the issue “you have seen this before” in my last post so here I am continue with its second part. So let’s begin with it so I am going to the answer of the question, I mentioned in the last post.

How I remove the “You have seen this before”?

To remove the “You have seen this before template” as mentioned above it is very simple before going to this as per the good practice. It is not a good idea to remove “you have seen this before” from all form the search results it would better to remove only for those results causing an issue (rewrite URL(s) or custom URL as mentioned in the above mentioned)

To remove “you have seen this before” items from all the results. (Not recommended Solution) 
Edit the common template “Item_CommonItem_Body.html”, as we know this template is used to display the common properties like title, URL and hithighlighted. Search for “clickType” item inside the template, you will find the following items.
var clickType = ctx.CurrentItem.csr_ClickType;
if(!clickType) {clickType = "Result"}
var titleHtml = String.format('<a clicktype="{0}" id="{1}" href="{2}" class="ms-srch-item-link" title="{3}" onfocus="{4}" {5}>{6}</a>', $htmlEncode(clickType), $htmlEncode(id + Srch.U.Ids.titleLink), $urlHtmlEncode(url), $htmlEncode(ctx.CurrentItem.Title), showHoverPanelCallback, appAttribs, Srch.U.trimTitle(title, maxTitleLengthInChars, termsToUse));

Remove the clicktype="{0}" from the link this will send the information to the analytic engine to 
calculate the click. So remove  clicktype="{0}" form the  titleHtml variable and the updated link 

Item would be like as mentioned below.
var titleHtml = String.format('<a id="{0}" href="{1}" class="ms-srch-item-link" title="{2}" onfocus="{3}" {4}>{5}</a>',  $htmlEncode(id + Srch.U.Ids.titleLink), $urlHtmlEncode(url), $htmlEncode(ctx.CurrentItem.Title),   showHoverPanelCallback, appAttribs, Srch.U.trimTitle(title, maxTitleLengthInChars, termsToUse));

To remove “you have seen this before” items from specific the results. (Better Way to remove the selected one, depending upon the query type condition)


To remove the “you have seen this before” from the specific type of record, for that you need to identify the template which responsible for display the data?


Once you identify the content, next step make the copy of this template and give it new name in the title and the template give a new name. So next step remove the _#=ctx.RenderBody(ctx)=#_ form the body & copy the content of the <div id="Item_CommonItem_Body"> with div and paste in place of this content.



Let start with an example
  • Copy the template “item_word.html” and give it name like “custom item template” and changed the copied template with “sharepointfordeveloper_item_word.html” name.
  • Open “sharepointfordeveloper_item_word.html” template and replace the _#=ctx.RenderBody(ctx)=#_   tag with <div id="Item_CommonItem_Body"> tag and content with  “Item_CommonItem_Body.html” template.
  • Remove the clicktype="{0}" from the link this will send the information to the analytic engine to calculate the click. So remove clicktype="{0}" form the  titleHtml variable and the updated link item would be like as mentioned below. 
var titleHtml = String.format('<a id="{0}" href="{1}" class="ms-srch-item-link" title="{2}" onfocus="{3}" {4}>{5}</a>',  $htmlEncode(id + Srch.U.Ids.titleLink), $urlHtmlEncode(url), $htmlEncode(ctx.CurrentItem.Title),   showHoverPanelCallback, appAttribs, Srch.U.trimTitle(title, maxTitleLengthInChars, termsToUse));
  • Save the template and published in the display template gallery.
  • Create the new result type and apply the condition that specify the condition which includes the customize URL rewrite implemented.
Part 2: SharePoint 2013: Remove from the search result "You have seen this before" Recommendation Part 3 

Comments

Popular posts from this blog

SharePoint RPC Protocols Examples Using OWSSVR.DLL

Types of Features in SharePoint 2013

Send Email using SharePoint Rest API