0

I have total 1,00,000 users in my SharePoint but I want to get specific user by its custom property called SP-EmployeeID. I tried KeywordQuery of SharePoint Search with having scope as People by below code but it is not working as I need to find a user by Custom Property & I found that KeywordQuery don't work with custom property.

DataTable dt = GetPeople(site, "SP-EmployeeID:\"C001*\"");

private static DataTable GetPeople(SPSite spSite, string queryText)
{
    var keywordQuery = new KeywordQuery(spSite)
    {
        QueryText = queryText,
        KeywordInclusion = KeywordInclusion.AllKeywords,
        HiddenConstraints = "scope:" + "\"People\"",
        SourceId = new Guid("B09A7990-05EA-4AF9-81EF-EDFAB16C4E31")
    };
    keywordQuery.RowLimit = 7;
    keywordQuery.SelectProperties.Add("AccountName");
    keywordQuery.SelectProperties.Add("SP-EmployeeID");
    SearchExecutor e = new SearchExecutor();
    ResultTableCollection rt = e.ExecuteQuery(keywordQuery);
    var tab = rt.Filter("TableType", KnownTableTypes.RelevantResults);
    var result = tab.FirstOrDefault();
    DataTable DT = result.Table;
    return DT;
}

After unsuccessful try of SharePoint Search, I used GetEnumerator(100,1100) method to iterate specific number of users (1000 users) at one time but it is not working at all.

SPServiceContext serviceContext = SPServiceContext.GetContext(site);
UserProfileManager upMananger = new UserProfileManager(serviceContext);

IEnumerator profileEnumerator = upMananger.GetEnumerator(100,1100);

int i = 0;
while (profileEnumerator.MoveNext())
{
  UserProfile userProfile = profileEnumerator.Current as UserProfile;
  Console.WriteLine(userProfile.AccountName);
  i++;
}

Can please anyone suggest me that how can I query specific user by it's custom property? or how can I iterate only 1000 userprofiles at one time?

1
  • map the property SP-EmployeeID to a RefinableStringXX and then use refinement filters. Ensure that the crawl is started and completed and then values filled up in the RefinableStringXX managed property Apr 13 '18 at 14:09
0

You need to map the custom user profile property to a managed property.

I usually map to the OOTB RefinableStringXX properties.

Once done, do a crawl of your people content source. It will populate this managed property which you can then use as RefinementFilter in your code as below:

var keywordQuery = new KeywordQuery(spSite)
{
    QueryText = "*",
    KeywordInclusion = KeywordInclusion.AllKeywords,
    HiddenConstraints = "scope:" + "\"People\"",
    SourceId = new Guid("B09A7990-05EA-4AF9-81EF-EDFAB16C4E31")
};
keywordQuery.RowLimit = 7;
keywordQuery.SelectProperties.Add("AccountName");
keywordQuery.SelectProperties.Add("SP-EmployeeID");
keywordQuery.SelectProperties.Add("JobTitle");  // add some extra select properties if you want
// logic to get specific user by custom property
// here, for example, am using RefinableString01 as managed property
keywordQuery.RefinementFilters.Add("RefinableString01:C001*");  
SearchExecutor e = new SearchExecutor();
// rest of the code
6
  • For Employee ID I would not use a refinable property as it is unique to each employee. You could create a new String property. Apr 14 '18 at 12:32
  • I am not able to get SP-EmployeeID in Crawled Property selection under Search Schema for People. SP-EmployeeID is custom property which I have created. Can you guys please tell me that how can I get it for the mapping with RefinableString?
    – Hardik
    Apr 16 '18 at 11:20
  • is the full crawl of the people results source complete ? I guess with 100k users , it will take some time. Once the crawl is complete, it will appear under the people section, check the internal name of the property. Apr 16 '18 at 12:02
  • I have finished full crawl on weekend as it takes so much time to finish (You are correct on it). But still I am not able to get that property by it's internal name as well. Did I miss anything?
    – Hardik
    Apr 16 '18 at 12:05
  • hmm, are there any errors in search crawl ? IF there are errors, i think that could be an issue with your crawled property not getting created. Other than that , i think you haven't missed anything. Once the property becomes available, you can just map it as you map any property Apr 16 '18 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.