You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Warren <wa...@clarksnutrition.com> on 2007/10/04 00:30:50 UTC
BooleanQuery questions
I am new to Lucene and am having problems with booleanQueries. How do you write Boolean OR and AND
queries?
Is this an OR query
booleanQuery.add(query1, BooleanClause.Occur.SHOULD);
booleanQuery.add(query2, BooleanClause.Occur.SHOULD);
and is this an AND query
booleanQuery.add(query1, BooleanClause.Occur.MUST);
booleanQuery.add(query2, BooleanClause.Occur.MUST);
Is there a problem writing it this way so I can change between the two by setting booleanANDSearch
to true or false
booleanQuery.add(query1,(booleanANDSearch?BooleanClause.Occur.MUST:BooleanClause.Occur.SHOULD));
booleanQuery.add(query2,(booleanANDSearch?BooleanClause.Occur.MUST:BooleanClause.Occur.SHOULD));
Also, when I call booleanQuery.toString(), I am getting this:
(upc:creatine description:creatine content:creatine) (brand:gluten brand:free) (category:alc
category:beer)
It looks like each grouping is a query but how are the queries connected, with AND, OR or NOT?
--
Thanks,
Warren Bell
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: BooleanQuery questions
Posted by Warren <wa...@clarksnutrition.com>.
Thanks for the reply. Everything is working correctly now. I jumped the gun without debuging it
more. booleanANDSearch was not getting set correctly.
Erick Erickson wrote:
> I don't see a problem with your booleanANDSearch thingy, although
> I haven't tried it.
>
> Does toString() return the same string regardless of the value of
> booleanANDSearch? That would surprise me. The default
> is OR, so the toString output looks like booleanANDSearch is false.
>
> In general, the Lucene syntax is
> no symbol SHOULD
> + MUST
> - MUST_NOT
>
> If this doesn't help, could you give us the toString for your
> query1 and query2?
>
> Erick
>
> On 10/3/07, Warren <wa...@clarksnutrition.com> wrote:
>> I am new to Lucene and am having problems with booleanQueries. How do you
>> write Boolean OR and AND
>> queries?
>>
>> Is this an OR query
>>
>> booleanQuery.add(query1, BooleanClause.Occur.SHOULD);
>> booleanQuery.add(query2, BooleanClause.Occur.SHOULD);
>>
>> and is this an AND query
>>
>> booleanQuery.add(query1, BooleanClause.Occur.MUST);
>> booleanQuery.add(query2, BooleanClause.Occur.MUST);
>>
>> Is there a problem writing it this way so I can change between the two by
>> setting booleanANDSearch
>> to true or false
>>
>> booleanQuery.add(query1,(booleanANDSearch?BooleanClause.Occur.MUST:
>> BooleanClause.Occur.SHOULD));
>> booleanQuery.add(query2,(booleanANDSearch?BooleanClause.Occur.MUST:
>> BooleanClause.Occur.SHOULD));
>>
>> Also, when I call booleanQuery.toString(), I am getting this:
>>
>> (upc:creatine description:creatine content:creatine) (brand:gluten
>> brand:free) (category:alc
>> category:beer)
>>
>> It looks like each grouping is a query but how are the queries connected,
>> with AND, OR or NOT?
>>
>> --
>> Thanks,
>>
>> Warren Bell
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>
>
--
Thanks,
Warren Bell
Systems Administrator
Clark's Nutritional Centers
4225 Market St.
Riverside, CA 92501
951-321-1960 ext. 142
909-645-8864 mobile
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: BooleanQuery questions
Posted by Erick Erickson <er...@gmail.com>.
I don't see a problem with your booleanANDSearch thingy, although
I haven't tried it.
Does toString() return the same string regardless of the value of
booleanANDSearch? That would surprise me. The default
is OR, so the toString output looks like booleanANDSearch is false.
In general, the Lucene syntax is
no symbol SHOULD
+ MUST
- MUST_NOT
If this doesn't help, could you give us the toString for your
query1 and query2?
Erick
On 10/3/07, Warren <wa...@clarksnutrition.com> wrote:
>
> I am new to Lucene and am having problems with booleanQueries. How do you
> write Boolean OR and AND
> queries?
>
> Is this an OR query
>
> booleanQuery.add(query1, BooleanClause.Occur.SHOULD);
> booleanQuery.add(query2, BooleanClause.Occur.SHOULD);
>
> and is this an AND query
>
> booleanQuery.add(query1, BooleanClause.Occur.MUST);
> booleanQuery.add(query2, BooleanClause.Occur.MUST);
>
> Is there a problem writing it this way so I can change between the two by
> setting booleanANDSearch
> to true or false
>
> booleanQuery.add(query1,(booleanANDSearch?BooleanClause.Occur.MUST:
> BooleanClause.Occur.SHOULD));
> booleanQuery.add(query2,(booleanANDSearch?BooleanClause.Occur.MUST:
> BooleanClause.Occur.SHOULD));
>
> Also, when I call booleanQuery.toString(), I am getting this:
>
> (upc:creatine description:creatine content:creatine) (brand:gluten
> brand:free) (category:alc
> category:beer)
>
> It looks like each grouping is a query but how are the queries connected,
> with AND, OR or NOT?
>
> --
> Thanks,
>
> Warren Bell
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>