/// <summary> /// Tests that a query matches the an expected set of documents using a /// HitCollector. /// <para> /// Note that when using the HitCollector API, documents will be collected /// if they "match" regardless of what their score is. /// </para> /// </summary> /// <param name="luceneTestCase"> The current test instance. </param> /// <param name="query"> The query to test. </param> /// <param name="searcher"> The searcher to test the query against. </param> /// <param name="defaultFieldName"> Used for displaying the query in assertion messages. </param> /// <param name="results"> A list of documentIds that must match the query. </param> /// <seealso cref="DoCheckHits(LuceneTestCase, Random, Query, string, IndexSearcher, int[])"/> // LUCENENET specific // Removes dependency on <see cref="LuceneTestCase.ClassEnv.Similarity"/> public static void CheckHitCollector(LuceneTestCase luceneTestCase, Random random, Query query, string defaultFieldName, IndexSearcher searcher, int[] results) #endif { QueryUtils.Check( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION luceneTestCase, #endif random, query, searcher); Trace.TraceInformation("Checked"); SortedSet <int?> correct = new SortedSet <int?>(); for (int i = 0; i < results.Length; i++) { correct.Add(Convert.ToInt32(results[i], CultureInfo.InvariantCulture)); } SortedSet <int?> actual = new SortedSet <int?>(); ICollector 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( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION luceneTestCase, #endif random, searcher, i); s.Search(query, c); Assert.AreEqual(correct, actual, "Wrap Reader " + i + ": " + query.ToString(defaultFieldName)); } }
/// <summary> Tests that a query matches the an expected set of documents using a /// HitCollector. /// /// <p/> /// Note that when using the HitCollector API, documents will be collected /// if they "match" regardless of what their score is. /// <p/> /// </summary> /// <param name="query">the query to test /// </param> /// <param name="searcher">the searcher to test the query against /// </param> /// <param name="defaultFieldName">used for displaying the query in assertion messages /// </param> /// <param name="results">a list of documentIds that must match the query /// </param> /// <seealso cref="Searcher.Search(Query,HitCollector)"> /// </seealso> /// <seealso cref="checkHits"> /// </seealso> public static void CheckHitCollector(Query query, System.String defaultFieldName, Searcher searcher, int[] results) { QueryUtils.Check(query, searcher); System.Collections.Hashtable correct = new System.Collections.Hashtable(); for (int i = 0; i < results.Length; i++) { SupportClass.CollectionsHelper.AddIfNotContains(correct, (System.Int32)results[i]); } System.Collections.Hashtable actual = new System.Collections.Hashtable(); 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(); QueryUtils.WrapSearcher(searcher, i).Search(query, c); Assert.AreEqual(correct, actual, "Wrap Searcher " + i + ": " + query.ToString(defaultFieldName)); } if (!(searcher is IndexSearcher)) { return; } for (int i = -1; i < 2; i++) { actual.Clear(); QueryUtils.WrapUnderlyingReader((IndexSearcher)searcher, i).Search(query, c); Assert.AreEqual(correct, actual, "Wrap Reader " + i + ": " + query.ToString(defaultFieldName)); } }
/// <summary> /// Tests that a query matches the an expected set of documents using a /// HitCollector. /// /// <p> /// Note that when using the HitCollector API, documents will be collected /// if they "match" regardless of what their score is. /// </p> </summary> /// <param name="query"> the query to test </param> /// <param name="searcher"> the searcher to test the query against </param> /// <param name="defaultFieldName"> used for displaying the query in assertion messages </param> /// <param name="results"> a list of documentIds that must match the query </param> /// <param name="similarity"> /// LUCENENET specific /// Removes dependency on <see cref="LuceneTestCase.ClassEnv.Similarity"/> /// </param> /// <seealso cref=#checkHits </seealso> 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], CultureInfo.InvariantCulture)); } SortedSet <int?> actual = new SortedSet <int?>(); ICollector 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)); } }
/// <summary> /// Tests that a query matches the an expected set of documents using a /// HitCollector. /// <para> /// Note that when using the HitCollector API, documents will be collected /// if they "match" regardless of what their score is. /// </para> /// </summary> /// <param name="query"> The query to test. </param> /// <param name="searcher"> The searcher to test the query against. </param> /// <param name="defaultFieldName"> Used for displaying the query in assertion messages. </param> /// <param name="results"> A list of documentIds that must match the query. </param> /// <seealso cref="DoCheckHits(Random, Query, string, IndexSearcher, int[])"/> public static void CheckHitCollector(Random random, Query query, string defaultFieldName, IndexSearcher searcher, int[] results) { QueryUtils.Check(random, query, searcher); Trace.TraceInformation("Checked"); JCG.SortedSet <int> correct = new JCG.SortedSet <int>(results); JCG.SortedSet <int> actual = new JCG.SortedSet <int>(); ICollector c = new SetCollector(actual); searcher.Search(query, c); Assert.AreEqual(correct, actual, aggressive: false, () => "Simple: " + query.ToString(defaultFieldName)); for (int i = -1; i < 2; i++) { actual.Clear(); IndexSearcher s = QueryUtils.WrapUnderlyingReader(random, searcher, i); s.Search(query, c); Assert.AreEqual(correct, actual, aggressive: false, () => "Wrap Reader " + i + ": " + query.ToString(defaultFieldName)); } }