简体   繁体   中英

Term frequency scoring in lucene 5.3

I want to use only the term frequency to rank the results in Apache Lucene 5.3. I tried overriding the DefaultSimilarity class, but it seems it is not working in Lucene 5.3. I am using the following code:

import org.apache.lucene.search.similarities.DefaultSimilarity;

public class TfSimilarity extends DefaultSimilarity {
    public TfSimilarity(){}
    public float idf(int docFreq, int numDocs) {
      return(float)1.0;
    }
    public float coord(int overlap, int maxOverlap) {
      return 1.0f;
    }
    public float lengthNorm(String fieldName, int numTerms) {
      return (float) numTerms;
    }

}

Moreover, it seems that the program is not going inside the idf function above.

You are not overriding the method correctly. It should be:

@Override
public float idf(long docFreq, long numDocs){}

You should use the @Override annotated to make sure you've got the method definition correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM