在Solr中在查询时忽略TF/IDF [英] Ignore tf/idf at query time in Solr
问题描述
我正在尝试根据字段值来增强特定文档.总体来说还可以,但是有些文档即使提升值较小也返回较高的分数.
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?
推荐答案
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!