lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: queryparser: parsing boolean logic
Date Thu, 10 Jun 2004 19:02:42 GMT
On Jun 10, 2004, at 10:47 AM, Ben Pryor wrote:
> Here is a follow-up to a previous message I posted, dealing with 
> converting
> user-entered boolean logic into a Query. Why does the QueryParser 
> construct
> the same query for the following two strings?

It has no precedence rules.  AND and OR appear to be to connect two 
terms in some kind of relationship, but BooleanQuery clauses don't work 
that way - each clause has a required/prohibited flags.  A parser would 
need to be more clever to do what you expect here...

> "apple AND orange OR pear AND grape"

(apple AND orange) OR (pear AND grape)  does what you expect.

> I think a user's expectation would be that the first query matches 
> things
> containing apple and orange, or containing pear and grape. And that the
> second query would only match things containing all four items. 
> However, the
> same query is constructed both times (the constructed query requires 
> all
> four).

I think we are running in circles with QueryParser more often than not. 
  What we really need to admit is that no single expression syntax is 
going to make everyone happy and that each application really deserves 
its own custom one.  Many thanks to the creator and maintainers of 
QueryParser, though, it is pretty decent for general purpose use.

If it's any consolation, though, I do agree with your issue here and 
think that the precedence rules should work like mathematics naturally 
does with AND and OR operators.  Changing it presents a backwards 
compatibility issue, though (which is of no concern to me personally).

	Erik


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


Mime
View raw message