On 1/10/24 15:22, Ing. Andrea Vettori wrote:
Is it the expected behaviour that a query like

someotherconditions OR -field:value

returns different result than

someotherconditions OR (-field:value)

It seems to me that the first works like the OR is instead and AND.

Welcome to the fun world of negative queries.

The way you should construct that query to remove all ambiguity is:

someotherconditions OR (*:* -field:value)

The reason this is a problem is that a negative clause like that is a subtraction. So your first query is basically "Give me all documents that meet these conditions and then subtract documents where "field" is "value". Which is most likely NOT what you were wanting to get.

With the second form, because the purely negative query is separated by the parentheses, Solr is able to detect the incorrect syntax, and it automatically adds the "all documents" before the negative query so the effective query is what I suggested above.

Solr is only able to detect a purely negative query if it is not mixed in with other clauses.

Thanks,
Shawn

Reply via email to