Search code examples
c#sharepoint-2013sharepoint-search

Search SharePoint 2013: set Result Source Type section to People Search Results


I've been able to create custom Result Source for SP13 people search like this:

    var fedManager = new FederationManager(application);
    var owner = new SearchObjectOwner(SearchObjectLevel.SPSite, site.RootWeb);
    var peopleSource = fedManager.GetSourceByName(Consts.ResultSources.PeopleSource, owner);
    QueryTransformProperties queryProperties = new QueryTransformProperties();
    SortCollection sortCollection = new SortCollection();
    sortCollection.Add("PreferredName", SortDirection.Ascending);
    queryProperties["SortList"] = sortCollection;
    var currentResultSource = fedManager.CreateSource(owner);
    currentResultSource.Name = sourceName;
    currentResultSource.ProviderId = fedManager.ListProviders()["Local SharePoint Provider"].Id;
    currentResultSource.CreateQueryTransform(queryProperties, "{?{searchTerms} ContentClass=urn:content-class:SPSPeople}");
    currentResultSource.Commit();

This works just fine but I still have to manually set "People Search Results" instead of default "SharePoint Search Results" in Type section. Can I do it programmatically? Thank you.


Solution

    • To set the Type property to People Results, you need to update the Source.ProviderId to equal SearchProvider.LocalPeopleProviderGuid;