lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven A Rowe <sar...@syr.edu>
Subject RE: Query Parser, Unary Operators and Multi-Field Query
Date Fri, 20 May 2011 18:26:24 GMT
Hi Renaud,

On 5/20/2011 at 1:58 PM, Renaud Delbru wrote:
> As said in 
> <http://lucidworks.lucidimagination.com/display/LWEUG/Boolean+Operators>, 
> "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.

I am not familiar with Lucid's offerings, so I can't comment on the documentation you quoted.
 Note, however, that LucidWorks and Lucene are different products.

> I would have expected that the default AND operator applies whenever no
> other operators are precised in the query.
>
> 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).

Restating: you want default AND behavior when the query contains no operators, and default
OR behavior when the query *does* contain operators.

This is not supported by the Lucene QueryParser.

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

A workaround may be to simply look for "+" and "-" in the query under one of the following
conditions: preceded either by "(" or " ", or at the beginning of the string, e.g. using a
regex like /(?:^|[\s(])[+-]/, and if you find a match, use default OR operator, and if not,
use default AND operator?

Steve

Mime
View raw message