Lucene Query Boosting

狂风中的少年 提交于 2020-04-16 01:55:21

问题


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


回答1:


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.




回答2:


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 .....



来源:https://stackoverflow.com/questions/6549080/lucene-query-boosting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!