We are passing a custom property (CustomID) as an input to the KeywordQuery Search API, which in turn will fetch the Account name for the user.
string
strAccountName =
string
.Empty;
SPSite currentSite =
new
SPSite(SPContext.Current.Site.ID);
KeywordQuery peopleQuery =
new
KeywordQuery(currentSite);
peopleQuery.ResultsProvider = SearchProvider.SharepointSearch;
peopleQuery.RowLimit = 2;
peopleQuery.HiddenConstraints =
"scope:"
+
"\"People\""
;
peopleQuery.ResultTypes = ResultType.RelevantResults;
peopleQuery.QueryText =
"CustomId:"
+ strCustomId;
//where CustomId will the managed property and strCustimId will be the value of the search
peopleQuery.SelectProperties.Add(
"CustomID"
);
peopleQuery.SelectProperties.Add(
"AccountName"
);
ResultTableCollection resultCollection = peopleQuery.Execute();
if
(resultCollection.Exists(ResultType.RelevantResults))
{
ResultTable result = resultCollection[ResultType.RelevantResults];
DataTable tblResult =
new
DataTable();
tblResult.TableName =
"CustomIdMatch"
;
tblResult.Load(result, LoadOption.OverwriteChanges);
if
(tblResult.Rows.Count > 0)
{
strAccountName = Convert.ToString(tblResult.Rows[0][
"AccountName"
]);
}
}