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

2019-05-22 14:09发布

问题:

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.

回答1:

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



标签: solr lucene