Пример #1
0
        public virtual void  TestSpanNearScorerExplain()
        {
            SpanNearQuery q = MakeQuery();
            Explanation   e = q.Weight(searcher).Explain(searcher.IndexReader, 1);

            Assert.IsTrue(0.0f < e.Value, "Scorer explanation value for doc#1 isn't positive: " + e.ToString());
        }
Пример #2
0
            private Explanation DoExplain(IndexReader reader, int doc)
            {
                Scorer[] valSrcScorers = new Scorer[valSrcWeights.Length];
                for (int i = 0; i < valSrcScorers.Length; i++)
                {
                    valSrcScorers[i] = valSrcWeights[i].Scorer(reader, true, false);
                }
                Explanation subQueryExpl = subQueryWeight.Explain(reader, doc);

                if (!subQueryExpl.IsMatch())
                {
                    return(subQueryExpl);
                }
                // match
                Explanation[] valSrcExpls = new Explanation[valSrcScorers.Length];
                for (int i = 0; i < valSrcScorers.Length; i++)
                {
                    valSrcExpls[i] = valSrcScorers[i].Explain(doc);
                }
                Explanation customExp = Enclosing_Instance.GetCustomScoreProvider(reader).CustomExplain(doc, subQueryExpl, valSrcExpls);
                float       sc        = GetValue() * customExp.GetValue();
                Explanation res       = new ComplexExplanation(true, sc, Enclosing_Instance.ToString() + ", product of:");

                res.AddDetail(customExp);
                res.AddDetail(new Explanation(GetValue(), "queryBoost"));                 // actually using the q boost as q weight (== weight value)
                return(res);
            }
Пример #3
0
        /// <summary> Explain the custom score.
        /// Whenever overriding {@link #CustomScore(int, float, float[])},
        /// this method should also be overridden to provide the correct explanation
        /// for the part of the custom scoring.
        ///
        /// </summary>
        /// <param name="doc">doc being explained.
        /// </param>
        /// <param name="subQueryExpl">explanation for the sub-query part.
        /// </param>
        /// <param name="valSrcExpls">explanation for the value source part.
        /// </param>
        /// <returns> an explanation for the custom score
        /// </returns>
        public virtual Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation[] valSrcExpls)
        {
            if (valSrcExpls.Length == 1)
            {
                return(CustomExplain(doc, subQueryExpl, valSrcExpls[0]));
            }
            if (valSrcExpls.Length == 0)
            {
                return(subQueryExpl);
            }
            float valSrcScore = 1;

            for (int i = 0; i < valSrcExpls.Length; i++)
            {
                valSrcScore *= valSrcExpls[i].GetValue();
            }
            Explanation exp = new Explanation(valSrcScore * subQueryExpl.GetValue(), "custom score: product of:");

            exp.AddDetail(subQueryExpl);
            for (int i = 0; i < valSrcExpls.Length; i++)
            {
                exp.AddDetail(valSrcExpls[i]);
            }
            return(exp);
        }
Пример #4
0
        public static Explanation ConvertLuceneExplanationToExplanation(Lucene.Net.Search.Explanation lExplanation)
        {
            if (lExplanation == null)
            {
                throw new ArgumentNullException("lExplanation");
            }

            var result = new Explanation
            {
                Description = lExplanation.Description,

                ExplanationHtml = lExplanation.ToHtml(),
                IsMatch         = lExplanation.IsMatch,
                Value           = lExplanation.Value,
            };

            var lDetails = lExplanation
                           .GetDetails();

            if (lDetails != null)
            {
                result.Details = lDetails.ToList()
                                 .Select(e => Explanation.ConvertLuceneExplanationToExplanation(e))
                                 .ToList();
            }

            return(result);
        }
Пример #5
0
        public virtual void  TestSpanNearScorerExplain()
        {
            SpanNearQuery q = MakeQuery();
            Weight        w = q.Weight(searcher);
            Scorer        s = w.Scorer(searcher.GetIndexReader(), true, false);
            Explanation   e = s.Explain(1);

            Assert.IsTrue(0.0f < e.GetValue(), "Scorer explanation value for doc#1 isn't positive: " + e.ToString());
        }
Пример #6
0
		public override Explanation Explain(int doc)
		{
			Explanation tfExplanation = new Explanation();
			
			int expDoc = Advance(doc);
			
			float phraseFreq = (expDoc == doc)?freq:0.0f;
			tfExplanation.SetValue(GetSimilarity().Tf(phraseFreq));
			tfExplanation.SetDescription("tf(phraseFreq=" + phraseFreq + ")");
			
			return tfExplanation;
		}
Пример #7
0
        public override Explanation Explain(int doc)
        {
            Explanation tfExplanation = new Explanation();

            SkipTo(doc);

            float phraseFreq = (Doc() == doc) ? freq : 0.0f;
            tfExplanation.SetValue(GetSimilarity().Tf(phraseFreq));
            tfExplanation.SetDescription("tf(phraseFreq=" + phraseFreq + ")");

            return tfExplanation;
        }
Пример #8
0
        /// <summary>
        /// This method is no longer an official member of <see cref="Scorer"/>
        /// but it is needed by SpanWeight to build an explanation.
        /// </summary>
        protected internal virtual Explanation Explain(int doc, IState state)
        {
            Explanation tfExplanation = new Explanation();

            int expDoc = Advance(doc, state);

            float phraseFreq = (expDoc == doc)?freq:0.0f;

            tfExplanation.Value       = Similarity.Tf(phraseFreq);
            tfExplanation.Description = "tf(phraseFreq=" + phraseFreq + ")";

            return(tfExplanation);
        }
Пример #9
0
        public override Explanation Explain(int doc)
        {
            Explanation tfExplanation = new Explanation();

            SkipTo(doc);

            float phraseFreq = (Doc() == doc)?freq:0.0f;

            tfExplanation.SetValue(GetSimilarity().Tf(phraseFreq));
            tfExplanation.SetDescription("tf(phraseFreq=" + phraseFreq + ")");

            return(tfExplanation);
        }
Пример #10
0
        /// <summary> Explain the custom score.
        /// Whenever overriding {@link #CustomScore(int, float, float)},
        /// this method should also be overridden to provide the correct explanation
        /// for the part of the custom scoring.
        ///
        /// </summary>
        /// <param name="doc">doc being explained.
        /// </param>
        /// <param name="subQueryExpl">explanation for the sub-query part.
        /// </param>
        /// <param name="valSrcExpl">explanation for the value source part.
        /// </param>
        /// <returns> an explanation for the custom score
        /// </returns>
        public virtual Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
        {
            float valSrcScore = 1;

            if (valSrcExpl != null)
            {
                valSrcScore *= valSrcExpl.GetValue();
            }
            Explanation exp = new Explanation(valSrcScore * subQueryExpl.GetValue(), "custom score: product of:");

            exp.AddDetail(subQueryExpl);
            exp.AddDetail(valSrcExpl);
            return(exp);
        }
Пример #11
0
            protected internal override Explanation Explain(int doc)
            {
                Explanation result         = new Explanation();
                Explanation nonPayloadExpl = base.Explain(doc);

                result.AddDetail(nonPayloadExpl);
                Explanation payloadBoost = new Explanation();

                result.AddDetail(payloadBoost);
                float avgPayloadScore = (payloadsSeen > 0?(payloadScore / payloadsSeen):1);

                payloadBoost.Value       = avgPayloadScore;
                payloadBoost.Description = "scorePayload(...)";
                result.Value             = nonPayloadExpl.Value * avgPayloadScore;
                result.Description       = "bnq, product of:";
                return(result);
            }
Пример #12
0
            public override Explanation Explain(int doc)
            {
                Explanation result         = new Explanation();
                Explanation nonPayloadExpl = base.Explain(doc);

                result.AddDetail(nonPayloadExpl);
                Explanation payloadBoost = new Explanation();

                result.AddDetail(payloadBoost);
                float avgPayloadScore = (payloadsSeen > 0?(payloadScore / payloadsSeen):1);

                payloadBoost.SetValue(avgPayloadScore);
                payloadBoost.SetDescription("scorePayload(...)");
                result.SetValue(nonPayloadExpl.GetValue() * avgPayloadScore);
                result.SetDescription("bnq, product of:");
                return(result);
            }
Пример #13
0
            /*(non-Javadoc) @see Lucene.Net.Search.Scorer#explain(int) */
            public override Explanation Explain(int doc)
            {
                Explanation subQueryExpl = weight.subQueryWeight.Explain(reader, doc);

                if (!subQueryExpl.IsMatch())
                {
                    return(subQueryExpl);
                }
                // match
                Explanation[] valSrcExpls = new Explanation[valSrcScorers.Length];
                for (int i = 0; i < valSrcScorers.Length; i++)
                {
                    valSrcExpls[i] = valSrcScorers[i].Explain(doc);
                }
                Explanation customExp = Enclosing_Instance.CustomExplain(doc, subQueryExpl, valSrcExpls);
                float       sc        = qWeight * customExp.GetValue();
                Explanation res       = new ComplexExplanation(true, sc, Enclosing_Instance.ToString() + ", product of:");

                res.AddDetail(customExp);
                res.AddDetail(new Explanation(qWeight, "queryBoost"));                 // actually using the q boost as q weight (== weight value)
                return(res);
            }
Пример #14
0
                protected internal override Explanation Explain(int doc)
                {
                    ComplexExplanation result         = new ComplexExplanation();
                    Explanation        nonPayloadExpl = base.Explain(doc);

                    result.AddDetail(nonPayloadExpl);
                    // QUESTION: Is there a way to avoid this skipTo call? We need to know
                    // whether to load the payload or not
                    Explanation payloadBoost = new Explanation();

                    result.AddDetail(payloadBoost);

                    float payloadScore = GetPayloadScore();

                    payloadBoost.Value = payloadScore;
                    // GSI: I suppose we could toString the payload, but I don't think that
                    // would be a good idea
                    payloadBoost.Description = "scorePayload(...)";
                    result.Value             = nonPayloadExpl.Value * payloadScore;
                    result.Description       = "btq, product of:";
                    result.Match             = nonPayloadExpl.Value == 0?false:true;         // LUCENE-1303
                    return(result);
                }
Пример #15
0
			private Explanation DoExplain(IndexReader reader, int doc)
			{
				Scorer[] valSrcScorers = new Scorer[valSrcWeights.Length];
				for (int i = 0; i < valSrcScorers.Length; i++)
				{
					valSrcScorers[i] = valSrcWeights[i].Scorer(reader, true, false);
				}
				Explanation subQueryExpl = subQueryWeight.Explain(reader, doc);
				if (!subQueryExpl.IsMatch())
				{
					return subQueryExpl;
				}
				// match
				Explanation[] valSrcExpls = new Explanation[valSrcScorers.Length];
				for (int i = 0; i < valSrcScorers.Length; i++)
				{
					valSrcExpls[i] = valSrcScorers[i].Explain(doc);
				}
                Explanation customExp = Enclosing_Instance.GetCustomScoreProvider(reader).CustomExplain(doc, subQueryExpl, valSrcExpls);
				float sc = GetValue() * customExp.GetValue();
				Explanation res = new ComplexExplanation(true, sc, Enclosing_Instance.ToString() + ", product of:");
				res.AddDetail(customExp);
				res.AddDetail(new Explanation(GetValue(), "queryBoost")); // actually using the q boost as q weight (== weight value)
				return res;
			}
Пример #16
0
		public virtual Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
		{
			float valSrcScore = 1;
			if (valSrcExpl != null)
			{
				valSrcScore *= valSrcExpl.GetValue();
			}
			Explanation exp = new Explanation(valSrcScore * subQueryExpl.GetValue(), "custom score: product of:");
			exp.AddDetail(subQueryExpl);
			exp.AddDetail(valSrcExpl);
			return exp;
		}
Пример #17
0
		public virtual Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation[] valSrcExpls)
		{
			if (valSrcExpls.Length == 1)
			{
				return CustomExplain(doc, subQueryExpl, valSrcExpls[0]);
			}
			if (valSrcExpls.Length == 0)
			{
				return subQueryExpl;
			}
			float valSrcScore = 1;
			for (int i = 0; i < valSrcExpls.Length; i++)
			{
				valSrcScore *= valSrcExpls[i].GetValue();
			}
			Explanation exp = new Explanation(valSrcScore * subQueryExpl.GetValue(), "custom score: product of:");
			exp.AddDetail(subQueryExpl);
			for (int i = 0; i < valSrcExpls.Length; i++)
			{
				exp.AddDetail(valSrcExpls[i]);
			}
			return exp;
		}
Пример #18
0
 public override Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
 {
     return parent.CustomExplain(doc, subQueryExpl, valSrcExpl);
 }
Пример #19
0
                public override Explanation Explain(int doc)
                {
                    ComplexExplanation result = new ComplexExplanation();
                    Explanation nonPayloadExpl = base.Explain(doc);
                    result.AddDetail(nonPayloadExpl);
                    // QUESTION: Is there a way to avoid this skipTo call? We need to know
                    // whether to load the payload or not
                    Explanation payloadBoost = new Explanation();
                    result.AddDetail(payloadBoost);

                    float payloadScore = GetPayloadScore();
                    payloadBoost.SetValue(payloadScore);
                    // 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() * payloadScore);
                    result.SetDescription("btq, product of:");
                    result.SetMatch(nonPayloadExpl.GetValue() == 0?false:true); // LUCENE-1303
                    return result;
                }
Пример #20
0
 public override Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
 {
     return(parent.CustomExplain(doc, subQueryExpl, valSrcExpl));
 }
Пример #21
0
            public override Explanation Explain(IndexReader reader, int doc)
            {
                Explanation explain = DoExplain(reader, doc);

                return(explain == null?new Explanation(0.0f, "no matching docs"):explain);
            }
Пример #22
0
 private static string CreateExplanation(Lucene.Net.Search.Explanation explanation)
 {
     return(explanation.ToString());
 }
        public virtual Explanation Explain(IndexReader reader, int doc)
        {
            Explanation result = new Explanation();
            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
            Explanation fieldExpl = new Explanation();
            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.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

            result.AddDetail(fieldExpl);

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

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

            return result;
        }
			/* (non-Javadoc)@see Lucene.Net.Search.Function.CustomScoreQuery#customExplain(int, Lucene.Net.Search.Explanation, Lucene.Net.Search.Explanation)*/
			public override Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation[] valSrcExpls)
			{
				if (valSrcExpls.Length == 0)
				{
					return subQueryExpl;
				}
				Explanation exp = new Explanation(valSrcExpls[0].GetValue() + subQueryExpl.GetValue(), "sum of:");
				exp.AddDetail(subQueryExpl);
				exp.AddDetail(valSrcExpls[0]);
				if (valSrcExpls.Length == 1)
				{
					exp.SetDescription("CustomMulAdd, sum of:");
					return exp;
				}
				Explanation exp2 = new Explanation(valSrcExpls[1].GetValue() * exp.GetValue(), "custom score: product of:");
				exp2.AddDetail(valSrcExpls[1]);
				exp2.AddDetail(exp);
				return exp2;
			}
Пример #25
0
        /// <summary>
        /// This method is no longer an official member of <see cref="Scorer"/>
        /// but it is needed by SpanWeight to build an explanation.
        /// </summary>
		protected internal virtual Explanation Explain(int doc)
		{
			Explanation tfExplanation = new Explanation();
			
			int expDoc = Advance(doc);
			
			float phraseFreq = (expDoc == doc)?freq:0.0f;
			tfExplanation.Value = Similarity.Tf(phraseFreq);
			tfExplanation.Description = "tf(phraseFreq=" + phraseFreq + ")";
			
			return tfExplanation;
		}
Пример #26
0
 public override Explanation Explain(int doc)
 {
     Explanation result = new Explanation();
     Explanation nonPayloadExpl = base.Explain(doc);
     result.AddDetail(nonPayloadExpl);
     Explanation payloadBoost = new Explanation();
     result.AddDetail(payloadBoost);
     float avgPayloadScore = (payloadsSeen > 0?(payloadScore / payloadsSeen):1);
     payloadBoost.SetValue(avgPayloadScore);
     payloadBoost.SetDescription("scorePayload(...)");
     result.SetValue(nonPayloadExpl.GetValue() * avgPayloadScore);
     result.SetDescription("bnq, product of:");
     return result;
 }
Пример #27
0
			// TODO: remove in 3.0
			/*(non-Javadoc) @see Lucene.Net.Search.Scorer#explain(int) */
			public override Explanation Explain(int doc)
			{
				Explanation subQueryExpl = weight.subQueryWeight.Explain(reader, doc);
				if (!subQueryExpl.IsMatch())
				{
					return subQueryExpl;
				}
				// match
				Explanation[] valSrcExpls = new Explanation[valSrcScorers.Length];
				for (int i = 0; i < valSrcScorers.Length; i++)
				{
					valSrcExpls[i] = valSrcScorers[i].Explain(doc);
				}
				Explanation customExp = Enclosing_Instance.CustomExplain(doc, subQueryExpl, valSrcExpls);
				float sc = qWeight * customExp.GetValue();
				Explanation res = new ComplexExplanation(true, sc, Enclosing_Instance.ToString() + ", product of:");
				res.AddDetail(customExp);
				res.AddDetail(new Explanation(qWeight, "queryBoost")); // actually using the q boost as q weight (== weight value)
				return res;
			}
			/* (non-Javadoc)@see Lucene.Net.Search.Function.CustomScoreQuery#customExplain(int, Lucene.Net.Search.Explanation, Lucene.Net.Search.Explanation)*/
			public override Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
			{
				float valSrcScore = valSrcExpl == null?0:valSrcExpl.GetValue();
				Explanation exp = new Explanation(valSrcScore + subQueryExpl.GetValue(), "custom score: sum of:");
				exp.AddDetail(subQueryExpl);
				if (valSrcExpl != null)
				{
					exp.AddDetail(valSrcExpl);
				}
				return exp;
			}
			protected internal override Explanation Explain(int doc)
			{
				Explanation result = new Explanation();
				Explanation nonPayloadExpl = base.Explain(doc);
				result.AddDetail(nonPayloadExpl);
				Explanation payloadBoost = new Explanation();
				result.AddDetail(payloadBoost);
				float avgPayloadScore = (payloadsSeen > 0?(payloadScore / payloadsSeen):1);
				payloadBoost.Value = avgPayloadScore;
				payloadBoost.Description = "scorePayload(...)";
				result.Value = nonPayloadExpl.Value * avgPayloadScore;
				result.Description = "bnq, product of:";
				return result;
			}
Пример #30
0
        public virtual Explanation Explain(IndexReader reader, int doc)
        {
            Explanation result = new Explanation();

            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())
            {
                Term term = (Term)i.Current;
                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
            Explanation fieldExpl = new Explanation();

            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.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

            result.AddDetail(fieldExpl);

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

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

            return(result);
        }