Reputation: 661
I would like to disable lengthNorm in Solr. Some people suggest using omitNorms=true. but I can't use it because I also want to do index time boost. "omitNorms=true" seems to disable index time boost. another approach I found online is to override lengthNorm method in DefaultSimilarty. but looks like this method is no longer used in Solr 4.0. Is there another other way to do so?
public float lengthNorm(String fieldName, int numTerms) {
return numTerms > 0 ? 1.0f : 0.0f;
}
Upvotes: 0
Views: 749
Reputation: 52799
You can check the source of DefaultSimilarity for 4.0
@Override
public void computeNorm(FieldInvertState state, Norm norm) {
final int numTerms;
if (discountOverlaps)
numTerms = state.getLength() - state.getNumOverlap();
else
numTerms = state.getLength();
norm.setByte(encodeNormValue(state.getBoost() * ((float) (1.0 / Math.sqrt(numTerms)))));
}
You can create a Custom class with numTerms equal to 1 or remove the calculation ((float) (1.0 / Math.sqrt(numTerms)))
to eliminate lengthNorm effect.
Upvotes: 1