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 Satish Kumar <sa...@gmail.com> on 2010/05/11 18:19:44 UTC

grouping in fq

Hi,

How do I implement a requirement like "if category is xyz, the price should
be greater than 100 for inclusion in the result set".

In other words, the result set should contain:
- all matching documents with category value not xyz
- all matching documents with category value xyz and price > 100

I was thinking something like fq=(-category:xyz OR (category:xyz AND price >
100))

this doesn't seem to work. Any suggestions will be greatly appreciated.


thanks,
Satish

Re: grouping in fq

Posted by Chris Hostetter <ho...@fucit.org>.
: Wait. If the default op is OR, I thought this query:
: 
: (+category:xyz +price:[100 TO *]) -category:xyz
: 
: meant "with xyz and range, OR without xyz" because without a plus or

Nope.  regardless of hte default op, you've got a BooleanQuery with two 
clauses, one of which is negative.  the other clauses is either mandatory 
because the default op says it should be, or it's mandatory because it's 
the only "SHOULD" clause and there are not "MUST" clauses.

consider it written out a little more simply...

        (+A +B) -A

...the params arround the A and B clauses make them a BooleanQuery 
which we can call X...

	X -A

...and now hopefully it's clear: A is prohibited, and since there aren't 
any mandatory clauses, and there is only one optional clause, that 
optional clause (X) is now mandatory ... Since X = (+A +B), that means (+A 
+B) is mandatory.  

so we get no matches because we can't match A and -A at the same time.

: minus, OR really means SHOULD (which, bizzarely, is not a keyword).

(yeah, it anoyes me that there is no prefix markup for "SHOULD" ... it 
wouldn't be so bad except thta if you change the default op to MUST there 
is no way of expression whole families of queries .. that's why i never 
recomend making the default op MUST)


-Hoss


Re: grouping in fq

Posted by Lance Norskog <go...@gmail.com>.
Wait. If the default op is OR, I thought this query:

(+category:xyz +price:[100 TO *]) -category:xyz

meant "with xyz and range, OR without xyz" because without a plus or
minus, OR really means SHOULD (which, bizzarely, is not a keyword).

(+category:xyz +price:[100 TO *]) (-category:xyz)

Is this what I'm thinking of? Does this really need an OR in the middle?

On Thu, May 13, 2010 at 9:48 AM, Chris Hostetter
<ho...@fucit.org> wrote:
>
> : >> (+category:xyz +price:[100 TO *]) -category:xyz
> :
> : this one doesn't seem to work (I'm not using a price field, but a text field
> : -- using price field here just for example).
>
> it never will, it's saying only things that are in category xyz and above
> 100 dollars can match, but anything in category xyz can not match.
>
> inherient contradiction.
>
> : (+category:xyz +price:[100 TO *]) (-category:xyz) -- returns only results
> : with category xyz and price >=100
>
> you can't have a pure negative clauses in a boolean query -- they match
> nothing (by definition: a query that only rejects things doesn't select
> anything) the second set of parens creates a boolean query with one
> negative clause, so it selects nothing, hence you only get docs matching
> the first part.
>
>
> : (+category:xyz +price:[100 TO *]) (*:* -category:xyz) -- returns results
> : with category xyz and price >=100 AND results where category!=xyz
>
> exactly.  *:* selects all docs, and -category:xyz then rejects the ones in
> category xyz.  these are then combined with the docs from the first part
> (in cat xyz and above 100)
>
> so now you have what you want...
>
> : > >> > How do I implement a requirement like "if category is xyz,
> : > >> > the price should
> : > >> > be greater than 100 for inclusion in the result set".
>
>
> -Hoss
>
>



-- 
Lance Norskog
goksron@gmail.com

Re: grouping in fq

Posted by Chris Hostetter <ho...@fucit.org>.
: >> (+category:xyz +price:[100 TO *]) -category:xyz
: 
: this one doesn't seem to work (I'm not using a price field, but a text field
: -- using price field here just for example).

it never will, it's saying only things that are in category xyz and above 
100 dollars can match, but anything in category xyz can not match.

inherient contradiction.

: (+category:xyz +price:[100 TO *]) (-category:xyz) -- returns only results
: with category xyz and price >=100

you can't have a pure negative clauses in a boolean query -- they match 
nothing (by definition: a query that only rejects things doesn't select 
anything) the second set of parens creates a boolean query with one 
negative clause, so it selects nothing, hence you only get docs matching 
the first part.


: (+category:xyz +price:[100 TO *]) (*:* -category:xyz) -- returns results
: with category xyz and price >=100 AND results where category!=xyz

exactly.  *:* selects all docs, and -category:xyz then rejects the ones in 
category xyz.  these are then combined with the docs from the first part 
(in cat xyz and above 100)

so now you have what you want...

: > >> > How do I implement a requirement like "if category is xyz,
: > >> > the price should
: > >> > be greater than 100 for inclusion in the result set".


-Hoss


Re: grouping in fq

Posted by Satish Kumar <sa...@gmail.com>.
>> (+category:xyz +price:[100 TO *]) -category:xyz

this one doesn't seem to work (I'm not using a price field, but a text field
-- using price field here just for example).

Below are some other variations I tried:

(+category:xyz +price:[100 TO *]) -category:xyz -- zero results
(+category:xyz +price:[100 TO *]) (-category:xyz) -- returns only results
with category xyz and price >=100
(+category:xyz +price:[100 TO *]) (*:* -category:xyz) -- returns results
with category xyz and price >=100 AND results where category!=xyz


On Wed, May 12, 2010 at 2:54 PM, Lance Norskog <go...@gmail.com> wrote:

> Because leading negative clauses don't work. The (*:* AND x) syntax
> means "select everything AND also select x".
>
> You could also do
> (+category:xyz +price:[100 TO *]) -category:xyz
>
> On Tue, May 11, 2010 at 12:36 PM, Satish Kumar
> <sa...@gmail.com> wrote:
> > thanks Ahmet.
> >
> > (+category:xyz +price:[100 TO *]) (+*:* -category:xyz)
> > why do we have to use (+*:* -category:xyz) instead of  -category:xyz?
> >
> >
> >
> > On Tue, May 11, 2010 at 3:08 PM, Ahmet Arslan <io...@yahoo.com> wrote:
> >
> >> > How do I implement a requirement like "if category is xyz,
> >> > the price should
> >> > be greater than 100 for inclusion in the result set".
> >> >
> >> > In other words, the result set should contain:
> >> > - all matching documents with category value not xyz
> >> > - all matching documents with category value xyz and price
> >> > > 100
> >> >
> >> > I was thinking something like fq=(-category:xyz OR
> >> > (category:xyz AND price >
> >> > 100))
> >> >
> >> > this doesn't seem to work. Any suggestions will be greatly
> >> > appreciated.
> >>
> >> Something like this should work:
> >> (+category:xyz +price:[100 TO *]) (+*:* -category:xyz)
> >>
> >> and your price field must be one of the trie based fields.
> >>
> >>
> >>
> >>
> >
>
>
>
> --
> Lance Norskog
> goksron@gmail.com
>

Re: grouping in fq

Posted by Lance Norskog <go...@gmail.com>.
Because leading negative clauses don't work. The (*:* AND x) syntax
means "select everything AND also select x".

You could also do
(+category:xyz +price:[100 TO *]) -category:xyz

On Tue, May 11, 2010 at 12:36 PM, Satish Kumar
<sa...@gmail.com> wrote:
> thanks Ahmet.
>
> (+category:xyz +price:[100 TO *]) (+*:* -category:xyz)
> why do we have to use (+*:* -category:xyz) instead of  -category:xyz?
>
>
>
> On Tue, May 11, 2010 at 3:08 PM, Ahmet Arslan <io...@yahoo.com> wrote:
>
>> > How do I implement a requirement like "if category is xyz,
>> > the price should
>> > be greater than 100 for inclusion in the result set".
>> >
>> > In other words, the result set should contain:
>> > - all matching documents with category value not xyz
>> > - all matching documents with category value xyz and price
>> > > 100
>> >
>> > I was thinking something like fq=(-category:xyz OR
>> > (category:xyz AND price >
>> > 100))
>> >
>> > this doesn't seem to work. Any suggestions will be greatly
>> > appreciated.
>>
>> Something like this should work:
>> (+category:xyz +price:[100 TO *]) (+*:* -category:xyz)
>>
>> and your price field must be one of the trie based fields.
>>
>>
>>
>>
>



-- 
Lance Norskog
goksron@gmail.com

Re: grouping in fq

Posted by Satish Kumar <sa...@gmail.com>.
thanks Ahmet.

(+category:xyz +price:[100 TO *]) (+*:* -category:xyz)
why do we have to use (+*:* -category:xyz) instead of  -category:xyz?



On Tue, May 11, 2010 at 3:08 PM, Ahmet Arslan <io...@yahoo.com> wrote:

> > How do I implement a requirement like "if category is xyz,
> > the price should
> > be greater than 100 for inclusion in the result set".
> >
> > In other words, the result set should contain:
> > - all matching documents with category value not xyz
> > - all matching documents with category value xyz and price
> > > 100
> >
> > I was thinking something like fq=(-category:xyz OR
> > (category:xyz AND price >
> > 100))
> >
> > this doesn't seem to work. Any suggestions will be greatly
> > appreciated.
>
> Something like this should work:
> (+category:xyz +price:[100 TO *]) (+*:* -category:xyz)
>
> and your price field must be one of the trie based fields.
>
>
>
>

Re: grouping in fq

Posted by Ahmet Arslan <io...@yahoo.com>.
> How do I implement a requirement like "if category is xyz,
> the price should
> be greater than 100 for inclusion in the result set".
> 
> In other words, the result set should contain:
> - all matching documents with category value not xyz
> - all matching documents with category value xyz and price
> > 100
> 
> I was thinking something like fq=(-category:xyz OR
> (category:xyz AND price >
> 100))
> 
> this doesn't seem to work. Any suggestions will be greatly
> appreciated.

Something like this should work:
(+category:xyz +price:[100 TO *]) (+*:* -category:xyz)

and your price field must be one of the trie based fields.