Now I will be talking about how to display additional properties of User inside people search results.
Points to remember:
1. Ensure that properties that you want to appear are currently being listed out in the search API results.
Use the http://server/_api/search/query?querytext=”&sourceid=’GUID OF PEOPLE SOURCE’&selectproperties=’AccountName,ABG_Property1,ABG_Property2′
2. If required properties are not being listed in the browser’s XML/JSON output, it means that the custom UPS properties do not have managed properties defined. Now you need to create a new Managed Property inside Search schema & point it to appropriate UPS’s crawled property. Then a FULL crawl is mandatory.
Now check the search API in the browser & then properties should be listed at least. Go & edit the UPS property for a user & do a incremental crawl & now both property & value should come up. Now is the time to create next SharePoint artefact.
In SP 2013, the search results are now rendered using HTML/JS files which are called Display Templates. Here HTML is the actual Display Template while .JS is created automatically by SP when a HTML is uploaded.
This HTML will contain both UI part and JS part. The JS alone will be encapsulated inside special SP tags. Once the HTML file is uploaded, SP will automatically create a JS after reading the HTML.
- Go to Site Settings -> Master page & Page layout Gallery -> Display Templates -> Search -> Download a copy of Item_Person.HTML
- Now rename the file to ABG_Person.html & look inside it.
- At the top there will be a definition of the list of FIELDS. Just go there & start adding up the new Managed properties. The list of fields will be defined inside a tag like:<mso:ManagedPropertyMapping
- Now in the middle you can append you required HTML UI elements as needed.
- Save the file & upload it in the same path as downloaded.
Now in the Upload screen, choose below options:
Now SAVE & PUBLISH the .HTML file.
Result types are the ones which define which display template need to be used for which result. Now go the result type settings page: https://server/_layouts/15/manageresulttypes.aspx?level=site
- Here click the Person’s dropdown menu & select COPY
- Enter the new result type details as below
Name as “ABG Person New”
Which Source should Results match: Local People Results
What should these results look like: here choose ABG People Item.
Once the above is done click SAVE.
RESULTS WEB PART:
Now its time to piece all together & make it work.
- Edit the page containing the people results web part
- Inside the web part properties, click on the Display Templates & choose the result type as “ABG Person New”, click OK & then save the page.
And finally perform search & viola you get the additional properties now.
That is all for now. In another post I will explain about how to edit the search results’s Query Builder where you define from where the SEARCH KEYWORD should be taken. Like should it be a search textbox or some Custom URL parameter…..