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 Arun Rangarajan <ar...@gmail.com> on 2013/05/13 22:11:27 UTC

Solr Boolean query help

I am trying to form a Solr query. Our documents have a multi-valued field
named tag_id. I want to get documents that either do not have tag_id 1 or
have both tag_id 1 and 2 i.e.
q=(tag_id:(1 AND 2) OR tag_id:(NOT 1))

This is not giving the desired results. The result is the same as that of
q=tag_id:(1 AND 2)
and the OR condition is ignored.
How would one do this query?

Re: Solr Boolean query help

Posted by Arun Rangarajan <ar...@gmail.com>.
Erik, Jack,
Thanks for your quick replies! That works.


On Mon, May 13, 2013 at 1:18 PM, Jack Krupansky <ja...@basetechnology.com>wrote:

> Pure negative queries only work at the top level.
>
> So, try:
>
> q=(tag_id:(1 AND 2) OR tag_id:(*:* NOT 1))
>
>
> -- Jack Krupansky
> -----Original Message----- From: Arun Rangarajan Sent: Monday, May 13,
> 2013 4:11 PM To: solr-user@lucene.apache.org Subject: Solr Boolean query
> help
>  I am trying to form a Solr query. Our documents have a multi-valued field
> named tag_id. I want to get documents that either do not have tag_id 1 or
> have both tag_id 1 and 2 i.e.
> q=(tag_id:(1 AND 2) OR tag_id:(NOT 1))
>
> This is not giving the desired results. The result is the same as that of
> q=tag_id:(1 AND 2)
> and the OR condition is ignored.
> How would one do this query?
>

Re: Solr Boolean query help

Posted by Jack Krupansky <ja...@basetechnology.com>.
Pure negative queries only work at the top level.

So, try:

q=(tag_id:(1 AND 2) OR tag_id:(*:* NOT 1))


-- Jack Krupansky
-----Original Message----- 
From: Arun Rangarajan 
Sent: Monday, May 13, 2013 4:11 PM 
To: solr-user@lucene.apache.org 
Subject: Solr Boolean query help 

I am trying to form a Solr query. Our documents have a multi-valued field
named tag_id. I want to get documents that either do not have tag_id 1 or
have both tag_id 1 and 2 i.e.
q=(tag_id:(1 AND 2) OR tag_id:(NOT 1))

This is not giving the desired results. The result is the same as that of
q=tag_id:(1 AND 2)
and the OR condition is ignored.
How would one do this query?

Re: Solr Boolean query help

Posted by Erik Hatcher <er...@gmail.com>.
Inner purely negative clauses aren't allowed by Lucene.  (Solr supports top-level negative clauses, though, so <q=NOT foo> works as expected)

To get a nested negative clause to work, try this:

    q=tag_id:(1 AND 2) OR (*:* AND -tag_id:1)



On May 13, 2013, at 16:11 , Arun Rangarajan wrote:

> I am trying to form a Solr query. Our documents have a multi-valued field
> named tag_id. I want to get documents that either do not have tag_id 1 or
> have both tag_id 1 and 2 i.e.
> q=(tag_id:(1 AND 2) OR tag_id:(NOT 1))
> 
> This is not giving the desired results. The result is the same as that of
> q=tag_id:(1 AND 2)
> and the OR condition is ignored.
> How would one do this query?