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

CheckHitCollector() public static method

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

Note that when using the HitCollector API, documents will be collected if they "match" regardless of what their score is.

public static CheckHitCollector ( 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 displaying 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 CheckHitCollector(Random random, Query query, string defaultFieldName, IndexSearcher searcher, int[] results, Similarity similarity)
        {
            QueryUtils.Check(random, query, searcher, similarity);

            Trace.TraceInformation("Checked");

            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?>();
            Collector c = new SetCollector(actual);

            searcher.Search(query, c);

            Assert.AreEqual(correct, actual, "Simple: " + query.ToString(defaultFieldName));

            for (int i = -1; i < 2; i++)
            {
                actual.Clear();
                IndexSearcher s = QueryUtils.WrapUnderlyingReader(random, searcher, i, similarity);
                s.Search(query, c);
                Assert.AreEqual(correct, actual, "Wrap Reader " + i + ": " + query.ToString(defaultFieldName));
            }
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// check the expDocNrs first, then check the query (and the explanations) </summary>
        public virtual void Qtest(Query q, int[] expDocNrs)
        {
            CheckHits.CheckHitCollector(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                this,
#endif
                Random, q, FIELD, Searcher, expDocNrs);
        }
All Usage Examples Of Lucene.Net.Search.CheckHits::CheckHitCollector