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:
You should use the
@Override
annotated to make sure you've got the method definition correctly.