I use mine in a service that returns some json, but here is the full method that searches the index:
private List<string[]> SearchUsersAdvanced(string searchString, int topNum)
{
DocumentSearchCondition docCondition = new DocumentSearchCondition();
var condition = new SearchCondition("", SearchModeEnum.AnyWord, SearchOptionsEnum.BasicSearch, docCondition,
false);
var searchText = SearchSyntaxHelper.CombineSearchCondition(searchString, condition);
SearchParameters parameters = new SearchParameters
{
SearchFor = searchText,
SearchSort = string.Empty,
Path = string.Empty,
ClassNames = string.Empty,
CurrentCulture = LocalizationContext.PreferredCultureCode,
DefaultCulture = CultureHelper.GetDefaultCultureCode(SiteContext.CurrentSiteName),
CombineWithDefaultCulture = false,
CheckPermissions = false,
SearchInAttachments = false,
User = MembershipContext.AuthenticatedUser,
SearchIndexes = "UsersIndex",
StartingPosition = 0,
DisplayResults = topNum,
NumberOfProcessedResults = 100,
NumberOfResults = topNum,
AttachmentWhere = string.Empty,
AttachmentOrderBy = string.Empty,
BlockFieldOnlySearch = false
};
// Search
DataSet users = SearchHelper.Search(parameters);
var result = new List<string[]>();
if (users != null && users.Tables[0] != null && users.Tables[0].Rows.Count > 0)
{
foreach (DataRow user in users.Tables[0].Rows)
{
//var userToAdd = new string[] { user["username"].ToString(), user["fullname"].ToString()};
var id = user["id"].ToString();
var userId = SearchContext.GetSearchValue(id, "userid");
var avatarId = ValidationHelper.GetInteger(SearchContext.GetSearchValue(id, "UserAvatarID"), 0);
var fullname = SearchContext.GetSearchValue(id, "FullName");
var imageUrl = AvatarInfoProvider.GetUserAvatarImageUrl(avatarId, userId, null, 0, 0, 0);
var position = SearchContext.GetSearchValue(id, "UserPosition");
var department = SearchContext.GetSearchValue(id, "UserDepartment");
result.Add(new string[]
{
"user",userId.ToString(), fullname.ToString(), imageUrl,
position.ToString(),
department.ToString(),"",""
});
}
}
return result;
}
You can look at SearchResults.ascx.cs control for some more on how it works.