如何按个人资料属性搜索? MSDN说使用ProfileSearchManager,但是它不起作用。
我希望通过MobilePhone属性搜索用户。

SPServiceContext serviceContext = SPServiceContext.GetContext(site);
UserProfileManager upm = new UserProfileManager(serviceContext);
ProfileSearchManager sp = ProfileSearchManager.GetProfileSearchManager(serviceContext);

string[] searchPattern = { "123" };
ProfileBase[] searchResults = sp.Search(searchPattern, ProfileSearchFlags.User);

foreach (ProfileBase profile in searchResults)
{
    Console.WriteLine(profile.DisplayName);
}

最佳答案

 using (SPSite site = new SPSite(siteUrl))
            {
                    using (var qRequest = new KeywordQuery(site)
                    {
                        QueryText = "MobilePhone:*" +"123" ,
                        EnableQueryRules = true,
                        EnableSorting = false,
                        SourceId = new Guid("Enter here Result Source Guid"),
                        TrimDuplicates = false
                    })
                    {
                        //Get properties you want here
                        qRequest.SelectProperties.Add("FirstName");
                        qRequest.SelectProperties.Add("LastName");


                        SearchExecutor e = new SearchExecutor();
                        ResultTableCollection rt = e.ExecuteQuery(qRequest);
                        var tab = rt.Filter("TableType", KnownTableTypes.RelevantResults);
                        var result = tab.FirstOrDefault();

                        DataTable resultTable = result.Table;
                    }
}

关于c# - 通过配置文件属性搜索用户,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26794553/

10-13 07:02