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 Phil Hoy <ph...@friendsreunited.co.uk> on 2011/11/25 13:28:35 UTC

Query a field with no value or a particular value.

Hi,

Is it possible to constrain the results of a query to return docs were a field contains no value or a particular value?

I tried  ?fq=(field:yes OR -field:[* TO *]) but I get no results even though queries with either ?fq=field:yes or ?fq=-field:[* TO *]) do return results.


Phil

Re: Query a field with no value or a particular value.

Posted by Erick Erickson <er...@gmail.com>.
You just need two clauses, something like
q=field:yes (field:* -field:[* TO *])

fq could work here too.


Best
Erick


On Fri, Nov 25, 2011 at 10:06 AM, Phil Hoy <ph...@friendsreunited.co.uk> wrote:
> Hi,
>
> Thanks for getting back to me, and sorry the default q value was *:* so I omitted it from the example.
>
> I do not have a problem getting the null values so q=*:*&fq=-field:[* TO *] indeed works but I also need the docs with a specific value e.g. fq=field:yes. Is this possible?
>
> Phil
>
> -----Original Message-----
> From: Erick Erickson [mailto:erickerickson@gmail.com]
> Sent: 25 November 2011 13:59
> To: solr-user@lucene.apache.org
> Subject: Re: Query a field with no value or a particular value.
>
> You haven't specified any "q" clause, just an "fq" clause. Try
> q=*:* -field:[* TO *]
> or
> q=*:*&fq=-field:[* TO *]
>
> BTW, the logic of field:yes -field:[* TO *] makes no sense
> You're saying "find me all the fields containing the value "yes" and
> remove from that set all the fields containing any value at all"....
>
> Best
> Erick
>
> On Fri, Nov 25, 2011 at 7:28 AM, Phil Hoy <ph...@friendsreunited.co.uk> wrote:
>> Hi,
>>
>> Is it possible to constrain the results of a query to return docs were a field contains no value or a particular value?
>>
>> I tried  ?fq=(field:yes OR -field:[* TO *]) but I get no results even though queries with either ?fq=field:yes or ?fq=-field:[* TO *]) do return results.
>>
>>
>> Phil
>>
>
> ______________________________________________________________________
> This email has been scanned by the brightsolid Email Security System. Powered by MessageLabs
> ______________________________________________________________________
>

RE: Query a field with no value or a particular value.

Posted by Phil Hoy <ph...@friendsreunited.co.uk>.
Hi,

Thanks for getting back to me, and sorry the default q value was *:* so I omitted it from the example.

I do not have a problem getting the null values so q=*:*&fq=-field:[* TO *] indeed works but I also need the docs with a specific value e.g. fq=field:yes. Is this possible?

Phil

-----Original Message-----
From: Erick Erickson [mailto:erickerickson@gmail.com] 
Sent: 25 November 2011 13:59
To: solr-user@lucene.apache.org
Subject: Re: Query a field with no value or a particular value.

You haven't specified any "q" clause, just an "fq" clause. Try
q=*:* -field:[* TO *]
or
q=*:*&fq=-field:[* TO *]

BTW, the logic of field:yes -field:[* TO *] makes no sense
You're saying "find me all the fields containing the value "yes" and
remove from that set all the fields containing any value at all"....

Best
Erick

On Fri, Nov 25, 2011 at 7:28 AM, Phil Hoy <ph...@friendsreunited.co.uk> wrote:
> Hi,
>
> Is it possible to constrain the results of a query to return docs were a field contains no value or a particular value?
>
> I tried  ?fq=(field:yes OR -field:[* TO *]) but I get no results even though queries with either ?fq=field:yes or ?fq=-field:[* TO *]) do return results.
>
>
> Phil
>

______________________________________________________________________
This email has been scanned by the brightsolid Email Security System. Powered by MessageLabs
______________________________________________________________________

Re: Query a field with no value or a particular value.

Posted by Erick Erickson <er...@gmail.com>.
You haven't specified any "q" clause, just an "fq" clause. Try
q=*:* -field:[* TO *]
or
q=*:*&fq=-field:[* TO *]

BTW, the logic of field:yes -field:[* TO *] makes no sense
You're saying "find me all the fields containing the value "yes" and
remove from that set all the fields containing any value at all"....

Best
Erick

On Fri, Nov 25, 2011 at 7:28 AM, Phil Hoy <ph...@friendsreunited.co.uk> wrote:
> Hi,
>
> Is it possible to constrain the results of a query to return docs were a field contains no value or a particular value?
>
> I tried  ?fq=(field:yes OR -field:[* TO *]) but I get no results even though queries with either ?fq=field:yes or ?fq=-field:[* TO *]) do return results.
>
>
> Phil
>