how do I normalise a solr/lucene score?

若如初见. 提交于 2019-11-27 07:28:53

To quote http://wiki.apache.org/lucene-java/ScoresAsPercentages:

People frequently want to compute a "Percentage" from Lucene scores to determine what is a "100% perfect" match vs a "50%" match. This is also somethings called a "normalized score"

Don't do this.

Seriously. Stop trying to think about your problem this way, it's not going to end well.

That page does give an example of how you could in theory do this, but it's very hard.

kenorb

It's called normalized score (Scores As Percentages).

You can use the following the following parameters to achieve that:

ns = {!func}product(scale(product(query({!type=edismax v=$q}),1),0,1),100)
fq = {!frange l=20}$ns

Where 20 is your 20% threshold.

See also:

Remove results below a certain score threshold in Solr/Lucene?

http://article.gmane.org/gmane.comp.jakarta.lucene.user/12076 http://article.gmane.org/gmane.comp.jakarta.lucene.user/10810

I've never had to do anything this complicated in Solr, so there may be a way to hook this in as a plugin - but you could handle it in the client when a result set is returned. If you've sorted by relevance this should be staightforward - get the relevence of the first result (max), and the last (min). Then for each result with relevance x, you can calculate

normalisedValue = (x - min) / (max - min)

which will give you a value between 0 and 1. Multiply by 5 and round to get the number of stars.

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