Explain() public abstract method

An explanation of the score computation for the named document.
public abstract Explain ( Lucene.Net.Index.IndexReader reader, int doc ) : Explanation
reader Lucene.Net.Index.IndexReader sub-reader containing the give doc ///
doc int ///
return Explanation
Example #1
0
        public override Explanation Explain(Weight weight, int doc, IState state)
        {
            int n          = ReaderUtil.SubIndex(doc, docStarts);
            int deBasedDoc = doc - docStarts[n];

            return(weight.Explain(subReaders[n], deBasedDoc, state));
        }
Example #2
0
        /// <summary>
        /// Expert: low-level implementation method
        /// Returns an Explanation that describes how <code>doc</code> scored against
        /// <code>weight</code>.
        ///
        /// <p>this is intended to be used in developing Similarity implementations,
        /// and, for good performance, should not be displayed with every hit.
        /// Computing an explanation is as expensive as executing the query over the
        /// entire index.
        /// <p>Applications should call <seealso cref="IndexSearcher#explain(Query, int)"/>. </summary>
        /// <exception cref="BooleanQuery.TooManyClauses"> If a query would exceed
        ///         <seealso cref="BooleanQuery#getMaxClauseCount()"/> clauses. </exception>
        protected internal virtual Explanation Explain(Weight weight, int doc)
        {
            int n = ReaderUtil.SubIndex(doc, LeafContexts);
            AtomicReaderContext ctx = LeafContexts[n];
            int deBasedDoc          = doc - ctx.DocBase;

            return(weight.Explain(ctx, deBasedDoc));
        }
Example #3
0
            public override Explanation Explain(AtomicReaderContext ir, int i)
            {
                Explanation      inner            = weight.Explain(ir, i);
                Filter           f                = outerInstance.filter;
                DocIdSet         docIdSet         = f.GetDocIdSet(ir, ir.AtomicReader.LiveDocs);
                DocIdSetIterator docIdSetIterator = docIdSet == null?DocIdSetIterator.GetEmpty() : docIdSet.GetIterator();

                if (docIdSetIterator == null)
                {
                    docIdSetIterator = DocIdSetIterator.GetEmpty();
                }
                if (docIdSetIterator.Advance(i) == i)
                {
                    return(inner);
                }
                else
                {
                    Explanation result = new Explanation(0.0f, "failure to match filter: " + f.ToString());
                    result.AddDetail(inner);
                    return(result);
                }
            }
Example #4
0
        public override Explanation Explain(Weight weight, int doc)
        {
            int n = ReaderUtil.SubIndex(doc, docStarts);
            int deBasedDoc = doc - docStarts[n];

            return weight.Explain(subReaders[n], deBasedDoc);
        }
Example #5
0
            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);
                }
            }
Example #6
0
            public override Explanation Explain(AtomicReaderContext context, int doc)
            {
                int minShouldMatch         = OuterInstance.MinimumNumberShouldMatch;
                ComplexExplanation sumExpl = new ComplexExplanation();

                sumExpl.Description = "sum of:";
                int   coord                       = 0;
                float sum                         = 0.0f;
                bool  fail                        = false;
                int   shouldMatchCount            = 0;
                IEnumerator <BooleanClause> cIter = OuterInstance.clauses.GetEnumerator();

                for (IEnumerator <Weight> wIter = Weights.GetEnumerator(); wIter.MoveNext();)
                {
                    Weight w = wIter.Current;
                    cIter.MoveNext();
                    BooleanClause c = cIter.Current;
                    if (w.Scorer(context, context.AtomicReader.LiveDocs) == null)
                    {
                        if (c.Required)
                        {
                            fail = true;
                            Explanation r = new Explanation(0.0f, "no match on required clause (" + c.Query.ToString() + ")");
                            sumExpl.AddDetail(r);
                        }
                        continue;
                    }
                    Explanation e = w.Explain(context, doc);
                    if (e.IsMatch)
                    {
                        if (!c.Prohibited)
                        {
                            sumExpl.AddDetail(e);
                            sum += e.Value;
                            coord++;
                        }
                        else
                        {
                            Explanation r = new Explanation(0.0f, "match on prohibited clause (" + c.Query.ToString() + ")");
                            r.AddDetail(e);
                            sumExpl.AddDetail(r);
                            fail = true;
                        }
                        if (c.Occur_ == Occur_e.SHOULD)
                        {
                            shouldMatchCount++;
                        }
                    }
                    else if (c.Required)
                    {
                        Explanation r = new Explanation(0.0f, "no match on required clause (" + c.Query.ToString() + ")");
                        r.AddDetail(e);
                        sumExpl.AddDetail(r);
                        fail = true;
                    }
                }
                if (fail)
                {
                    sumExpl.Match       = false;
                    sumExpl.Value       = 0.0f;
                    sumExpl.Description = "Failure to meet condition(s) of required/prohibited clause(s)";
                    return(sumExpl);
                }
                else if (shouldMatchCount < minShouldMatch)
                {
                    sumExpl.Match       = false;
                    sumExpl.Value       = 0.0f;
                    sumExpl.Description = "Failure to match minimum number " + "of optional clauses: " + minShouldMatch;
                    return(sumExpl);
                }

                sumExpl.Match = 0 < coord ? true : false;
                sumExpl.Value = sum;

                float coordFactor = DisableCoord ? 1.0f : Coord(coord, maxCoord);

                if (coordFactor == 1.0f)
                {
                    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);
                }
            }
Example #7
0
            public virtual Explanation Explain(IndexReader reader, int doc)
            {
                Explanation sumExpl = new Explanation();

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

                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.GetValue() > 0)
                    {
                        if (!c.IsProhibited())
                        {
                            sumExpl.AddDetail(e);
                            sum += e.GetValue();
                            coord++;
                        }
                        else
                        {
                            return(new Explanation(0.0f, "match prohibited"));
                        }
                    }
                    else if (c.IsRequired())
                    {
                        return(new Explanation(0.0f, "match required"));
                    }
                }
                sumExpl.SetValue(sum);

                if (coord == 1)
                {
                    // only one clause matched
                    sumExpl = sumExpl.GetDetails()[0];                     // eliminate wrapper
                }
                float coordFactor = similarity.Coord(coord, maxCoord);

                if (coordFactor == 1.0f)
                {
                    // coord is no-op
                    return(sumExpl);
                }
                // eliminate wrapper
                else
                {
                    Explanation result = new Explanation();
                    result.SetDescription("product of:");
                    result.AddDetail(sumExpl);
                    result.AddDetail(new Explanation(coordFactor, "coord(" + coord + "/" + maxCoord + ")"));
                    result.SetValue(sum * coordFactor);
                    return(result);
                }
            }
Example #8
0
 public override Explanation Explain(Weight weight, int doc)
 {
     return weight.Explain(reader, doc);
 }
Example #9
0
 public override Explanation Explain(Weight weight, int doc)
 {
     return(weight.Explain(reader, doc));
 }
Example #10
0
 public override Explanation Explain(AtomicReaderContext context, int doc)
 {
     return(@in.Explain(context, doc));
 }