コード例 #1
0
            public virtual Explanation Explain(IndexReader reader, int doc)
            {
                ConstantScorer cs     = (ConstantScorer)Scorer(reader);
                bool           exists = cs.bits.Get(doc);

                ComplexExplanation result = new ComplexExplanation();

                if (exists)
                {
                    result.SetDescription("ConstantScoreQuery(" + Enclosing_Instance.filter + "), product of:");
                    result.SetValue(queryWeight);
                    System.Boolean tempAux = true;
                    result.SetMatch(tempAux);
                    result.AddDetail(new Explanation(Enclosing_Instance.GetBoost(), "boost"));
                    result.AddDetail(new Explanation(queryNorm, "queryNorm"));
                }
                else
                {
                    result.SetDescription("ConstantScoreQuery(" + Enclosing_Instance.filter + ") doesn't match id " + doc);
                    result.SetValue(0);
                    System.Boolean tempAux2 = false;
                    result.SetMatch(tempAux2);
                }
                return(result);
            }
コード例 #2
0
            public override Explanation Explain(IndexReader reader, int doc)
            {
                ConstantScorer cs     = new ConstantScorer(enclosingInstance, similarity, reader, this);
                bool           exists = cs.docIdSetIterator.Advance(doc) == doc;

                ComplexExplanation result = new ComplexExplanation();

                if (exists)
                {
                    result.SetDescription("ConstantScoreQuery(" + Enclosing_Instance.filter + "), product of:");
                    result.SetValue(queryWeight);
                    System.Boolean tempAux = true;
                    result.SetMatch(tempAux);
                    result.AddDetail(new Explanation(Enclosing_Instance.GetBoost(), "boost"));
                    result.AddDetail(new Explanation(queryNorm, "queryNorm"));
                }
                else
                {
                    result.SetDescription("ConstantScoreQuery(" + Enclosing_Instance.filter + ") doesn't match id " + doc);
                    result.SetValue(0);
                    System.Boolean tempAux2 = false;
                    result.SetMatch(tempAux2);
                }
                return(result);
            }
コード例 #3
0
            /* Explain the score we computed for doc */
            public override Explanation Explain(IndexReader reader, int doc)
            {
                if (Enclosing_Instance.disjuncts.Count == 1)
                {
                    return(((Weight)weights[0]).Explain(reader, doc));
                }
                ComplexExplanation result = new ComplexExplanation();
                float max = 0.0f, sum = 0.0f;

                result.SetDescription(Enclosing_Instance.tieBreakerMultiplier == 0.0f?"max of:":"max plus " + Enclosing_Instance.tieBreakerMultiplier + " times others of:");
                for (System.Collections.IEnumerator iter = weights.GetEnumerator(); iter.MoveNext();)
                {
                    Explanation e = ((Weight)iter.Current).Explain(reader, doc);
                    if (e.IsMatch())
                    {
                        System.Boolean tempAux = true;
                        result.SetMatch(tempAux);
                        result.AddDetail(e);
                        sum += e.GetValue();
                        max  = System.Math.Max(max, e.GetValue());
                    }
                }
                result.SetValue(max + (sum - max) * Enclosing_Instance.tieBreakerMultiplier);
                return(result);
            }
コード例 #4
0
            /* Explain the score we computed for doc */
            public virtual Explanation Explain(IndexReader reader, int doc)
            {
                if (Enclosing_Instance.disjuncts.Count == 1)
                {
                    return(((Weight)weights[0]).Explain(reader, doc));
                }
                ComplexExplanation result = new ComplexExplanation();
                float max = 0.0f, sum = 0.0f;

                result.SetDescription(Enclosing_Instance.tieBreakerMultiplier == 0.0f ? "max of:" : "max plus " + Enclosing_Instance.tieBreakerMultiplier + " times others of:");
                for (int i = 0; i < weights.Count; i++)
                {
                    Explanation e = ((Weight)weights[i]).Explain(reader, doc);
                    if (e.IsMatch())
                    {
                        System.Boolean tempAux = true;
                        result.SetMatch(tempAux);
                        result.AddDetail(e);
                        sum += e.GetValue();
                        max  = System.Math.Max(max, e.GetValue());
                    }
                }
                result.SetValue(max + (sum - max) * Enclosing_Instance.tieBreakerMultiplier);
                return(result);
            }
コード例 #5
0
ファイル: BooleanQuery.cs プロジェクト: sainabob/teamlab.v7.5
            public override Explanation Explain(IndexReader reader, int doc)
            {
                int minShouldMatch         = Enclosing_Instance.GetMinimumNumberShouldMatch();
                ComplexExplanation sumExpl = new ComplexExplanation();

                sumExpl.SetDescription("sum of:");
                int   coord            = 0;
                int   maxCoord         = 0;
                float sum              = 0.0f;
                bool  fail             = false;
                int   shouldMatchCount = 0;

                for (System.Collections.IEnumerator wIter = weights.GetEnumerator(), cIter = Enclosing_Instance.clauses.GetEnumerator(); wIter.MoveNext();)
                {
                    cIter.MoveNext();

                    Weight        w = (Weight)wIter.Current;
                    BooleanClause c = (BooleanClause)cIter.Current;
                    if (w.Scorer(reader, true, true) == null)
                    {
                        continue;
                    }
                    Explanation e = w.Explain(reader, doc);
                    if (!c.IsProhibited())
                    {
                        maxCoord++;
                    }
                    if (e.IsMatch())
                    {
                        if (!c.IsProhibited())
                        {
                            sumExpl.AddDetail(e);
                            sum += e.GetValue();
                            coord++;
                        }
                        else
                        {
                            Explanation r = new Explanation(0.0f, "match on prohibited clause (" + c.GetQuery().ToString() + ")");
                            r.AddDetail(e);
                            sumExpl.AddDetail(r);
                            fail = true;
                        }
                        if (c.GetOccur() == Occur.SHOULD)
                        {
                            shouldMatchCount++;
                        }
                    }
                    else if (c.IsRequired())
                    {
                        Explanation r = new Explanation(0.0f, "no match on required clause (" + c.GetQuery().ToString() + ")");
                        r.AddDetail(e);
                        sumExpl.AddDetail(r);
                        fail = true;
                    }
                }
                if (fail)
                {
                    System.Boolean tempAux = false;
                    sumExpl.SetMatch(tempAux);
                    sumExpl.SetValue(0.0f);
                    sumExpl.SetDescription("Failure to meet condition(s) of required/prohibited clause(s)");
                    return(sumExpl);
                }
                else if (shouldMatchCount < minShouldMatch)
                {
                    System.Boolean tempAux2 = false;
                    sumExpl.SetMatch(tempAux2);
                    sumExpl.SetValue(0.0f);
                    sumExpl.SetDescription("Failure to match minimum number " + "of optional clauses: " + minShouldMatch);
                    return(sumExpl);
                }

                sumExpl.SetMatch(0 < coord?true:false);
                sumExpl.SetValue(sum);

                float coordFactor = similarity.Coord(coord, maxCoord);

                if (coordFactor == 1.0f)
                {
                    // coord is no-op
                    return(sumExpl);
                }
                // eliminate wrapper
                else
                {
                    ComplexExplanation result = new ComplexExplanation(sumExpl.IsMatch(), sum * coordFactor, "product of:");
                    result.AddDetail(sumExpl);
                    result.AddDetail(new Explanation(coordFactor, "coord(" + coord + "/" + maxCoord + ")"));
                    return(result);
                }
            }
コード例 #6
0
		public override Explanation Explain(IndexReader reader, int doc)
		{
			
			ComplexExplanation result = new ComplexExplanation();
			result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
			System.String field = ((SpanQuery) GetQuery()).GetField();
			
			Explanation idfExpl = new Explanation(idf, "idf(" + field + ": " + idfExp.Explain() + ")");
			
			// explain query weight
			Explanation queryExpl = new Explanation();
			queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");
			
			Explanation boostExpl = new Explanation(GetQuery().GetBoost(), "boost");
			if (GetQuery().GetBoost() != 1.0f)
				queryExpl.AddDetail(boostExpl);
			queryExpl.AddDetail(idfExpl);
			
			Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");
			queryExpl.AddDetail(queryNormExpl);
			
			queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());
			
			result.AddDetail(queryExpl);
			
			// explain field weight
			ComplexExplanation fieldExpl = new ComplexExplanation();
			fieldExpl.SetDescription("fieldWeight(" + field + ":" + query.ToString(field) + " in " + doc + "), product of:");
			
			Explanation tfExpl = Scorer(reader, true, false).Explain(doc);
			fieldExpl.AddDetail(tfExpl);
			fieldExpl.AddDetail(idfExpl);
			
			Explanation fieldNormExpl = new Explanation();
			byte[] fieldNorms = reader.Norms(field);
			float fieldNorm = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]):1.0f;
			fieldNormExpl.SetValue(fieldNorm);
			fieldNormExpl.SetDescription("fieldNorm(field=" + field + ", doc=" + doc + ")");
			fieldExpl.AddDetail(fieldNormExpl);
			
			fieldExpl.SetMatch(tfExpl.IsMatch());
			fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());
			
			result.AddDetail(fieldExpl);
			System.Boolean? tempAux = fieldExpl.GetMatch();
			result.SetMatch(tempAux);
			
			// combine them
			result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());
			
			if (queryExpl.GetValue() == 1.0f)
				return fieldExpl;
			
			return result;
		}
コード例 #7
0
ファイル: TermQuery.cs プロジェクト: ferrod20/tprilucene
            public virtual Explanation Explain(IndexReader reader, int doc)
            {
                ComplexExplanation result = new ComplexExplanation();

                result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");

                Explanation idfExpl = new Explanation(idf, "idf(docFreq=" + reader.DocFreq(Enclosing_Instance.term) + ", numDocs=" + reader.NumDocs() + ")");

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

                queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");

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

                if (Enclosing_Instance.GetBoost() != 1.0f)
                {
                    queryExpl.AddDetail(boostExpl);
                }
                queryExpl.AddDetail(idfExpl);

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

                queryExpl.AddDetail(queryNormExpl);

                queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());

                result.AddDetail(queryExpl);

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

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

                Explanation tfExpl = Scorer(reader).Explain(doc);

                fieldExpl.AddDetail(tfExpl);
                fieldExpl.AddDetail(idfExpl);

                Explanation fieldNormExpl = new Explanation();

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

                fieldNormExpl.SetValue(fieldNorm);
                fieldNormExpl.SetDescription("fieldNorm(field=" + field + ", doc=" + doc + ")");
                fieldExpl.AddDetail(fieldNormExpl);

                fieldExpl.SetMatch(tfExpl.IsMatch());
                fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

                result.AddDetail(fieldExpl);
                System.Boolean tempAux = fieldExpl.GetMatch();
                result.SetMatch(tempAux);

                // combine them
                result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());

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

                return(result);
            }
コード例 #8
0
        public virtual Explanation Explain(IndexReader reader, int doc)
        {
            ComplexExplanation result = new ComplexExplanation();
            result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
            System.String field = ((SpanQuery) GetQuery()).GetField();

            System.Text.StringBuilder docFreqs = new System.Text.StringBuilder();
            System.Collections.IEnumerator i = terms.GetEnumerator();
            while (i.MoveNext())
            {
                System.Collections.DictionaryEntry tmp = (System.Collections.DictionaryEntry) i.Current;
                Term term = (Term) tmp.Key;
                docFreqs.Append(term.Text());
                docFreqs.Append("=");
                docFreqs.Append(reader.DocFreq(term));

                if (i.MoveNext())
                {
                    docFreqs.Append(" ");
                }
            }

            Explanation idfExpl = new Explanation(idf, "idf(" + field + ": " + docFreqs + ")");

            // explain query weight
            Explanation queryExpl = new Explanation();
            queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");

            Explanation boostExpl = new Explanation(GetQuery().GetBoost(), "boost");
            if (GetQuery().GetBoost() != 1.0f)
                queryExpl.AddDetail(boostExpl);
            queryExpl.AddDetail(idfExpl);

            Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");
            queryExpl.AddDetail(queryNormExpl);

            queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());

            result.AddDetail(queryExpl);

            // explain field weight
            ComplexExplanation fieldExpl = new ComplexExplanation();
            fieldExpl.SetDescription("fieldWeight(" + field + ":" + query.ToString(field) + " in " + doc + "), product of:");

            Explanation tfExpl = Scorer(reader).Explain(doc);
            fieldExpl.AddDetail(tfExpl);
            fieldExpl.AddDetail(idfExpl);

            Explanation fieldNormExpl = new Explanation();
            byte[] fieldNorms = reader.Norms(field);
            float fieldNorm = fieldNorms != null ? Similarity.DecodeNorm(fieldNorms[doc]) : 0.0f;
            fieldNormExpl.SetValue(fieldNorm);
            fieldNormExpl.SetDescription("fieldNorm(field=" + field + ", doc=" + doc + ")");
            fieldExpl.AddDetail(fieldNormExpl);

            fieldExpl.SetMatch(tfExpl.IsMatch());
            fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

            result.AddDetail(fieldExpl);
            System.Boolean tempAux = fieldExpl.GetMatch();
            result.SetMatch(tempAux);

            // combine them
            result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());

            if (queryExpl.GetValue() == 1.0f)
                return fieldExpl;

            return result;
        }
コード例 #9
0
            public override Explanation Explain(IndexReader reader, int doc)
            {
                ComplexExplanation result = new ComplexExplanation();

                result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");

                Explanation idfExpl = new Explanation(idf, "idf(" + GetQuery() + ")");

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

                queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");

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

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

                queryExpl.AddDetail(idfExpl);

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

                queryExpl.AddDetail(queryNormExpl);

                queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());

                result.AddDetail(queryExpl);

                // explain field weight
                ComplexExplanation fieldExpl = new ComplexExplanation();

                fieldExpl.SetDescription("fieldWeight(" + GetQuery() + " in " + doc + "), product of:");

                Scorer scorer = Scorer(reader, true, false);

                if (scorer == null)
                {
                    return(new Explanation(0.0f, "no matching docs"));
                }
                Explanation tfExpl = scorer.Explain(doc);

                fieldExpl.AddDetail(tfExpl);
                fieldExpl.AddDetail(idfExpl);

                Explanation fieldNormExpl = new Explanation();

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

                fieldNormExpl.SetValue(fieldNorm);
                fieldNormExpl.SetDescription("fieldNorm(field=" + Enclosing_Instance.field + ", doc=" + doc + ")");
                fieldExpl.AddDetail(fieldNormExpl);

                fieldExpl.SetMatch(tfExpl.IsMatch());
                fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

                result.AddDetail(fieldExpl);
                System.Boolean?tempAux = fieldExpl.GetMatch();
                result.SetMatch(tempAux);

                // combine them
                result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());

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

                return(result);
            }
コード例 #10
0
			public virtual Explanation Explain(IndexReader reader, int doc)
			{
				
				ComplexExplanation result = new ComplexExplanation();
				result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
				
				Explanation idfExpl = new Explanation(idf, "idf(docFreq=" + reader.DocFreq(Enclosing_Instance.term) + ", numDocs=" + reader.NumDocs() + ")");
				
				// explain query weight
				Explanation queryExpl = new Explanation();
				queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");
				
				Explanation boostExpl = new Explanation(Enclosing_Instance.GetBoost(), "boost");
				if (Enclosing_Instance.GetBoost() != 1.0f)
					queryExpl.AddDetail(boostExpl);
				queryExpl.AddDetail(idfExpl);
				
				Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");
				queryExpl.AddDetail(queryNormExpl);
				
				queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());
				
				result.AddDetail(queryExpl);
				
				// explain field weight
				System.String field = Enclosing_Instance.term.Field();
				ComplexExplanation fieldExpl = new ComplexExplanation();
				fieldExpl.SetDescription("fieldWeight(" + Enclosing_Instance.term + " in " + doc + "), product of:");
				
				Explanation tfExpl = Scorer(reader).Explain(doc);
				fieldExpl.AddDetail(tfExpl);
				fieldExpl.AddDetail(idfExpl);
				
				Explanation fieldNormExpl = new Explanation();
				byte[] fieldNorms = reader.Norms(field);
				float fieldNorm = fieldNorms != null ? Similarity.DecodeNorm(fieldNorms[doc]) : 0.0f;
				fieldNormExpl.SetValue(fieldNorm);
				fieldNormExpl.SetDescription("fieldNorm(field=" + field + ", doc=" + doc + ")");
				fieldExpl.AddDetail(fieldNormExpl);
				
				fieldExpl.SetMatch(tfExpl.IsMatch());
				fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());
				
				result.AddDetail(fieldExpl);
				System.Boolean tempAux = fieldExpl.GetMatch();
				result.SetMatch(tempAux);
				
				// combine them
				result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());
				
				if (queryExpl.GetValue() == 1.0f)
					return fieldExpl;
				
				return result;
			}
コード例 #11
0
 /* Explain the score we computed for doc */
 public override Explanation Explain(IndexReader reader, int doc)
 {
     if (Enclosing_Instance.disjuncts.Count == 1)
         return ((Weight) weights[0]).Explain(reader, doc);
     ComplexExplanation result = new ComplexExplanation();
     float max = 0.0f, sum = 0.0f;
     result.SetDescription(Enclosing_Instance.tieBreakerMultiplier == 0.0f?"max of:":"max plus " + Enclosing_Instance.tieBreakerMultiplier + " times others of:");
     for (System.Collections.IEnumerator iter = weights.GetEnumerator(); iter.MoveNext(); )
     {
         Explanation e = ((Weight) iter.Current).Explain(reader, doc);
         if (e.IsMatch())
         {
             System.Boolean tempAux = true;
             result.SetMatch(tempAux);
             result.AddDetail(e);
             sum += e.GetValue();
             max = System.Math.Max(max, e.GetValue());
         }
     }
     result.SetValue(max + (sum - max) * Enclosing_Instance.tieBreakerMultiplier);
     return result;
 }
コード例 #12
0
			/* Explain the score we computed for doc */
			public virtual Explanation Explain(IndexReader reader, int doc)
			{
				if (Enclosing_Instance.disjuncts.Count == 1)
					return ((Weight) weights[0]).Explain(reader, doc);
				ComplexExplanation result = new ComplexExplanation();
				float max = 0.0f, sum = 0.0f;
				result.SetDescription(Enclosing_Instance.tieBreakerMultiplier == 0.0f ? "max of:" : "max plus " + Enclosing_Instance.tieBreakerMultiplier + " times others of:");
				for (int i = 0; i < weights.Count; i++)
				{
					Explanation e = ((Weight) weights[i]).Explain(reader, doc);
					if (e.IsMatch())
					{
						System.Boolean tempAux = true;
						result.SetMatch(tempAux);
						result.AddDetail(e);
						sum += e.GetValue();
						max = System.Math.Max(max, e.GetValue());
					}
				}
				result.SetValue(max + (sum - max) * Enclosing_Instance.tieBreakerMultiplier);
				return result;
			}
コード例 #13
0
                public override Explanation Explain(int doc)
                {
                    ComplexExplanation result = new ComplexExplanation();
                    Explanation nonPayloadExpl = base.Explain(doc);
                    result.AddDetail(nonPayloadExpl);
                    //QUESTION: Is there a wau to avoid this skipTo call?  We need to know whether to load the payload or not

                    Explanation payloadBoost = new Explanation();
                    result.AddDetail(payloadBoost);
                    /*
                    if (skipTo(doc) == true) {
                    processPayload();
                    }*/

                    float avgPayloadScore = (payloadsSeen > 0 ? (payloadScore / payloadsSeen) : 1);
                    payloadBoost.SetValue(avgPayloadScore);
                    //GSI: I suppose we could toString the payload, but I don't think that would be a good idea
                    payloadBoost.SetDescription("scorePayload(...)");
                    result.SetValue(nonPayloadExpl.GetValue() * avgPayloadScore);
                    result.SetDescription("btq, product of:");
                    result.SetMatch(nonPayloadExpl.GetValue() == 0 ? false : true); // LUCENE-1303
                    return result;
                }
コード例 #14
0
			public override Explanation Explain(IndexReader reader, int doc)
			{
				
				ConstantScorer cs = new ConstantScorer(enclosingInstance, similarity, reader, this);
				bool exists = cs.docIdSetIterator.Advance(doc) == doc;
				
				ComplexExplanation result = new ComplexExplanation();
				
				if (exists)
				{
					result.SetDescription("ConstantScoreQuery(" + Enclosing_Instance.filter + "), product of:");
					result.SetValue(queryWeight);
					System.Boolean tempAux = true;
					result.SetMatch(tempAux);
					result.AddDetail(new Explanation(Enclosing_Instance.GetBoost(), "boost"));
					result.AddDetail(new Explanation(queryNorm, "queryNorm"));
				}
				else
				{
					result.SetDescription("ConstantScoreQuery(" + Enclosing_Instance.filter + ") doesn't match id " + doc);
					result.SetValue(0);
					System.Boolean tempAux2 = false;
					result.SetMatch(tempAux2);
				}
				return result;
			}
コード例 #15
0
			public override Explanation Explain(IndexReader reader, int doc)
			{
				ComplexExplanation result = new ComplexExplanation();
				result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
				
				Explanation idfExpl = new Explanation(idf, "idf(" + GetQuery() + ")");
				
				// explain query weight
				Explanation queryExpl = new Explanation();
				queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");
				
				Explanation boostExpl = new Explanation(Enclosing_Instance.GetBoost(), "boost");
				if (Enclosing_Instance.GetBoost() != 1.0f)
					queryExpl.AddDetail(boostExpl);
				
				queryExpl.AddDetail(idfExpl);
				
				Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");
				queryExpl.AddDetail(queryNormExpl);
				
				queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());
				
				result.AddDetail(queryExpl);
				
				// explain field weight
				ComplexExplanation fieldExpl = new ComplexExplanation();
				fieldExpl.SetDescription("fieldWeight(" + GetQuery() + " in " + doc + "), product of:");
				
				Scorer scorer = Scorer(reader, true, false);
				if (scorer == null)
				{
					return new Explanation(0.0f, "no matching docs");
				}
				Explanation tfExpl = scorer.Explain(doc);
				fieldExpl.AddDetail(tfExpl);
				fieldExpl.AddDetail(idfExpl);
				
				Explanation fieldNormExpl = new Explanation();
				byte[] fieldNorms = reader.Norms(Enclosing_Instance.field);
				float fieldNorm = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]):1.0f;
				fieldNormExpl.SetValue(fieldNorm);
				fieldNormExpl.SetDescription("fieldNorm(field=" + Enclosing_Instance.field + ", doc=" + doc + ")");
				fieldExpl.AddDetail(fieldNormExpl);
				
				fieldExpl.SetMatch(tfExpl.IsMatch());
				fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());
				
				result.AddDetail(fieldExpl);
				System.Boolean? tempAux = fieldExpl.GetMatch();
				result.SetMatch(tempAux);
				
				// combine them
				result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());
				
				if (queryExpl.GetValue() == 1.0f)
					return fieldExpl;
				
				return result;
			}
コード例 #16
0
            public virtual Explanation Explain(IndexReader reader, int doc)
            {
                int minShouldMatch = Enclosing_Instance.GetMinimumNumberShouldMatch();
                ComplexExplanation sumExpl = new ComplexExplanation();
                sumExpl.SetDescription("sum of:");
                int coord = 0;
                int maxCoord = 0;
                float sum = 0.0f;
                bool fail = false;
                int shouldMatchCount = 0;
                for (int i = 0; i < weights.Count; i++)
                {
                    BooleanClause c = (BooleanClause) Enclosing_Instance.clauses[i];
                    Weight w = (Weight) weights[i];
                    Explanation e = w.Explain(reader, doc);
                    if (!c.IsProhibited())
                        maxCoord++;
                    if (e.IsMatch())
                    {
                        if (!c.IsProhibited())
                        {
                            sumExpl.AddDetail(e);
                            sum += e.GetValue();
                            coord++;
                        }
                        else
                        {
                            Explanation r = new Explanation(0.0f, "match on prohibited clause (" + c.GetQuery().ToString() + ")");
                            r.AddDetail(e);
                            sumExpl.AddDetail(r);
                            fail = true;
                        }
                        if (c.GetOccur().Equals(Occur.SHOULD))
                            shouldMatchCount++;
                    }
                    else if (c.IsRequired())
                    {
                        Explanation r = new Explanation(0.0f, "no match on required clause (" + c.GetQuery().ToString() + ")");
                        r.AddDetail(e);
                        sumExpl.AddDetail(r);
                        fail = true;
                    }
                }
                if (fail)
                {
                    System.Boolean tempAux = false;
                    sumExpl.SetMatch(tempAux);
                    sumExpl.SetValue(0.0f);
                    sumExpl.SetDescription("Failure to meet condition(s) of required/prohibited clause(s)");
                    return sumExpl;
                }
                else if (shouldMatchCount < minShouldMatch)
                {
                    System.Boolean tempAux2 = false;
                    sumExpl.SetMatch(tempAux2);
                    sumExpl.SetValue(0.0f);
                    sumExpl.SetDescription("Failure to match minimum number " + "of optional clauses: " + minShouldMatch);
                    return sumExpl;
                }

                sumExpl.SetMatch(0 < coord ? true : false);
                sumExpl.SetValue(sum);

                float coordFactor = similarity.Coord(coord, maxCoord);
                if (coordFactor == 1.0f)
                // coord is no-op
                    return sumExpl;
                // eliminate wrapper
                else
                {
                    ComplexExplanation result = new ComplexExplanation(sumExpl.IsMatch(), sum * coordFactor, "product of:");
                    result.AddDetail(sumExpl);
                    result.AddDetail(new Explanation(coordFactor, "coord(" + coord + "/" + maxCoord + ")"));
                    return result;
                }
            }
コード例 #17
0
			public virtual Explanation Explain(IndexReader reader, int doc)
			{
				
				ConstantScorer cs = (ConstantScorer) Scorer(reader);
				bool exists = cs.bits.Get(doc);
				
				ComplexExplanation result = new ComplexExplanation();
				
				if (exists)
				{
					result.SetDescription("ConstantScoreQuery(" + Enclosing_Instance.filter + "), product of:");
					result.SetValue(queryWeight);
					System.Boolean tempAux = true;
					result.SetMatch(tempAux);
					result.AddDetail(new Explanation(Enclosing_Instance.GetBoost(), "boost"));
					result.AddDetail(new Explanation(queryNorm, "queryNorm"));
				}
				else
				{
					result.SetDescription("ConstantScoreQuery(" + Enclosing_Instance.filter + ") doesn't match id " + doc);
					result.SetValue(0);
					System.Boolean tempAux2 = false;
					result.SetMatch(tempAux2);
				}
				return result;
			}