示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
            }
            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);
            }
示例#5
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;
		}
示例#6
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;
		}
        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;
        }
 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;
 }
示例#9
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);
        }
			/* (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;
			}
			/* (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;
			}