Lucene.Net.Search.CheckHits.CheckNoMatchExplanations C# (CSharp) Method

CheckNoMatchExplanations() public static method

Tests that all documents up to maxDoc which are *not* in the expected result set, have an explanation which indicates that the document does not match
public static CheckNoMatchExplanations ( Query q, string defaultFieldName, IndexSearcher searcher, int results ) : void
q Query
defaultFieldName string
searcher IndexSearcher
results int
return void
        public static void CheckNoMatchExplanations(Query q, string defaultFieldName, IndexSearcher searcher, int[] results)
        {
            string d = q.ToString(defaultFieldName);
            SortedSet<int?> ignore = new SortedSet<int?>();
            for (int i = 0; i < results.Length; i++)
            {
                ignore.Add(Convert.ToInt32(results[i]));
            }

            int maxDoc = searcher.IndexReader.MaxDoc;
            for (int doc = 0; doc < maxDoc; doc++)
            {
                if (ignore.Contains(Convert.ToInt32(doc)))
                {
                    continue;
                }

                Explanation exp = searcher.Explain(q, doc);
                Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null");
                Assert.IsFalse(exp.IsMatch, "Explanation of [[" + d + "]] for #" + doc + " doesn't indicate non-match: " + exp.ToString());
            }
        }

Usage Example

 /// <summary> Overrides superclass to ignore matches and focus on non-matches
 ///
 /// </summary>
 /// <seealso cref="CheckHits.checkNoMatchExplanations">
 /// </seealso>
 public override void  Qtest(Query q, int[] expDocNrs)
 {
     CheckHits.CheckNoMatchExplanations(q, FIELD, searcher, expDocNrs);
 }