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

DoCheckHits() public static method

Tests that a query matches the an expected set of documents using Hits.

Note that when using the Hits API, documents will only be returned if they have a positive normalized score.

public static DoCheckHits ( Random random, Query query, string defaultFieldName, IndexSearcher searcher, int results, Similarity similarity ) : void
random System.Random
query Query the query to test
defaultFieldName string used for displaing the query in assertion messages
searcher IndexSearcher the searcher to test the query against
results int a list of documentIds that must match the query
similarity Similarity /// LUCENENET specific /// Removes dependency on ///
return void
        public static void DoCheckHits(Random random, Query query, string defaultFieldName, IndexSearcher searcher, int[] results, Similarity similarity)
        {
            ScoreDoc[] hits = searcher.Search(query, 1000).ScoreDocs;

            SortedSet<int?> correct = new SortedSet<int?>();
            for (int i = 0; i < results.Length; i++)
            {
                correct.Add(Convert.ToInt32(results[i]));
            }

            SortedSet<int?> actual = new SortedSet<int?>();
            for (int i = 0; i < hits.Length; i++)
            {
                actual.Add(Convert.ToInt32(hits[i].Doc));
            }

            Assert.AreEqual(correct, actual, query.ToString(defaultFieldName));

            QueryUtils.Check(random, query, searcher, LuceneTestCase.Rarely(random), similarity);
        }