Solr查询时忽略tf/idf [英] Ignore tf/idf at query time in Solr

查看:30
本文介绍了Solr查询时忽略tf/idf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据字段值提升特定文档.它通常可以正常工作,但某些文档即使具有较小的 boost 值也会返回更高的分数.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆