Esempio n. 1
0
		/// <summary>Skips to the first match beyond the current whose document number is
		/// greater than or equal to a given target. 
		/// <br>The implementation uses {@link TermDocs#SkipTo(int)}.
		/// </summary>
		/// <param name="target">The target document number.
		/// </param>
		/// <returns> true iff there is such a match.
		/// </returns>
		public override bool SkipTo(int target)
		{
			// first scan in cache
			for (pointer++; pointer < pointerMax; pointer++)
			{
				if (docs[pointer] >= target)
				{
					doc = docs[pointer];
					return true;
				}
			}
			
			// not found in cache, seek underlying stream
			bool result = termDocs.SkipTo(target);
			if (result)
			{
				pointerMax = 1;
				pointer = 0;
				docs[pointer] = doc = termDocs.Doc();
				freqs[pointer] = termDocs.Freq();
			}
			else
			{
				doc = System.Int32.MaxValue;
			}
			return result;
		}
Esempio n. 2
0
        /// <summary> Advances to the first match beyond the current whose document number is
        /// greater than or equal to a given target. <br/>
        /// The implementation uses {@link TermDocs#SkipTo(int)}.
        ///
        /// </summary>
        /// <param name="target">The target document number.
        /// </param>
        /// <returns> the matching document or -1 if none exist.
        /// </returns>
        public override int Advance(int target)
        {
            // first scan in cache
            for (pointer++; pointer < pointerMax; pointer++)
            {
                if (docs[pointer] >= target)
                {
                    return(doc = docs[pointer]);
                }
            }

            // not found in cache, seek underlying stream
            bool result = termDocs.SkipTo(target);

            if (result)
            {
                pointerMax     = 1;
                pointer        = 0;
                docs[pointer]  = doc = termDocs.Doc();
                freqs[pointer] = termDocs.Freq();
            }
            else
            {
                doc = NO_MORE_DOCS;
            }
            return(doc);
        }
Esempio n. 3
0
 public override int Advance(int target)
 {
     if (!termDocs.SkipTo(target))
     {
         return(doc = NO_MORE_DOCS);
     }
     while (!Enclosing_Instance.MatchDoc(doc = termDocs.Doc))
     {
         if (!termDocs.Next())
         {
             return(doc = NO_MORE_DOCS);
         }
     }
     return(doc);
 }
Esempio n. 4
0
 public override int Advance(int target)
 {
     return(doc = termDocs.SkipTo(target)?termDocs.Doc():NO_MORE_DOCS);
 }
Esempio n. 5
0
            public override Explanation Explain(IndexReader reader, int doc)
            {
                ComplexExplanation result = new ComplexExplanation();

                result.Description = "weight(" + Query + " in " + doc + "), product of:";

                Explanation expl = new Explanation(idf, idfExp.Explain());

                // explain query weight
                Explanation queryExpl = new Explanation();

                queryExpl.Description = "queryWeight(" + Query + "), product of:";

                Explanation boostExpl = new Explanation(Enclosing_Instance.Boost, "boost");

                if (Enclosing_Instance.Boost != 1.0f)
                {
                    queryExpl.AddDetail(boostExpl);
                }
                queryExpl.AddDetail(expl);

                Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");

                queryExpl.AddDetail(queryNormExpl);

                queryExpl.Value = boostExpl.Value * expl.Value * queryNormExpl.Value;

                result.AddDetail(queryExpl);

                // explain field weight
                string             field     = Enclosing_Instance.term.Field;
                ComplexExplanation fieldExpl = new ComplexExplanation();

                fieldExpl.Description = "fieldWeight(" + Enclosing_Instance.term + " in " + doc + "), product of:";

                Explanation tfExplanation = new Explanation();
                int         tf            = 0;
                TermDocs    termDocs      = reader.TermDocs(enclosingInstance.term);

                if (termDocs != null)
                {
                    try
                    {
                        if (termDocs.SkipTo(doc) && termDocs.Doc == doc)
                        {
                            tf = termDocs.Freq;
                        }
                    }
                    finally
                    {
                        termDocs.Close();
                    }
                    tfExplanation.Value       = similarity.Tf(tf);
                    tfExplanation.Description = "tf(termFreq(" + enclosingInstance.term + ")=" + tf + ")";
                }
                else
                {
                    tfExplanation.Value       = 0.0f;
                    tfExplanation.Description = "no matching term";
                }
                fieldExpl.AddDetail(tfExplanation);
                fieldExpl.AddDetail(expl);

                Explanation fieldNormExpl = new Explanation();

                byte[] fieldNorms = reader.Norms(field);
                float  fieldNorm  = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]) : 1.0f;

                fieldNormExpl.Value       = fieldNorm;
                fieldNormExpl.Description = "fieldNorm(field=" + field + ", doc=" + doc + ")";
                fieldExpl.AddDetail(fieldNormExpl);

                fieldExpl.Match = tfExplanation.IsMatch;
                fieldExpl.Value = tfExplanation.Value * expl.Value * fieldNormExpl.Value;

                result.AddDetail(fieldExpl);
                bool?tempAux = fieldExpl.Match;

                result.Match = tempAux;

                // combine them
                result.Value = queryExpl.Value * fieldExpl.Value;

                if (queryExpl.Value == 1.0f)
                {
                    return(fieldExpl);
                }

                return(result);
            }
Esempio n. 6
0
 public override bool SkipTo(int target)
 {
     return(termDocs.SkipTo(target));
 }