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 sp...@gmx.eu on 2008/01/24 19:18:00 UTC
Creating search query
Hi,
I have an index with some fields which are indexed and un_tokenized
(keywords) and one field which is indexed and tokenized (content).
Now I want to create a Query-Object:
TermQuery k1 = new TermQuery(new Term("foo", "some foo"));
TermQuery k2 = new TermQuery(new Term("bar", "some bar"));
QueryParser p = new QueryParser("content", new
SomeAnalyzer());//same analyzer is used for indexing
Query c =p.parse("text we are looking for");
BooleanQuery q = new BooleanQuery();
q.add(k1, Occur.MUST);
q.add(k2, Occur.MUST);
q.add(c, Occur.MUST);
Is this the best way?
Thank you
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
RE: Creating search query
Posted by sp...@gmx.eu.
Yes, sorry, that's the case.
Thank you!
> -----Original Message-----
> From: Erick Erickson [mailto:erickerickson@gmail.com]
> Sent: Donnerstag, 24. Januar 2008 19:49
> To: java-user@lucene.apache.org
> Subject: Re: Creating search query
>
> That should work fine, assuming that foo and bar are the untokenized
> fields and content is the tokenized content.
>
> Erick
>
> On Jan 24, 2008 1:18 PM, <sp...@gmx.eu> wrote:
>
> > Hi,
> >
> > I have an index with some fields which are indexed and un_tokenized
> > (keywords) and one field which is indexed and tokenized (content).
> >
> > Now I want to create a Query-Object:
> >
> > TermQuery k1 = new TermQuery(new Term("foo", "some foo"));
> > TermQuery k2 = new TermQuery(new Term("bar", "some bar"));
> > QueryParser p = new QueryParser("content", new
> > SomeAnalyzer());//same analyzer is used for indexing
> > Query c =p.parse("text we are looking for");
> >
> > BooleanQuery q = new BooleanQuery();
> > q.add(k1, Occur.MUST);
> > q.add(k2, Occur.MUST);
> > q.add(c, Occur.MUST);
> >
> > Is this the best way?
> >
> > Thank you
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Creating search query
Posted by Erick Erickson <er...@gmail.com>.
That should work fine, assuming that foo and bar are the untokenized
fields and content is the tokenized content.
Erick
On Jan 24, 2008 1:18 PM, <sp...@gmx.eu> wrote:
> Hi,
>
> I have an index with some fields which are indexed and un_tokenized
> (keywords) and one field which is indexed and tokenized (content).
>
> Now I want to create a Query-Object:
>
> TermQuery k1 = new TermQuery(new Term("foo", "some foo"));
> TermQuery k2 = new TermQuery(new Term("bar", "some bar"));
> QueryParser p = new QueryParser("content", new
> SomeAnalyzer());//same analyzer is used for indexing
> Query c =p.parse("text we are looking for");
>
> BooleanQuery q = new BooleanQuery();
> q.add(k1, Occur.MUST);
> q.add(k2, Occur.MUST);
> q.add(c, Occur.MUST);
>
> Is this the best way?
>
> Thank you
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>