Solr supports pure negative queries. They do this, essentially, by expanding the pure negative to something like:
*:* -startDate:[* TO *]
However, what you combine it in a BooleanQuery, I don't believe it applies this sort of logic anymore. A negative query does not, in lucene, fetch anything, but rather filters out matches brought in by other, positive, query terms. This differs from SQL queries, which in a sense start with an implicit *:*
, or a full table of results, and allow you to pare it down.
I believe your OR
is effectively being ignored, since it doesn't, strictly speaking, make sense in context. Generally, OR
is just syntactic sugar, I believe (field:this OR field:that
is equivalent to field:this field:that
).
So, in effect your query is: startDate:[* TO NOW/DAY+1DAY] -startDate:[* TO *]
, which makes the results you see more obvious. When you wrap it in parentheses, then each term query is treated separately, and you gain access to solr
's support of lonely negative queries.
A much better idea is to store a default value, if you need to search for unset/null values. *:*
and by extension pure negative queries like this have to scan the entire index, and so perform very poorly. Providing a default value will improve performance, and prevent this sort of confusing situation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…