Hi,
I tried implementing my own Similarity and setting it in
IndexWriter.setSimilarity(new CosSimilarity()).
But, there's something weird, it doesn't seem to call the methods in my
Similarity. For example, when I set the idf to return 0.0f the
Similarity still gives me a score > 0.0f.
How do I correctly set the Similarity? I'm quite new to this, some links
to implementing Similarity will also be useful.
Thanks.
--
Eugene
Here's the code for my CosSimilarity:
import org.apache.lucene.search.Similarity;
public class CosSimilarity extends Similarity
{
public float lengthNorm(String fieldName, int numTerms) {
return 1.0f;
}
public float queryNorm(float sumOfSquaredWeights) {
return (float)(1.0 / Math.sqrt(sumOfSquaredWeights));
}
public float tf(float freq) {
return (float)(1 + Math.log(1 + freq));
}
public float sloppyFreq(int distance) {
return 1.0f / (distance + 1);
}
public float idf(int docFreq, int numDocs) {
float f = (float)(Math.log((double)numDocs/(double)(docFreq+1) + 1.0));
System.out.println("CosSimilarity.idf>" + f);
return 0.0f;
}
public float coord(int overlap, int maxOverlap) {
return overlap / (float)maxOverlap;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]