private String cachedFieldName;
private Similarity cachedSimilarity;
public byte[] norms(String fieldName) {
byte[] norms = cachedNorms;
Similarity sim = getSimilarity();
if (fieldName != cachedFieldName || sim != cachedSimilarity) { // not cached?
Info info = getInfo(fieldName);
int numTokens = info != null ? info.numTokens : 0;
int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
float boost = info != null ? info.getBoost() : 1.0f;
FieldInvertState invertState = new FieldInvertState(0, numTokens, numOverlapTokens, 0, boost);
float n = sim.computeNorm(fieldName, invertState);
byte norm = Similarity.encodeNorm(n);
norms = new byte[] {norm};
// cache it for future reuse
cachedNorms = norms;