Hi everyone, I am getting funny results when searching for users. I am using the .Net Auth0 component to do the searching using the UserClient’s GetAllAsync method.
Users I have in Auth0:
scooby.doo@travelctm.com
scooby.doo1@travelctm.com
andy.layzell@travelctm.com
I am searching by email:
- When I pass in “scooby” or “scooby*” as my search term, I get zero results, when I expected 2 results.
- When I pass in “scooby.doo” or “scooby.doo*”, I get 1 result: scooby.doo@travelctm.com. I expected 2 results.
- When I pass in “scooby.doo1” or “scooby.doo1*”, I get 1 result: scooby.doo1@travelctm.com. This worked.
- When I pass in “andy” or “andy*”, I get zero results, when I expected 1 result.
- When I pass in “andy.layzell” or “andy.layzell*”, I get 1 result: andy.layzell@travelctm.com.
Can anyone explain this behaviour?
private string BuildLucerneQueryText(IUserFilter filter)
{
var searchQuery = "";
if (!string.IsNullOrEmpty(filter.Email))
{
searchQuery = $" OR email:\"{filter.Email}*\"";
}
if (!string.IsNullOrEmpty(filter.Name))
{
searchQuery = $" OR name:\"{filter.Name}*\"";
}
if (!string.IsNullOrEmpty(filter.UserId))
{
searchQuery = $" OR user_id:\"{filter.UserId}*\"";
}
if (!string.IsNullOrEmpty(filter.Username))
{
searchQuery = $" OR username:\"{filter.Username}*\"";
}
//remove the leading text " OR "
if (!string.IsNullOrEmpty(searchQuery) && searchQuery.Substring(0,4) == " OR ")
{
searchQuery = searchQuery.Substring(4);
}
//result will be searchQuery = email:"andy*"
return searchQuery.Trim();
}
public async Task<IList<UserModel>> GetAsync(IUserFilter filter)
{
var users = new List<UserModel>();
var token = GetAccessToken();
var apiClient = new ManagementApiClient(token, managementApiUri);
var filterText = BuildLucerneQueryText(filter);
if (!string.IsNullOrEmpty(filterText))
{
var apiUsers = await apiClient.Users.GetAllAsync(null, null, null, null, null, null, null, filterText, "v2");
users = apiUsers.Select(u => userModelMapper.Map(u)).ToList();
}
return users;
}