Wednesday 3 September 2014

SharePoint Search result Customization


Steps:
1.Open SharePoint site
2.Add new page
3.Add "Search Box" webpart
4.Edit web part properties.
5.Under "Settings"--> you will find: Search box control Display Template
6.You will find dropdown.
7.In the dropdown, you will "Site Searchbox". The physical location of the this file is:(Site Settings -->Master pages and page layouts -->Display Templates-->Search-->Control_SearchBox.html
8.Download "Control_SearchBox.html"
9.Recreate new html file with same content, with different name.
10.Upload in this path: Site Settings -->Master pages and page layouts -->Display Templates-->Search
11.Now Edit "Search Box" web part properties.Under "Settings"-->you will find: Search box control Display Template. Select new html file.
12.Add "Search Results" web part.
First create a Result source for search results.
To do that....
Go to Site Settings-->Result Sources--> New Result Source
Enter name.
Under Query Transform:
{searchTerms?} (contentclass:sts_listitem) path:https://SPO/teams/SourceSite
Save.
13.Now go to "Search Results" web part. Edit web part properties.
14.Click on "Change Query"
15.You will get popup. Under "Select a query ", select result source which we have created.
16.Under "Display Templates", you will find "Results Control Display Template". This template name is: Control_SearchResults.html ( Site Settings -->Master pages and page layouts -->Display Templates-->Search)
17. Download: Control_SearchResults.html
Rename and change the look and feel.
New file name is: SearchResultNew.html
Under "Results Control Display Template" : select "SearchResultNew.html"
This is control template..
Sample:  SearchResultNew.html
Select radio button  at: Use a single template to display items.
Under: Item Display Template.
By default "Best Bet Item" will be there.
We have to create custom Item template and upload, then select that template name in the dropdown.

Don't worry, we have added some AddPostRenderCallBack. This one will do using jquery Templates...

Create new html file name it srTemplate.html and add below code.

Upload above srTemplate.html file to style library.
You have to add srTemplate.html file to search page, where your webpart are located.
Add content editor web part.
Under "Content Link To link to a text file, type a URL. "
../Style Library/srTemplat.html
Save