lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hoss Man (JIRA)" <>
Subject [jira] Commented: (LUCENE-72) [PATCH] Query parser inconsistency when using terms to exclude.
Date Wed, 30 Aug 2006 17:54:23 GMT
    [ ] 
Hoss Man commented on LUCENE-72:

I think the general issue here is that mixing syntax (ie: using AND, OR or NOT along with
"+" and "-") is not something that works very well in the QueryParser.

At the lowest level the "+" and "-" syntax most closely models the way Lucene BooleanQueries
work -- most specificly, they are not truely BooleanQueries -- they are agregation queries,
in which each sub query can be required, optional or prohibited -- but at least one most always
"match" and positively select some documents.  (it is invalide to have a BooleanQuery containing
all "prohibited" clauses)

Setting the default operator onthe QueryParser to be "OR" or "AND" really just tells the QueryParser
whether you want the default property of the sub-queries to be "optional" or "required" in
the absense of other information.

when specifying a query like:   +(fruits vegetables) AND (-tomatoes -bananas)
...this is really just a varient expression of:   +(fruits vegetables) +(-tomatoes -bananas)
...which is not a valid query becuse the second clause doesn't match anything

when specifing a query like:     fruits OR -tomatoes
...this is really just a varient expression of:   fruits -tomatoes
...which (since there is only one "optional" clause and no "required" clauses) will only match
documents containing the word "fruits" as long as they do not match the word "tomatoes"

in short ... things are behaving as expected.  The only question is wether documentation might
be improved to make the behavior more clear to people.

as for the (now very old) patches to this bug ... they don't acctually seem to be related
at all as far as i can tell.

> [PATCH] Query parser inconsistency when using terms to exclude.
> ---------------------------------------------------------------
>                 Key: LUCENE-72
>                 URL:
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: QueryParser
>    Affects Versions: 1.2
>         Environment: Operating System: All
> Platform: PC
>            Reporter: Carlos
>         Assigned To: Lucene Developers
>         Attachments: patch6.txt, patch7.txt,,
> Hi.
> The problem I am having occurs when using queryparser and also when building the
> query using the API.
> Assume that we want to look for documents about fruits or vegetables but 
> excluding tomatoes and bananas. I suppose the right query sould be:
> +(fruits vegetables) AND (-tomatoes -bananas)
> wich I think is equivalent to (if tou parse it and then print the query.toString
> ("") result that is what you get)
> +(fruits vegetables) +(-tomatoes -bananas)
> but the query doesn't work as expected, in fact the query that works is
> +(fruits vegetables) -(-tomatoes -bananas)
> which doesn´t really make much sense, because the second part seems to say:
> All documents where the condition "tomatoes is not present and bananas is not 
> present " is false, which means the opposite.
> In fact, second query works as (even if they look quite opposite):
> +(fruits vegetables) -tomatoes -bananas
> Hope someone could help, thanks

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:


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

View raw message