Try our conversational search powered by Generative AI!

Filter operators & | !

Vote:
 

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.

#86604
May 26, 2014 15:19
Vote:
 

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!

#86610
Edited, May 26, 2014 16:25
Vote:
 

Any comments?

#86616
May 26, 2014 18:17
Vote:
 

That is really critical for me.

#86617
May 26, 2014 18:41
Vote:
 

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

#86619
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.