Explain() публичный Метод

Returns an Explanation that describes how doc scored against query.

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.

public Explain ( Query query, int doc ) : Explanation
query Query
doc int
Результат Explanation
Пример #1
0
            public override void  Collect(int doc)
            {
                Explanation exp = null;

                doc = doc + base_Renamed;
                try
                {
                    exp = s.Explain(q, doc);
                }
                catch (System.IO.IOException e)
                {
                    throw new System.SystemException("exception in hitcollector of [[" + d + "]] for #" + doc, e);
                }

                Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null");
                Lucene.Net.Search.CheckHits.VerifyExplanation(d, doc, scorer.Score(), deep, exp);
            }
Пример #2
0
		public static float EXPLAIN_SCORE_TOLERANCE_DELTA = 0.00025f;   // {{See: LUCENENET-288}} Intentional diversion from Java Lucene per above comment
		
		/// <summary> Tests that all documents up to maxDoc which are *not* in the
		/// expected result set, have an explanation which indicates no match
		/// (ie: Explanation value of 0.0f)
		/// </summary>
		public static void  CheckNoMatchExplanations(Query q, System.String defaultFieldName, Searcher searcher, int[] results)
		{
			
			System.String d = q.ToString(defaultFieldName);
			System.Collections.Hashtable ignore = new System.Collections.Hashtable();
			for (int i = 0; i < results.Length; i++)
			{
				SupportClass.CollectionsHelper.AddIfNotContains(ignore, (System.Int32) results[i]);
			}
			
			int maxDoc = searcher.MaxDoc();
			for (int doc = 0; doc < maxDoc; doc++)
			{
				if (ignore.Contains((System.Int32) doc))
					continue;
				
				Explanation exp = searcher.Explain(q, doc);
				Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null");
				Assert.AreEqual(0.0f, exp.GetValue(), 0.0f, "Explanation of [[" + d + "]] for #" + doc + " doesn't indicate non-match: " + exp.ToString());
			}
		}
Пример #3
0
        public static float EXPLAIN_SCORE_TOLERANCE_DELTA = 0.00025f;           // {{See: LUCENENET-288}} Intentional diversion from Java Lucene per above comment

        /// <summary> Tests that all documents up to maxDoc which are *not* in the
        /// expected result set, have an explanation which indicates no match
        /// (ie: Explanation value of 0.0f)
        /// </summary>
        public static void  CheckNoMatchExplanations(Query q, System.String defaultFieldName, Searcher searcher, int[] results)
        {
            System.String d = q.ToString(defaultFieldName);
            System.Collections.Hashtable ignore = new System.Collections.Hashtable();
            for (int i = 0; i < results.Length; i++)
            {
                SupportClass.CollectionsHelper.AddIfNotContains(ignore, (System.Int32)results[i]);
            }

            int maxDoc = searcher.MaxDoc();

            for (int doc = 0; doc < maxDoc; doc++)
            {
                if (ignore.Contains((System.Int32)doc))
                {
                    continue;
                }

                Explanation exp = searcher.Explain(q, doc);
                Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null");
                Assert.AreEqual(0.0f, exp.GetValue(), 0.0f, "Explanation of [[" + d + "]] for #" + doc + " doesn't indicate non-match: " + exp.ToString());
            }
        }
Пример #4
0
 /// <summary> Checks to see if the hits are what we expected.
 /// 
 /// </summary>
 /// <param name="query">the query to execute
 /// </param>
 /// <param name="description">the description of the search
 /// </param>
 /// <param name="expectedIds">the expected document ids of the hits
 /// </param>
 /// <param name="expectedScores">the expected scores of the hits
 /// 
 /// </param>
 /// <throws>  IOException </throws>
 protected internal static void  assertHits(Searcher s, Query query, System.String description, System.String[] expectedIds, float[] expectedScores)
 {
     QueryUtils.Check(query, s);
     
     float tolerance = 1e-5f;
     
     // Hits hits = searcher.search(query);
     // hits normalizes and throws things off if one score is greater than 1.0
     TopDocs topdocs = s.Search(query, null, 10000);
     
     /***
     // display the hits
     System.out.println(hits.length() + " hits for search: \"" + description + '\"');
     for (int i = 0; i < hits.length(); i++) {
     System.out.println("  " + FIELD_ID + ':' + hits.doc(i).get(FIELD_ID) + " (score:" + hits.score(i) + ')');
     }
     *****/
     
     // did we get the hits we expected
     Assert.AreEqual(expectedIds.Length, topdocs.TotalHits);
     for (int i = 0; i < topdocs.TotalHits; i++)
     {
         //System.out.println(i + " exp: " + expectedIds[i]);
         //System.out.println(i + " field: " + hits.doc(i).get(FIELD_ID));
         
         int id = topdocs.ScoreDocs[i].Doc;
         float score = topdocs.ScoreDocs[i].Score;
         Document doc = s.Doc(id);
         Assert.AreEqual(expectedIds[i], doc.Get(FIELD_ID));
         bool scoreEq = System.Math.Abs(expectedScores[i] - score) < tolerance;
         if (!scoreEq)
         {
             System.Console.Out.WriteLine(i + " warning, expected score: " + expectedScores[i] + ", actual " + score);
             System.Console.Out.WriteLine(s.Explain(query, id));
         }
         Assert.AreEqual(expectedScores[i], score, tolerance);
         Assert.AreEqual(s.Explain(query, id).Value, score, tolerance);
     }
 }