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;
float n = sim.lengthNorm(fieldName, numTokens);
float boost = info != null ? info.getBoost() : 1.0f;
n = n * boost; // see DocumentWriter.writeNorms(String segment)
byte norm = Similarity.encodeNorm(n);
norms = new byte[] {norm};