what is the best lucene setup for ranking exact matches as the highest

≡放荡痞女 提交于 2019-12-04 06:35:10

All three matches are exact (term car being matched, not 'ca' or 'ar') :)

If there's no more content in these fields ("car parts", "car" and "car shop"), then you could use lengthNorm() or computeNorm() (depending on Lucene version), to give shorter fields more weight so that car gets higher score for being shorter. In Lucene 3.3.0, DefaultSimilarity.computeNorm() looks like this:

return state.getBoost() * ((float) (1.0 / Math.sqrt(numTerms)));

where numTerms is the total number of terms in the field. So it's surprising "car" and "car shop" documents have the same score, because for "car" the norm is 1 and for "car shop" it should be 0.7 (assuming boost of 1).

Quick hack: after getting the ScoreDoc[] from IndexSearcher.search, re-sort it with score as the first criterion and length (ascending) as the second.

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