Try our conversational search powered by Generative AI!

Filter operators & | !


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.

May 26, 2014 15:19

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!

Edited, May 26, 2014 16:25

Any comments?

May 26, 2014 18:17

That is really critical for me.

May 26, 2014 18:41

Hi Yauheni,

I have entered this into our bug system to make sure it is triaged and investigated.

Thank you for your reporting this!


May 26, 2014 19:10
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.