You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Frank Schima <fj...@foraker.com> on 2007/06/12 20:45:07 UTC
Search with AND by default
I'm searching my index and if a user types multiple words (e.g. "two words")
in the search field, I want both of the search terms to appear in the
resulting hits, but it appears to be doing an OR by default. How can I get
an AND by default instead?
Here's how i create my Search:
QueryParser qp = new MultiFieldQueryParser( new String[] {"content",
"content_title"}, new StandardAnalyzer() );
Query query = qp.parse(strTerms);
Thanks!
Frank
--
View this message in context: http://www.nabble.com/Search-with-AND-by-default-tf3909294.html#a11084504
Sent from the Lucene - Java Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Search with AND by default
Posted by Frank Schima <fj...@foraker.com>.
Erick Erickson wrote:
>
> QueryParser.setDefaultOperator(QueryParser.Operator.AND).
>
That works. Thanks!
--
View this message in context: http://www.nabble.com/Search-with-AND-by-default-tf3909294.html#a11086380
Sent from the Lucene - Java Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Search with AND by default
Posted by Erick Erickson <er...@gmail.com>.
QueryParser.setDefaultOperator(QueryParser.Operator.AND).
Erick
On 6/12/07, Frank Schima <fj...@foraker.com> wrote:
>
>
> I'm searching my index and if a user types multiple words (e.g. "two
> words")
> in the search field, I want both of the search terms to appear in the
> resulting hits, but it appears to be doing an OR by default. How can I get
> an AND by default instead?
>
> Here's how i create my Search:
>
> QueryParser qp = new MultiFieldQueryParser( new String[] {"content",
> "content_title"}, new StandardAnalyzer() );
> Query query = qp.parse(strTerms);
>
>
> Thanks!
> Frank
>
>
> --
> View this message in context:
> http://www.nabble.com/Search-with-AND-by-default-tf3909294.html#a11084504
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>