Hi,
There have been examples in this group or the presentations where the `OnBeforeQuery` event has been used to further constraint the query, like in Multi-Tenant or Soft-Delete scenarios.
The provided approach can lead to very undesired behavior if there is any `OR` comparison used in the query:
Existing `OnBeforeQuery` examples:
Multi-tenant:
dynamic query = e.QueryCustomization;
query.AndAlso();
query.WhereEquals("TenantId", tenant.Id);
Soft delete:
switch (e.QueryCustomization)
{
case IDocumentQuery<User> userQuery:
userQuery.AndAlso().WhereEquals("IsDeleted", false);
break;
case IAsyncDocumentQuery<User> userAsyncQuery:
userAsyncQuery.AndAlso().WhereEquals("IsDeleted", false);
break;
default:
break;
}
Problematic example:
Let's say we use the soft-delete approach described above with the following query where we have an `or` condition:
session.Query<Article>().search(article => article.Title, "foo").search(article => article.Description, "bar", options: SearchOptions.Or);
The final query produced will be:
select from 'Articles' where search(Title, "foo") or search(Description, "Bar") and IsDeleted = false;
This will return articles where the title matches "foo" disregarding the "IsDeleted" constraint.
Question:
Is there a way the `OnBeforeQuery` callback can be modified to enclose the existing query conditions into brackets, before adding the `.AndAlso().WhereEquals()` condition? That would eventually solve the problem.