lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adriano Crestani <adrianocrest...@gmail.com>
Subject Re: Generating Query
Date Wed, 12 Aug 2009 09:23:44 GMT
Try this:

     BooleanQuery b1 =  new BooleanQuery();
     b1.add(new TermQuery(new Term("url", "news")),
BooleanClause.Occur.MUST);
     b1.add(new TermQuery(new Term("url", "politics")),
BooleanClause.Occur.MUST);
     b1.setBoost(1.5f);

     BooleanQuery b2 =  new BooleanQuery();
     b2.add(new TermQuery(new Term("content", "news")),
BooleanClause.Occur.MUST);
     b2.add(new TermQuery(new Term("content", "politics")),
BooleanClause.Occur.MUST);
     b2.setBoost(2f);

     BooleanQuery finalQuery =  new BooleanQuery();
     finalQuery.add(b1, BooleanClause.Occur.SHOULD);
     finalQuery.add(b2, BooleanClause.Occur.SHOULD);

     System.out.println(finalQuery.toString());

On Wed, Aug 12, 2009 at 2:09 AM, bourne71 <garylkc@live.com> wrote:

>
> Hi,
>
> I am trying to build a query that looks like the following:
> url:(+news +politics)^1.5 content:(+news +politics)^2.0
>
> But I can't seems to find any reference to it. I try hardcoding it like the
> following:
> BooleanQuery query = new BooleanQuery();
> query.add(new TermQuery(new Term(field, "+news +politics")),
> BooleanClause.Occur.SHOULD);
>
> But with this, the query doesn't seems to provide any response or effect.
> By
> right its suppose to boost the field of the page that contain both of the
> word in it.
>
> Can anyone advise me on how to create this type of query? Thanks
> --
> View this message in context:
> http://www.nabble.com/Generating-Query-tp24931880p24931880.html
> 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
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message