Esempio n. 1
0
            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);
            }
            public override NumericDocValues GetNormValues(string field)
            {
                FieldInfo fieldInfo;

                if (!outerInstance.fieldInfos.TryGetValue(field, out fieldInfo) || fieldInfo.OmitsNorms())
                {
                    return(null);
                }
                NumericDocValues norms = cachedNormValues;
                Similarity       sim   = Similarity;

                if (!field.Equals(cachedFieldName) || sim != cachedSimilarity) // not cached?
                {
                    Info             info             = GetInfo(field);
                    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(field, 0, numTokens, numOverlapTokens, 0, boost);
                    long             value            = sim.ComputeNorm(invertState);
                    norms = new MemoryIndexNormDocValues(value);
                    // cache it for future reuse
                    cachedNormValues = norms;
                    cachedFieldName  = field;
                    cachedSimilarity = sim;
#if DEBUG
                    Debug.WriteLine("MemoryIndexReader.norms: " + field + ":" + value + ":" + numTokens);
#endif
                }
                return(norms);
            }
Esempio n. 3
0
 public override long ComputeNorm(FieldInvertState state)
 {
     if (state.Name.Equals(NORMS_FIELD, StringComparison.Ordinal))
     {
         return(Number.SingleToInt32Bits(state.Boost));
     }
     else
     {
         return(@in.ComputeNorm(state));
     }
 }
Esempio n. 4
0
 public override long ComputeNorm(FieldInvertState state)
 {
     if (state.Name.Equals(NORMS_FIELD))
     {
         return(Number.FloatToIntBits(state.Boost));
     }
     else
     {
         return(@in.ComputeNorm(state));
     }
 }
Esempio n. 5
0
 internal override void Finish()
 {
     if (fieldInfo.IsIndexed && !fieldInfo.OmitsNorms)
     {
         if (consumer == null)
         {
             fieldInfo.NormType = DocValuesType.NUMERIC;
             consumer           = new NumericDocValuesWriter(fieldInfo, docState.docWriter.bytesUsed, false);
         }
         consumer.AddValue(docState.docID, similarity.ComputeNorm(fieldState));
     }
 }
Esempio n. 6
0
 internal override void Finish()
 {
     if (FieldInfo.Indexed && !FieldInfo.OmitsNorms())
     {
         if (Consumer == null)
         {
             FieldInfo.NormType = FieldInfo.DocValuesType_e.NUMERIC;
             Consumer           = new NumericDocValuesWriter(FieldInfo, DocState.DocWriter.bytesUsed, false);
         }
         Consumer.AddValue(DocState.DocID, Similarity.ComputeNorm(FieldState));
     }
 }
 public static byte ComputeAndGetNorm(Similarity s, FieldInvertState state)
 {
     return((byte)s.ComputeNorm(state));
 }