lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From AHMET ARSLAN <iori...@yahoo.com>
Subject Re: Generating Query for Multiple Clauses in a Single Field
Date Tue, 28 Jul 2009 10:28:28 GMT

> generate a query like the following:
> title:(+chemistry +"national curriculum")

I didn't understand what exactly you are asking but the query string is already well-formatted.
You can pass this string directly to the parse method of QueryParser. The following four examples
yields the same Query object.

String[] ar = {"title:(+chemistry +\"national curriculum\")"};
org.apache.lucene.queryParser.QueryParser.main(ar);

String[] ar1 = {"title:(chemistry AND \"national curriculum\")"};
org.apache.lucene.queryParser.QueryParser.main(ar1);

QueryParser qp = new QueryParser("title", new StandardAnalyzer());
Query q = qp.parse("chemistry AND \"national curriculum\"");
System.out.println(q.toString());

qp.setDefaultOperator(QueryParser.AND_OPERATOR);
q = qp.parse("chemistry \"national curriculum\"");
System.out.println(q.toString());

> its mention that it can be done using the QueryParser but
> unfortunately I can't find any reference in how to used it. 

http://lucene.apache.org/java/2_4_1/queryparsersyntax.html
Just prepare a String according to descriptions in here, and pass it to the parse method of
QueryParser.



      

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


Mime
View raw message