1

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.

Alexey
  • 414
  • 3
  • 10
SadPanda
  • 35
  • 1
  • 1
  • 10
  • Your error was in using ["Local SharePoint Provider"] instead of "Local People Provider". And it's better to use the static properties of the SearchProvider class than to hardcode magic strings. – Alexey Oct 17 '14 at 10:49

1 Answers1

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