Lucene Query Boosting

2019-07-24 04:16发布

I am reading 2 query from file like,

Query q1 = new QueryParser(Version.LUCENE_CURRENT, "id", analyzer).parse(dis.readLine());
Query q2 = new QueryParser(Version.LUCENE_CURRENT, "id", analyzer).parse(dis.readLine());

I want these query to be combined as one query and give some boost (say by 5) to query 2 i.e q2.

Thanks,
Ravi

标签: java lucene
2条回答
走好不送
2楼-- · 2019-07-24 04:47

I believe this should work:

q2.setBoost(5);

BooleanQuery q3 = new BooleanQuery();
q3.add(q1, BooleanClause.Occur.SHOULD);
q3.add(q2, BooleanClause.Occur.SHOULD);

You searching using the BooleanQuery q3.

查看更多
聊天终结者
3楼-- · 2019-07-24 04:48

I'm not sure if you can boost a query or not. I know you can boost a field when you create the index e.g.

Field field = new Field("id", id, ......);
field.setBoost(0.5);

As far as combining those 2 queries:

String term = dis.readLine() + " AND " + dis.readLine();

Or something to that effect .....

查看更多
登录 后发表回答