Ignore tf/idf at query time in Solr

后端 未结 1 504
刺人心
刺人心 2020-12-10 19:44

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 v

相关标签:
1条回答
  • 2020-12-10 20:16

    You'll want to create a custom Similarity which overrides the tf and idf methods, and use it in place of the DefaultSimilarity.

    Something like:

    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;
        }
    }
    

    The set it to use that similarity in your schema.xml:

    <similarity class="myorg.mypackage.CustomSimilarity"/>
    
    0 讨论(0)
提交回复
热议问题