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 karanjindal <ka...@students.iiit.ac.in> on 2013/07/31 08:14:25 UTC

Negative Query Behaviour in Solr 3.2

Hi All,

I am using solr 3.2 and confused how a particular query is executed.
q=name:memory OR -name:encoded
separately firing q=name:memory gives 3 results 
and q=-name:encoded gives 25 results and result sets are disjoint sets.

Since I am doing OR query it should return 28 results, but it is only
returning 3 results same as query (name:memory).

Can anyone explain?

-Karan




--
View this message in context: http://lucene.472066.n3.nabble.com/Negative-Query-Behaviour-in-Solr-3-2-tp4081538.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Negative Query Behaviour in Solr 3.2

Posted by Jack Krupansky <ja...@basetechnology.com>.
Since there are no parentheses, the terms and operators are all at the save 
level and the "OR" is essentially a redundant operator and ignored, so:

q=name:memory OR -name:encoded

is treated as:

q=name:memory -name:encoded

When what you probably want is:

q=name:memory OR (-name:encoded)

BUT... a bug/deficiency prevents Solr from handling pure-negative 
sub-queries properly, so you have to add a "*:*":

q=name:memory OR (*:* -name:encoded)

So that reads "... or any documents that do not contain encoded in the name 
field", which is equivalent to "... or all documents except those that have 
encoded in the name field".

-- Jack Krupansky

-----Original Message----- 
From: karanjindal
Sent: Wednesday, July 31, 2013 2:14 AM
To: solr-user@lucene.apache.org
Subject: Negative Query Behaviour in Solr 3.2

Hi All,

I am using solr 3.2 and confused how a particular query is executed.
q=name:memory OR -name:encoded
separately firing q=name:memory gives 3 results
and q=-name:encoded gives 25 results and result sets are disjoint sets.

Since I am doing OR query it should return 28 results, but it is only
returning 3 results same as query (name:memory).

Can anyone explain?

-Karan




--
View this message in context: 
http://lucene.472066.n3.nabble.com/Negative-Query-Behaviour-in-Solr-3-2-tp4081538.html
Sent from the Solr - User mailing list archive at Nabble.com. 


Re: Negative Query Behaviour in Solr 3.2

Posted by Mikhail Khludnev <mk...@griddynamics.com>.
Can you try:

q=+name:memory -name:encoded
or
q=name:memory AND -name:encoded



On Wed, Jul 31, 2013 at 10:14 AM, karanjindal <
karan_jindal@students.iiit.ac.in> wrote:

> Hi All,
>
> I am using solr 3.2 and confused how a particular query is executed.
> q=name:memory OR -name:encoded
> separately firing q=name:memory gives 3 results
> and q=-name:encoded gives 25 results and result sets are disjoint sets.
>
> Since I am doing OR query it should return 28 results, but it is only
> returning 3 results same as query (name:memory).
>
> Can anyone explain?
>
> -Karan
>
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Negative-Query-Behaviour-in-Solr-3-2-tp4081538.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>



-- 
Sincerely yours
Mikhail Khludnev
Principal Engineer,
Grid Dynamics

<http://www.griddynamics.com>
 <mk...@griddynamics.com>