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 Kaan Meralan <me...@gmail.com> on 2010/07/28 19:08:33 UTC
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?
Also is there anybody who does some performance checks on "NOT" queries? I
want to know whether there is a significant performance degradation or not
when you have "NOT" in a query.
Thanks...
//kaan
Re: How do "NOT" queries work?
Posted by Chris Hostetter <ho...@fucit.org>.
: 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