You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by Anton Potehin <an...@orbita1.ru> on 2005/11/07 14:27:25 UTC

How create Query

I have two fields in the index called "first" and "second". Is it
possible to make search using following condition: the "first" field
must have "car" and the "second" field must have "java" or "sun"? If it
is possible, please tell me how?

 


Re: How create Query

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On 7 Nov 2005, at 08:27, Anton Potehin wrote:
> I have two fields in the index called "first" and "second". Is it
> possible to make search using following condition: the "first" field
> must have "car" and the "second" field must have "java" or "sun"?  
> If it
> is possible, please tell me how?

Using QueryParser, this expression would give you the query you desire:

     first:car AND second:(java OR sun)

Using the API, you can construct this query using BooleanQuery with  
two required clauses, the first clause being a TermQuery for car on  
the "first" field, and the second clause being a nested BooleanQuery  
with two optional TermQuery's for java and sun on the "second" field.

     Erik



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