Search code examples
sharepoint-2013sharepoint-search

Extend people search, custom result source


I've made a a custom result source based on "Local SharePoint Results", where I use this "Query Transform"

{?(({searchTerms}) ContentClass=urn:content-class:SPSPeople)} 
{?OR (({searchTerms}) spcontenttype:contact)}

My search results work, I get both spspeople and contacts. What I cant figure out is why the spspeople object is presented in the search result as a website. While debugging I noticed that it's indeed a spspeople content class returned.

I want it presented as a "normal" people object with picture and so on.


Solution

  • 1.I made a copy of the control_searchresults displaytemplate. And included this code in a function(to use title as prefferedname, and prefferedname is used in People item display):

     var peopleTable = ctx.ListData.ResultTables.filter(function( table ) {
          return table.TableType == "RelevantResults";
        });
    
    
        if( $isEmptyArray(peopleTable) ) return;
    
        if(!$isEmptyArray(peopleTable)) {
    
        for (var i=0, item; item = peopleTable[0].ResultRows[i]; i++) {
              item.PreferredName = item.Title;
        }
    
    1. In the People search web part chose to use it as a display template.

    3.In the webpart: "Use a single template to display items" and chose "People item".