public override 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.Boost : 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; cachedFieldName = fieldName; cachedSimilarity = sim; if (DEBUG) { System.Diagnostics.Debug.WriteLine("MemoryIndexReader.norms: " + fieldName + ":" + n + ":" + norm + ":" + numTokens); } } return(norms); }
internal override void Finish() { System.Diagnostics.Debug.Assert(docIDs.Length == norms.Length); if (fieldInfo.isIndexed && !fieldInfo.omitNorms) { if (docIDs.Length <= upto) { System.Diagnostics.Debug.Assert(docIDs.Length == upto); docIDs = ArrayUtil.Grow(docIDs, 1 + upto); norms = ArrayUtil.Grow(norms, 1 + upto); } float norm = docState.similarity.ComputeNorm(fieldInfo.name, fieldState); norms[upto] = Similarity.EncodeNorm(norm); docIDs[upto] = docState.docID; upto++; } }
static NormsWriter() { defaultNorm = Similarity.EncodeNorm(1.0f); }