/// <summary> /// Tests that a query matches the an expected set of documents using Hits. /// /// <para>Note that when using the Hits API, documents will only be returned /// if they have a positive normalized score. /// </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 displaing the query in assertion messages </param> /// <param name="results"> a list of documentIds that must match the query </param> /// <seealso cref="CheckHitCollector(LuceneTestCase, Random, Query, string, IndexSearcher, int[])"/> // LUCENENET specific // Removes dependency on <see cref="LuceneTestCase.ClassEnv.Similarity"/> public static void DoCheckHits(LuceneTestCase luceneTestCase, Random random, Query query, string defaultFieldName, IndexSearcher searcher, int[] results) #endif { 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], CultureInfo.InvariantCulture)); } SortedSet <int?> actual = new SortedSet <int?>(); for (int i = 0; i < hits.Length; i++) { actual.Add(Convert.ToInt32(hits[i].Doc, CultureInfo.InvariantCulture)); } Assert.AreEqual(correct, actual, query.ToString(defaultFieldName)); QueryUtils.Check( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION luceneTestCase, #endif random, query, searcher, LuceneTestCase.Rarely(random)); }
private TokenFilter MaybePayload(TokenFilter stream, string fieldName) { UninterruptableMonitor.Enter(this); try { previousMappings.TryGetValue(fieldName, out int?val); if (val == null) { val = -1; // no payloads if (LuceneTestCase.Rarely(random)) { switch (random.Next(3)) { case 0: // no payloads val = -1; break; case 1: // variable length payload val = int.MaxValue; break; case 2: // fixed length payload val = random.Next(12); break; } } if (LuceneTestCase.Verbose) { if (val == int.MaxValue) { Console.WriteLine("MockAnalyzer: field=" + fieldName + " gets variable length payloads"); } else if (val != -1) { Console.WriteLine("MockAnalyzer: field=" + fieldName + " gets fixed length=" + val + " payloads"); } } previousMappings[fieldName] = val; // save it so we are consistent for this field } if (val == -1) { return(stream); } else if (val == int.MaxValue) { return(new MockVariableLengthPayloadFilter(random, stream)); } else { return(new MockFixedLengthPayloadFilter(random, stream, (int)val)); } } finally { UninterruptableMonitor.Exit(this); } }
public RandomCodec(Random random, ISet <string> avoidCodecs) { this.perFieldSeed = random.Next(); // TODO: make it possible to specify min/max iterms per // block via CL: int minItemsPerBlock = TestUtil.NextInt32(random, 2, 100); int maxItemsPerBlock = 2 * (Math.Max(2, minItemsPerBlock - 1)) + random.Next(100); int lowFreqCutoff = TestUtil.NextInt32(random, 2, 100); Add(avoidCodecs, new Lucene41PostingsFormat(minItemsPerBlock, maxItemsPerBlock), new FSTPostingsFormat(), new FSTOrdPostingsFormat(), new FSTPulsing41PostingsFormat(1 + random.Next(20)), new FSTOrdPulsing41PostingsFormat(1 + random.Next(20)), new DirectPostingsFormat(LuceneTestCase.Rarely(random) ? 1 : (LuceneTestCase.Rarely(random) ? int.MaxValue : maxItemsPerBlock), LuceneTestCase.Rarely(random) ? 1 : (LuceneTestCase.Rarely(random) ? int.MaxValue : lowFreqCutoff)), new Pulsing41PostingsFormat(1 + random.Next(20), minItemsPerBlock, maxItemsPerBlock), // add pulsing again with (usually) different parameters new Pulsing41PostingsFormat(1 + random.Next(20), minItemsPerBlock, maxItemsPerBlock), //TODO as a PostingsFormat which wraps others, we should allow TestBloomFilteredLucene41Postings to be constructed //with a choice of concrete PostingsFormats. Maybe useful to have a generic means of marking and dealing //with such "wrapper" classes? new TestBloomFilteredLucene41Postings(), new MockSepPostingsFormat(), new MockFixedInt32BlockPostingsFormat(TestUtil.NextInt32(random, 1, 2000)), new MockVariableInt32BlockPostingsFormat(TestUtil.NextInt32(random, 1, 127)), new MockRandomPostingsFormat(random), new NestedPulsingPostingsFormat(), new Lucene41WithOrds(), new SimpleTextPostingsFormat(), new AssertingPostingsFormat(), new MemoryPostingsFormat(true, random.nextFloat()), new MemoryPostingsFormat(false, random.nextFloat()) ); AddDocValues(avoidCodecs, new Lucene45DocValuesFormat(), new DiskDocValuesFormat(), new MemoryDocValuesFormat(), new SimpleTextDocValuesFormat(), new AssertingDocValuesFormat()); formats.Shuffle(random); dvFormats.Shuffle(random); // Avoid too many open files: if (formats.Count > 4) { formats = formats.SubList(0, 4); } if (dvFormats.Count > 4) { dvFormats = dvFormats.SubList(0, 4); } }
// LUCENENET specific - de-nested SetCollector /// <summary> /// Tests that a query matches the an expected set of documents using Hits. /// /// <para>Note that when using the Hits API, documents will only be returned /// if they have a positive normalized score. /// </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 displaing the query in assertion messages </param> /// <param name="results"> a list of documentIds that must match the query </param> /// <seealso cref="CheckHitCollector(Random, Query, string, IndexSearcher, int[])"/> public static void DoCheckHits(Random random, Query query, string defaultFieldName, IndexSearcher searcher, int[] results) { ScoreDoc[] hits = searcher.Search(query, 1000).ScoreDocs; JCG.SortedSet <int> correct = new JCG.SortedSet <int>(); for (int i = 0; i < results.Length; i++) { correct.Add(Convert.ToInt32(results[i], CultureInfo.InvariantCulture)); } JCG.SortedSet <int> actual = new JCG.SortedSet <int>(); for (int i = 0; i < hits.Length; i++) { actual.Add(Convert.ToInt32(hits[i].Doc, CultureInfo.InvariantCulture)); } Assert.AreEqual(correct, actual, aggressive: false, () => query.ToString(defaultFieldName)); QueryUtils.Check(random, query, searcher, LuceneTestCase.Rarely(random)); }
/// <summary> /// Tests that a query matches the an expected set of documents using Hits. /// /// <p> /// Note that when using the Hits API, documents will only be returned /// if they have a positive normalized score. /// </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 displaing the query in assertion messages </param> /// <param name="results"> a list of documentIds that must match the query </param> /// <seealso cref= #checkHitCollector </seealso> public static void DoCheckHits(Random random, Query query, string defaultFieldName, IndexSearcher searcher, int[] results) { 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)); }