You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Chris Hostetter <ho...@fucit.org> on 2010/08/07 03:53:55 UTC
Re: How do "NOT" queries work?
: I wonder how do "NOT" queries work. Is it a pass on the result set and
: filtering out the "NOT" property or something like that?
it depends on what you mean by a "not" query.
If you mean at a low level: a Query object that is a BooleanQuery
consisting purely of Clauses that have the MUST_NOT property -- then the
answer is they don't work at all. Queries must positively select
something to be functional.
If you mean at a high level: what solr does when you write something like
q=-foo%2B-bar (ie: you write a query string that only contains
negative clauses) then the answer is that internally solr adds a
MatchAllDocs query to the BooleanQuery it generates.
That said: in the case of filter queries and facet queries and what not,
where all you care about is the DocSet (not scoring), then what solr
does is "invert" the purely negative query, generates a result (or reads
the result from cache) and then intersects it with a DocSet matching all
documents ... so fq=-foo and fq=foo are cache hits for eachother.
-Hoss