コード例 #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);
            }
コード例 #2
0
            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);
            }
コード例 #3
0
ファイル: SorterTestBase.cs プロジェクト: zhuthree/lucenenet
 public override long ComputeNorm(FieldInvertState state)
 {
     if (state.Name.Equals(NORMS_FIELD, StringComparison.Ordinal))
     {
         return(Number.SingleToInt32Bits(state.Boost));
     }
     else
     {
         return(@in.ComputeNorm(state));
     }
 }
コード例 #4
0
 public override long ComputeNorm(FieldInvertState state)
 {
     if (state.Name.Equals(NORMS_FIELD))
     {
         return(Number.FloatToIntBits(state.Boost));
     }
     else
     {
         return(@in.ComputeNorm(state));
     }
 }
コード例 #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));
     }
 }
コード例 #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));
     }
 }
コード例 #7
0
 public static byte ComputeAndGetNorm(Similarity s, FieldInvertState state)
 {
     return((byte)s.ComputeNorm(state));
 }