I need to query a field and a string list for the same value, I started creating a custom search method but I can’t figure out how to add another query parameter, I tried using .AddCondition on my MemoryDataSource to no avail.
How do I add another condition or query after I call:
var q = AutoQuery.CreateQuery(query, Request, db);
Thanks Mythz but I am using IAutoQueryData which doesn’t provide that type, “db” is a MemoryDataSource.
Should this work out of the box? meaning the Search endpoints can inspect lists within a record?
This is what I have so far but it doesn’t work, ProxyAddresses is List[string] and I would need to perform a case insensitive search on it.
public object Any(SearchWindowsUsers query)
{
var windowsUsers = WindowsUserManagementUtilities.GetWindowsUsers(false, true);
var db = new MemoryDataSource<WindowsUser>(windowsUsers, query, Request);
var q = AutoQuery.CreateQuery(query, Request, db);
if (!string.IsNullOrWhiteSpace(query.Email))
{
var field = typeof(WindowsUser).GetProperty(nameof(WindowsUser.ProxyAddresses));
q.AddCondition(QueryTerm.Or, field, InCollectionCondition.Instance, query.Email);
}
var users = AutoQuery.Execute(query, q, Request, db);
return users;
}
}
Yeah adding a condition should work, but it wont do a case insensitive match, you should be able to do a custom condition that does it with:
public class CaseInsensitiveInCollectionCondition : QueryCondition, IQueryMultiple
{
public static CaseInsensitiveInCollectionCondition Instance = new();
public override string Alias => ConditionAlias.In;
public override bool Match(object a, object b)
{
var bValues = b as IEnumerable;
if (bValues == null)
return new CaseInsensitiveEqualCondition().Match(a, b);
foreach (var item in bValues)
{
if (new CaseInsensitiveEqualCondition().Match(a, item))
return true;
}
return false;
}
}
Otherwise you can always apply an in memory filter after query is executed.
If you don’t specify a cacheKey on the 4th argument it uses the GET Url for the request which varies depending on the Request, you can search for aqd* keys on your Redis Instance to find the cache keys used.