lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Renaud Delbru <>
Subject Re: Query Parser, Unary Operators and Multi-Field Query
Date Fri, 20 May 2011 17:58:12 GMT

not necessarily,

I would have expected that the default AND operator applies whenever no 
other operators are precised in the query.
As said in [1], "if one or more of the terms in a term list has an 
explicit term operator (+ or - or relational operator) the rest of the 
terms will be treated as "nice to have. For exmaple

     cat +dog -fox

Selects documents which must contain "dog" and must not contain "fox". 
Documents will rank higher if "cat" is present, but it is not required."

I would have expected such behaviour, whatever "Default Operator" as 
been defined.

But it seems that I need to use the Default Operator OR to have this 
behaviour, which breaks our current requirement (we want default 
operator AND if no operators are precised in the query).

IS there anyway to achieve this ? Or do I need to extend myself the 
queryparser contrib ?


Renaud Delbru

On 20/05/11 13:21, Steven A Rowe wrote:
> Hi Renaud,
> That's normal behavior, since you have AND as default operator.  This is equivalent to
placing a "+" in front of every element of your query.  In fact, if you removed the other
two "+"s, you would get the same behavior.  I think you'll get what you want by just switching
the default operator to "OR"?
> Steve
>> -----Original Message-----
>> From: Renaud Delbru []
>> Sent: Friday, May 20, 2011 5:10 AM
>> To:
>> Subject: Query Parser, Unary Operators and Multi-Field Query
>> Hi,
>> The behaviour of the query parser (either the standard lucene query
>> parser, or the query parser contrib) is not what I expect when I am using
>> - unary operators
>> - a multi-field query
>> - AND as default operator.
>> For example, let say I have two field fieldA and fieldB, and the
>> following query:
>> +termA +termB termC
>> Lucene query parsers will expand the query as:
>> +(fieldA:termA fieldB:termA) +(fieldA:termB fieldB:termB) +(fieldA:termC
>> fieldB:termC)
>> while I would have expected this
>> +(fieldA:termA fieldB:termA) +(fieldA:termB fieldB:termB) (fieldA:termC
>> fieldB:termC)
>> Is it the normal behaviour ? A Bug ? Am I doing something wrong ?
>> Thanks in advance for your help,
>> --
>> Renaud Delbru
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message