Thursday, 25 September 2014

SharePoint Search box read input search key word

You can find using below code...
var keyword=ctx.CurrentItem.HitHighlightedSummary;
Steps:
Open Search result webpart Item Template(Edit Search result webpart-->Expand Display Templates
-->Under "Use a single template to display items"
Check what is the name of Item Template. Ex: SearchResult_item
Now go to Site Settings-->Master pages and page layouts -->Display Templates-->Search
Now find the Item Template which you find in the earlier steps. Ex: SearchResult_item
Download that. Open in notepad or Visual Studio
Find below code....
var keyword=ctx.CurrentItem.HitHighlightedSummary;
<body>
<div id="Item_Temp">
<!--#_
if(!$isNull(ctx.CurrentItem) && !$isNull(ctx.ClientControl)){
var keyword=ctx.CurrentItem.HitHighlightedSummary;
var keywordOnly;
if(keyword)
{
keywordOnly=keyword.substring(keyword.indexOf("<c0>"), keyword.indexOf("</c0>"));
}
if (!ctx['Searchkeyword']){
if(keywordOnly){
ctx.Searchkeyword=keywordOnly;
}else
{
ctx.Searchkeyword="";
}
}
_#-->
<!--#_
}
_#-->
</div>
</body>
view raw gistfile1.js hosted with ❤ by GitHub