示例#1
0
        /// <returns> An explanation for the score of a given document.
        /// </returns>
        public override Explanation Explain(int doc)
        {
            Explanation res = new Explanation();

            System.Collections.IEnumerator ssi = subScorers.GetEnumerator();
            float sumScore  = 0.0f;
            int   nrMatches = 0;

            while (ssi.MoveNext())
            {
                Explanation es = ((Scorer)ssi.Current).Explain(doc);
                if (es.GetValue() > 0.0f)
                {
                    // indicates match
                    sumScore += es.GetValue();
                    nrMatches++;
                }
                res.AddDetail(es);
            }
            if (nrMatchers >= minimumNrMatchers)
            {
                res.SetValue(sumScore);
                res.SetDescription("sum over at least " + minimumNrMatchers + " of " + subScorers.Count + ":");
            }
            else
            {
                res.SetValue(0.0f);
                res.SetDescription(nrMatches + " match(es) but at least " + minimumNrMatchers + " of " + subScorers.Count + " needed");
            }
            return(res);
        }
示例#2
0
        public override Explanation Explain(int doc)
        {
            Explanation res = new Explanation();

            if (exclDisi.Advance(doc) == doc)
            {
                res.SetDescription("excluded");
            }
            else
            {
                res.SetDescription("not excluded");
                res.AddDetail(reqScorer.Explain(doc));
            }
            return(res);
        }
示例#3
0
        /// <summary>Returns an explanation of the score for a document.
        /// <br/>When this method is used, the {@link #Next()} method
        /// and the {@link #Score(HitCollector)} method should not be used.
        /// </summary>
        /// <param name="doc">The document number for the explanation.
        /// </param>
        public override Explanation Explain(int doc)
        {
            TermQuery   query         = (TermQuery)weight.GetQuery();
            Explanation tfExplanation = new Explanation();
            int         tf            = 0;

            while (pointer < pointerMax)
            {
                if (docs[pointer] == doc)
                {
                    tf = freqs[pointer];
                }
                pointer++;
            }
            if (tf == 0)
            {
                if (termDocs.SkipTo(doc))
                {
                    if (termDocs.Doc() == doc)
                    {
                        tf = termDocs.Freq();
                    }
                }
            }
            termDocs.Close();
            tfExplanation.SetValue(GetSimilarity().Tf(tf));
            tfExplanation.SetDescription("tf(termFreq(" + query.GetTerm() + ")=" + tf + ")");

            return(tfExplanation);
        }
示例#4
0
                // add an explanation about whether the document was filtered
                public override Explanation Explain(int i)
                {
                    Explanation exp = scorer.Explain(i);

                    if (docIdSetIterator.Advance(i) == i)
                    {
                        exp.SetDescription("allowed by filter: " + exp.GetDescription());
                        exp.SetValue(Enclosing_Instance.Enclosing_Instance.GetBoost() * exp.GetValue());
                    }
                    else
                    {
                        exp.SetDescription("removed by filter: " + exp.GetDescription());
                        exp.SetValue(0.0f);
                    }
                    return(exp);
                }
示例#5
0
        /// <summary>Explain the score of a document.
        /// TODO: Also show the total score.
        /// See BooleanScorer.explain() on how to do this.
        /// </summary>
        public override Explanation Explain(int doc)
        {
            Explanation res = new Explanation();

            res.SetDescription("required, optional");
            res.AddDetail(reqScorer.Explain(doc));
            res.AddDetail(optScorer.Explain(doc));
            return(res);
        }
示例#6
0
        public override Explanation Explain(int doc)
        {
            Explanation tfExplanation = new Explanation();

            int   d          = Advance(doc);
            float phraseFreq = (d == doc)?freq:0.0f;

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

            return(tfExplanation);
        }
示例#7
0
		/// <summary>Returns an explanation of the score for a document.
		/// <br/>When this method is used, the {@link #Next()} method
		/// and the {@link #Score(HitCollector)} method should not be used.
		/// </summary>
		/// <param name="doc">The document number for the explanation.
		/// </param>
		public override Explanation Explain(int doc)
		{
			TermQuery query = (TermQuery) weight.GetQuery();
			Explanation tfExplanation = new Explanation();
			int tf = 0;
			while (pointer < pointerMax)
			{
				if (docs[pointer] == doc)
					tf = freqs[pointer];
				pointer++;
			}
			if (tf == 0)
			{
				if (termDocs.SkipTo(doc))
				{
					if (termDocs.Doc() == doc)
					{
						tf = termDocs.Freq();
					}
				}
			}
			termDocs.Close();
			tfExplanation.SetValue(GetSimilarity().Tf(tf));
			tfExplanation.SetDescription("tf(termFreq(" + query.GetTerm() + ")=" + tf + ")");
			
			return tfExplanation;
		}
示例#8
0
            public override Explanation Explain(IndexReader reader, int doc)
            {
                Explanation result = new Explanation();

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

                System.Text.StringBuilder docFreqs = new System.Text.StringBuilder();
                System.Text.StringBuilder query    = new System.Text.StringBuilder();
                query.Append('\"');
                docFreqs.Append(idfExp.Explain());
                for (int i = 0; i < Enclosing_Instance.terms.Count; i++)
                {
                    if (i != 0)
                    {
                        query.Append(" ");
                    }

                    Term term = (Term)Enclosing_Instance.terms[i];

                    query.Append(term.Text());
                }
                query.Append('\"');

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

                // 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
                Explanation fieldExpl = new Explanation();

                fieldExpl.SetDescription("fieldWeight(" + Enclosing_Instance.field + ":" + query + " 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.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);
            }
示例#9
0
			public override Explanation Explain(IndexReader reader, int doc)
			{
				
				ComplexExplanation result = new ComplexExplanation();
				result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
				
				Explanation expl = new Explanation(idf, idfExp.Explain());
				
				// 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(expl);
				
				Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");
				queryExpl.AddDetail(queryNormExpl);
				
				queryExpl.SetValue(boostExpl.GetValue() * expl.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, true, false).Explain(doc);
				fieldExpl.AddDetail(tfExpl);
				fieldExpl.AddDetail(expl);
				
				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() * expl.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 override Explanation Explain(int doc)
		{
			Explanation tfExplanation = new Explanation();
			
			int d = Advance(doc);
			float phraseFreq = (d == doc)?freq:0.0f;
			tfExplanation.SetValue(GetSimilarity().Tf(phraseFreq));
			tfExplanation.SetDescription("tf(phraseFreq=" + phraseFreq + ")");
			
			return tfExplanation;
		}
示例#11
0
			public override Explanation Explain(IndexReader reader, int doc)
			{
				
				Explanation result = new Explanation();
				result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
				
				System.Text.StringBuilder docFreqs = new System.Text.StringBuilder();
				System.Text.StringBuilder query = new System.Text.StringBuilder();
				query.Append('\"');
				docFreqs.Append(idfExp.Explain());
				for (int i = 0; i < Enclosing_Instance.terms.Count; i++)
				{
					if (i != 0)
					{
						query.Append(" ");
					}
					
					Term term = (Term) Enclosing_Instance.terms[i];
					
					query.Append(term.Text());
				}
				query.Append('\"');
				
				Explanation idfExpl = new Explanation(idf, "idf(" + Enclosing_Instance.field + ":" + docFreqs + ")");
				
				// 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
				Explanation fieldExpl = new Explanation();
				fieldExpl.SetDescription("fieldWeight(" + Enclosing_Instance.field + ":" + query + " 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.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;
			}
示例#12
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);
            }
示例#13
0
		/// <returns> An explanation for the score of a given document. 
		/// </returns>
		public override Explanation Explain(int doc)
		{
			Explanation res = new Explanation();
			System.Collections.IEnumerator ssi = subScorers.GetEnumerator();
			float sumScore = 0.0f;
			int nrMatches = 0;
			while (ssi.MoveNext())
			{
				Explanation es = ((Scorer) ssi.Current).Explain(doc);
				if (es.GetValue() > 0.0f)
				{
					// indicates match
					sumScore += es.GetValue();
					nrMatches++;
				}
				res.AddDetail(es);
			}
			if (nrMatchers >= minimumNrMatchers)
			{
				res.SetValue(sumScore);
				res.SetDescription("sum over at least " + minimumNrMatchers + " of " + subScorers.Count + ":");
			}
			else
			{
				res.SetValue(0.0f);
				res.SetDescription(nrMatches + " match(es) but at least " + minimumNrMatchers + " of " + subScorers.Count + " needed");
			}
			return res;
		}
示例#14
0
		/// <summary>Explain the score of a document.
		/// TODO: Also show the total score.
		/// See BooleanScorer.explain() on how to do this.
		/// </summary>
		public override Explanation Explain(int doc)
		{
			Explanation res = new Explanation();
			res.SetDescription("required, optional");
			res.AddDetail(reqScorer.Explain(doc));
			res.AddDetail(optScorer.Explain(doc));
			return res;
		}