On 11/20/2012 1:27 PM, Ravi Solr wrote:
Can somebody kindly clarify how negative queries work. I having this weird
issue with an analyzed text field. I want to find all docs which don't have
a value in the 'body' field. The field definition and query i am using is
given below. Can somebody tell me what I am doing wrong ??

<snip>

QUERY
------------
http://testserver/solr/mycore/select/?q=*:*&start=0&rows=30&fl=systemid,body&fq=contenttype:"Article";
-body:[* TO *] pubdatetime:[2007-01-01T23:59:59Z TO
2010-12-31T00:00:00Z]&debugQuery=on

I get back the following doc which HAS the body, why does it match even
though I specifically asked solr for docs NOT containing body ???

Without knowing anything about how Solr is configured, I would guess that it is because of a default operator of "OR" making it so that any of those filter clauses will match. Give the following filter a try:

fq=contenttype:"Article" AND -body:[* TO *] AND pubdatetime:[2007-01-01T23:59:59Z TO 2010-12-31T00:00:00Z]

Alternately, you could use three separate filters:

fq=contenttype:"Article"
fq=*:* AND -body:[* TO *]
fq=pubdatetime:[2007-01-01T23:59:59Z TO 2010-12-31T00:00:00Z]

Thanks,
Shawn

Reply via email to