lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Pryor <>
Subject queryparser: parsing boolean logic
Date Thu, 10 Jun 2004 14:47:48 GMT
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?


"apple AND orange OR pear AND grape"

"apple AND orange AND pear AND grape"


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




import org.apache.lucene.analysis.standard.StandardAnalyzer;

import org.apache.lucene.queryParser.ParseException;

import org.apache.lucene.queryParser.QueryParser;



import junit.framework.TestCase;


public class QPTest extends TestCase


            public QPTest(String arg0)





            private void display(String s, Query q)


                        System.out.println("\"" + s + "\" = \"" +
q.toString() + "\"");



            public void testBooleanConstruction() throws ParseException


                        String test1 = "apple AND orange OR pear AND grape";

                        String test2 = "apple AND orange AND pear AND


                        QueryParser qp = new QueryParser("df", new


                        Query query1 = qp.parse(test1);

                        Query query2 = qp.parse(test2);


                        display(test1, query1);

                        display(test2, query2);                



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message