How lucene query works

I am having problem with this query and i want to understand why this is happening and how lucene evaluates fields values.

(id:1 OR id:2) OR (type:1 OR type:2) AND product:* this query gives me 1000 results

product:* AND (id:1 OR id:2) OR (type:1 OR type:2) this query gives me 994 results

And the correct answer is 994.

Can anyone tell me how this works? and why this is happening?

I am also having same issue in 2 other queries. If i interchange position of product results also change.

Thanks,
Meet Dave

Isn't logical operators evaluated in order?
Let's assume that (id:1 OR id:2) is evaluated to true and (type:1 OR type:2) to true, product:* is false.

(id:1 OR id:2) OR (type:1 OR type:2)
true OR true == true
AND product:*
true AND false == false

product:* AND (id:1 OR id:2)
false AND true == false
OR (type:1 OR type:2)
false OR true == true

If product:* evaluates to false, then its position does matter because of the different operators.

edit: to summarize it.

If product:* is false, the first query will always evaluate to false, regardless of the other fields.

If type is 1 or 2, the second query will always evaluate to true, regardless of any other field. product:* evaluation won't matter.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.