Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

lucene - 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.

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.

Is there a way to ignore tf/idf scoring at query time?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...