搜索SharePoint 2013:将“结果源类型”部分设置为“人员搜索结果”

时间:2014-10-09 12:32:10

标签: c# sharepoint-2013 sharepoint-search

我已经能够为SP13人员创建自定义结果源,如下所示:

    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();

这很好用但我仍然需要在“类型”部分中手动设置“人物搜索结果”而不是默认的“SharePoint搜索结果”。我可以通过编程方式进行吗? 谢谢。

1 个答案:

答案 0 :(得分:1)

  • 要将Type属性设置为People Results,您需要更新 Source.ProviderId等于SearchProvider。LocalPeopleProviderGuid;