Hi, You can use Boolean query for the same. Boolean query is meant for having a series of queries with boolean operators defined. For eg. lets say you have 3 diff queries A, B, C and you want a final query which behaves as A && (B || C) BooleanQuery query = new BooleanQuery(); BooleanQuery temp = new BooleanQuery(); temp.add(B, Occur.SHOULD); //Occur.SHOULD is equvalent to OR operator temp.add(C, Occur.SHOULD); query.add(A, Occur.MUST); //Occur.MUST is equivalent to an AND operator query.add(temp, Occur.Must);
Now "query" = A && (B || C) Go through lucene documentation about Boolean query Hope it helps. Prabin On Wed, Nov 12, 2008 at 8:56 AM, Santosh Urs <[EMAIL PROTECTED]> wrote: > > 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\://www.wtr.org/wordlist#c_2379 > http\://www.wtr.org/wordlist#c_65748 http\://www.wtr.org/wordlist#c_7612 > here the search term or phrase is = rice land > URIs are= http\://www.wtr.org/wordlist#c_2379 > http\://www.wtr.org/wordlist#c_65748 http\://www.wtr.org/wordlist#c_7612 > > Now the way i want to build the Query is:: > > rice land AND ( http\://www.wtr.org/wordlist#c_2379 OR > http\://www.wtr.org/wordlist#c_65748 OR http\:// > www.wtr.org/wordlist#c_7612 > ) > > i tried this- > > try { > if (queryString != null && fields != null) { > PerFieldAnalyzerWrapper perFieldAnalyzer = > new > PerFieldAnalyzerWrapper(analyzer); > perFieldAnalyzer.addAnalyzer("conceptURI", new > KeywordAnalyzer()); > > 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"), > queryString.length()); > > 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 > methods? > > -- > View this message in context: > http://www.nabble.com/Grouping-of-Boolean-opeartors-in-Lucene..--tp20453434p20453434.html > Sent from the Lucene - Java Users mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >