This is a Lucene limitation that negative-only boolean queries do not match anything. Solr works around this limitation for the top level only. So when you do +foo (-bar) it won't match anything because the parens create a separate boolean query with only a single negative clause. +foo -bar will work, or +foo (*:* -bar)
-Yonik On 8/10/07, Aaron Suggs <[EMAIL PROTECTED]> wrote: > Hi all, > > I'm observing odd results when using parentheses to group two or more > terms in a solr query, some of which are negated (by prefixing the > term with '-' or 'NOT ') > > For example, in the current stable version of solr, I indexed the > accompanying example docs: > [EMAIL PROTECTED]:~/solr/example/exampledocs$ java -jar post.jar *.xml > ...which contain information for two "video" related products: an ATI > video card, and an iPod. > > So the following queriesy *should* return one hit, the ATI card: > name:video AND (-features:podcasts) > name:video AND (NOT features:podcasts) > > ...but they returns zero hits. Strangely, if I move the negation > outside the parentheses, the queries properly return one result: > > name:video AND -(features:podcasts) > > name:video AND NOT (features:podcasts) > > Here are some other problematic queries that should return 1 result, > but return zero: > > name:video AND (-features:podcasts) AND -features:itunes > name:video AND (-features:podcasts AND -features:itunes) > (name:video) AND (-features:podcasts) AND (-features:itunes) > > But these logically-equivalent queries return the correct results: > name:video AND -features:podcasts AND -features:itunes > (name:video AND -features:podcasts AND -features:itunes) > name:video AND -(features:podcasts OR features:itunes) > > Generally whenever I include negations inside a grouping, Solr returns > zero hits. The only exception to this is when I group the entire > search. The following queries work properly: > (name:video AND -features:podcasts) > (name:video AND NOT features:podcasts) > ...I suspect this is due to the parser simply stripping off the > parentheses before further tokenizing the query. > > Is this a bug, or am I doing something wrong? It seems rather limiting > to only allowing grouping of 'AND' and 'OR" operators, but not > negation operators. > > Cheers, > Aaron Suggs >