问题描述
我正在尝试根据字段值提升特定文档.它通常工作正常,但一些文档返回更高的分数,即使它们具有较小的提升值.
I am trying to boost particular documents based on a field value. It is generally working ok but some documents return a higher score even though they have a smaller boost value.
在使用 debugQuery=on
请求参数调试查询后,我注意到 idf
函数为特定文档返回了更高的分数,这影响了整体得分.
After debugging the query with the debugQuery=on
request parameter I have noticed that the idf
function is returning a higher score for a particular document, which is affecting the overall score.
有没有办法在查询时忽略 tf/idf 评分?
Is there a way to ignore tf/idf scoring at query time?
推荐答案
您需要创建一个自定义 Similarity 覆盖 tf 和 idf 方法,并使用它代替 DefaultSimilarity.
You'll want to create a custom Similarity which overrides the tf and idf methods, and use it in place of the DefaultSimilarity.
类似:
class CustomSimilarity extends DefaultSimilarity {
@Override
public float tf(float freq) {
return 1.0;
}
@Override
public float tf(int freq) {
return 1.0;
}
@Override
// Note the signature of this method may now take longs:
// public float idf(long docFreq, long numDocs)
public float idf(int docFreq, int numDocs) {
return 1.0;
}
}
将其设置为在您的 schema.xml 中使用该相似性:
The set it to use that similarity in your schema.xml:
<similarity class="myorg.mypackage.CustomSimilarity"/>
这篇关于在 Solr 中的查询时忽略 tf/idf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!