kee
kee

Reputation: 11619

How to assign a weight to a term query in Lucene/Solr

I am programatically constructing a BoostedQuery and I am creating two TermQuery instances which will be added to BoostedQuery instance:

Query query1 = new TermQuery(new Term("body", "new"));
Query query2 = new TermQuery(new Term("body", "york"));

But I am wondering if I could add some weight to this like I can do in qf field in Solr. Here is an example:

body:new^0.1
body:york^0.1

Any help or a pointer would be appreciated.

Upvotes: 2

Views: 6363

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

Query.setBoost

query1.setBoost(0.1);

Or in a parsed query, using StandardQueryParser, precisely as you specified in your question:

body:new^0.1

See also, Lucene scoring basics

Upvotes: 4

Related Questions