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 Daniel Naber <lu...@danielnaber.de> on 2006/12/05 22:03:51 UTC

too many parentheses confuse Lucene

Hi,

a query like 
(-merkel) AND schröder 

is parsed as
+(-body:merkel) +body:schröder

I get no hits for this query because +(-body:merkel) doesn't return any 
hits (it's not a valid query for Lucene). However, a query like

-merkel AND schröder 

works fine. From the user's point-of-view, both queries should return the 
same result set. One solution I see is to add a MatchAllDocsQuery clause 
to all prohibited clauses in QueryParser's getBooleanQuery() method. Is 
that a valid solution? I tried with some simple cases and it seems to 
work. Any other ideas to solve or work around this issue?

Regards
 Daniel

-- 
http://www.danielnaber.de

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: too many parentheses confuse Lucene

Posted by Chris Hostetter <ho...@fucit.org>.
: works fine. From the user's point-of-view, both queries should return the
: same result set. One solution I see is to add a MatchAllDocsQuery clause
: to all prohibited clauses in QueryParser's getBooleanQuery() method. Is
: that a valid solution? I tried with some simple cases and it seems to
: work. Any other ideas to solve or work around this issue?

if i understand your implimentation suggestion correctly, that will cause
some very unexpected results when people pass "(a -b) c" to
QueryParser.parse .... but as far as the general idea you are proposing,
i'm very leary of leting QueryParser make any asusmptions about what a
user means when they specify a query ... I've acctually got some code in
production that users QueryParser to parse query fragments fro ma config
file, which are then combined with other Queries ... if QueryParser all of
the sudden decided that...
	(-apple -orange)
...should be parsed the same as...
	(*:* -apple -orange)
...now my code that combines the Query i get from QueryParser with other
Queryies from other parts of my code base will unexpected match all
documents.

Once upon a time the notion that QueryParser should throw an
ParseException when it detected a query that was syntacticly valid but
structurally unusable was discussed ... and ultimately rejected for the
same reason: QueryParser should make any assumptions about how the Queries
it parses are going to be used.



-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org