/// <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
                public override Explanation Explain(int doc)
                {
                    Explanation result         = new Explanation();
                    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:");
                    return(result);
                }
示例#3
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);
                }
示例#4
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);
        }
示例#5
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);
            }
示例#6
0
        private void AddNode(TreeNode tn, Explanation e)
        {
            TreeNode node = new TreeNode(e.GetValue().ToString("G4") + "  " + e.GetDescription());

            if (null == tn)
            {
                treeExplain.Nodes.Add(node);
            }
            else
            {
                tn.Nodes.Add(node);
            }

            Explanation[] kids = e.GetDetails();
            if (kids != null && kids.Length > 0)
            {
                for (int i = 0; i < kids.Length; i++)
                {
                    AddNode(node, kids[i]);
                }
            }
        }
示例#7
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);
            }
示例#8
0
 /// <summary>
 /// Explain the custom score.
 /// Whenever overriding <see cref="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;
 }
示例#9
0
 /// <summary>
 /// Explain the custom score.
 /// Whenever overriding <see cref="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;
 }
示例#10
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);
        }
示例#11
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);
        }