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 Geoffrey Young <ge...@modperlcookbook.org> on 2008/11/19 21:17:13 UTC

filtering on blank OR specific range

hi all :)

I'm having difficultly filtering my documents when a field is either
blank or set to a specific value.  I would have thought this would work

  fq=-Type:[* TO *] OR Type:blue

which I would expect to find all document where either Type is undefined
or Type is "blue".  my actual result set is zero.

using a similar filter

  fq=-Type:[* TO *] OR OtherThing:cat

does what I would expect (documents with undefined type or documents
with cats), so it feels like solr is getting confused with the range
negation and ORing, but only when the field is the same.  adding various
parentheses makes no difference.

I know this is kind of nebulous sounding, but I was hoping someone would
look at this and go "you're doing it wrong.  your filter should be..."

the field is defined as

  <field name="Type" type="string" indexed="true" stored="true"
multiValued="true"/>

if it matters.

tia

--Geoff

Re: filtering on blank OR specific range

Posted by Chris Hostetter <ho...@fucit.org>.
: I'm having difficultly filtering my documents when a field is either
: blank or set to a specific value.  I would have thought this would work
: 
:   fq=-Type:[* TO *] OR Type:blue

Rule#1 don't try to mix AND/OR syntax with +/- syntax ... it never works 
the way you want.

"a OR b" is just syntactic sugar for "a b" ... "-a OR b" is equivilent to 
"-a b" ... if you use debugQuery=true and look at the 
parsed_filter_queries you'll see that your fq is being parsed as...

   -Type:[* TO *]  Type:blue

...looking at it that way, odes it make sense why it doesn't match any 
documents?  there is only one "positive" clause, which is that Type == 
blue.  But then you are excluding any docs where Type has a value, so you 
get the empty set.


you could have a special "Type_empty" boolean field and use...

	fq = Type_empty:true Type:blue

...or you can play tricks with the syntax, and do something like this...

	fq = (*:* -Type:[* TO *]) Type:blue


-Hoss


Re: filtering on blank OR specific range

Posted by Thijs Vonk <vo...@gmail.com>.
I actually am looking for the same answer.
I have worked around it by indexing 'empty' fields with a dumpy value 
but this isn't an ideal situation

Thijs
On 11/19/08 10:38 PM, Geoffrey Young wrote:
> Lance Norskog wrote:
>    
>> Try:   Type:blue OR -Type:[* TO *]
>>
>> You can't have a negative clause at the beginning. Yes, Lucene should barf
>> about this.
>>      
>
> I did try that, before and again now, and still no luck.
>
> anything else?
>
> --Geoff
>    


Re: filtering on blank OR specific range

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Lance Norskog wrote:
> Try:   Type:blue OR -Type:[* TO *] 
> 
> You can't have a negative clause at the beginning. Yes, Lucene should barf
> about this.

I did try that, before and again now, and still no luck.

anything else?

--Geoff

RE: filtering on blank OR specific range

Posted by Lance Norskog <go...@gmail.com>.
Try:   Type:blue OR -Type:[* TO *] 

You can't have a negative clause at the beginning. Yes, Lucene should barf
about this.

-----Original Message-----
From: Geoffrey Young [mailto:geoff@modperlcookbook.org] 
Sent: Wednesday, November 19, 2008 12:17 PM
To: solr-user@lucene.apache.org
Subject: filtering on blank OR specific range

hi all :)

I'm having difficultly filtering my documents when a field is either blank
or set to a specific value.  I would have thought this would work

  fq=-Type:[* TO *] OR Type:blue

which I would expect to find all document where either Type is undefined or
Type is "blue".  my actual result set is zero.

using a similar filter

  fq=-Type:[* TO *] OR OtherThing:cat

does what I would expect (documents with undefined type or documents with
cats), so it feels like solr is getting confused with the range negation and
ORing, but only when the field is the same.  adding various parentheses
makes no difference.

I know this is kind of nebulous sounding, but I was hoping someone would
look at this and go "you're doing it wrong.  your filter should be..."

the field is defined as

  <field name="Type" type="string" indexed="true" stored="true"
multiValued="true"/>

if it matters.

tia

--Geoff