lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Santosh Urs <>
Subject Grouping of Boolean opeartors in Lucene..?
Date Wed, 12 Nov 2008 03:26:12 GMT

How can i use multiple Boolean operators in a search query.?

For example , from the search text field , i usually get the queries which
looks like

Any (word or phrase) and ( a list of URI's)
example::   rice land  http\://
http\:// http\://
here the search term or phrase is = rice land
URIs are= http\://
http\:// http\://

Now the way i want to build the Query is::

rice land AND ( http\:// OR
http\:// OR http\://

i tried this-

try {
	if (queryString != null && fields != null) {
                  PerFieldAnalyzerWrapper perFieldAnalyzer =
					new PerFieldAnalyzerWrapper(analyzer);
                perFieldAnalyzer.addAnalyzer("conceptURI", new

MultiFieldQueryParser mfqp = new MultiFieldQueryParser(
						fields, perFieldAnalyzer);
if (queryString.contains("http") && !queryString.startsWith("http")) {

String orgQuery =queryString.substring(0, queryString.indexOf("http"));
					String uri=queryString.substring(queryString.indexOf("http"),

uri = uri.trim();
					String[] uris = uri.split(" ");
					String tempUri="";
					for (int i = 0; i < uris.length; i++) {
						if(i== uris.length-1){
							tempUri =  tempUri + uris[i];
						}else {
							tempUri =  tempUri + uris[i]+QueryParser.OR_OPERATOR;

query = mfqp.parse(orgQuery+ QueryParser.AND_OPERATOR+ tempUri );

 is this is the correct way to  form a Query..?? Are there any other

View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message