Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
You can meet the problem with operators even in regular find API usage (without multiple context apply as I do). Here is the sample:
//prepare "shared" filter and keep reference
var filter = new AndFilter(...);
//run first search that uses my "shared" filter
var results1 = SearchClient.Instance.Search<Document>.Filter(filter).Filter(x=> ...[additional filter 1] ...).GetResult();
//run second search that uses my "shared" filter
var results2 = SearchClient.Instance.Search<Document>.Filter(filter).Filter(x=> ... [additional filter 2] ...).GetResult();
In such case second query will have wrong filters sent with second query. It will be AND filter that includes both [additional filter 1] and [additional filter2]
Consider that is a bug.
It will be nice to get that fixed as soon as possible (operators should always return new AND|OR instance and should not modify operands) :)
It will be nice to get minor fix for 7.5.450.89 version :)
Thank you!
Hi Yauheni,
I have entered this into our bug system to make sure it is triaged and investigated.
Thank you for your reporting this!
Regards,
Håkan
Filter operators working in wrong way:
public static Filter operator &(Filter first, Filter second)
{
if (first is AndFilter)
{
((AndFilter) first).Filters.Add(second);
return first;
}
if (second is AndFilter)
{
((AndFilter) second).Filters.Insert(0, first);
return second;
}
return new AndFilter(new Filter[] { first, second });
}
As you see it can modify arguments passed. From my point of you that is wrong. It is better to return new AndFilter instance here otherwise it leads to problem when you executing ISearch.ApplyActions(context) multiple times (I have to do that for my project tasks):
You pass new context instance for each ApplyActions() call and each time it will modify same filter instance as a result context.SearchBody.Query will be wrong.