/// <summary> /// Checks if the <paramref name="seed"/> is an <see cref="IndexReader"/>, and if so will walk /// the hierarchy of subReaders building up a list of the objects /// returned by <c>seed.CoreCacheKey</c> /// </summary> private static IList <object> GetAllDescendantReaderKeys(object seed) // LUCENENET: CA1822: Mark members as static { var all = new JCG.List <object>(17) { seed }; // will grow as we iter for (var i = 0; i < all.Count; i++) { var obj = all[i]; // TODO: We don't check closed readers here (as getTopReaderContext // throws ObjectDisposedException), what should we do? Reflection? if (obj is IndexReader reader) { try { var childs = reader.Context.Children; if (childs != null) // it is composite reader { foreach (var ctx in childs) { all.Add(ctx.Reader.CoreCacheKey); } } } catch (Exception ace) when(ace.IsAlreadyClosedException()) { // ignore this reader } } } // need to skip the first, because it was the seed return(all.GetView(1, all.Count - 1)); // LUCENENET: Converted end index to length }
public override MergeSpecification FindMerges(MergeTrigger mergeTrigger, SegmentInfos segmentInfos) { MergeSpecification mergeSpec = null; //System.out.println("MRMP: findMerges sis=" + segmentInfos); int numSegments /* = segmentInfos.Count*/; // LUCENENET: IDE0059: Remove unnecessary value assignment JCG.List <SegmentCommitInfo> segments = new JCG.List <SegmentCommitInfo>(); ICollection <SegmentCommitInfo> merging = base.m_writer.Get().MergingSegments; foreach (SegmentCommitInfo sipc in segmentInfos.Segments) { if (!merging.Contains(sipc)) { segments.Add(sipc); } } numSegments = segments.Count; if (numSegments > 1 && (numSegments > 30 || random.Next(5) == 3)) { segments.Shuffle(random); // TODO: sometimes make more than 1 merge? mergeSpec = new MergeSpecification(); int segsToMerge = TestUtil.NextInt32(random, 1, numSegments); mergeSpec.Add(new OneMerge(segments.GetView(0, segsToMerge))); // LUCENENET: Checked length for correctness } return(mergeSpec); }
private void PopNextLemma() { // One tag (concatenated) per lemma. WordData lemma = lemmaList[lemmaListIndex++]; termAtt.SetEmpty().Append(lemma.GetStem().ToString()); var tag = lemma.GetTag(); if (tag != null) { string[] tags = lemmaSplitter.Split(tag.ToString()); for (int i = 0; i < tags.Length; i++) { if (tagsList.Count <= i) { tagsList.Add(new StringBuilder()); } StringBuilder buffer = tagsList[i]; buffer.Length = 0; buffer.Append(tags[i]); } tagsAtt.Tags = tagsList.GetView(0, tags.Length - 0); // LUCENENET: Converted end index to length } else { tagsAtt.Tags = Collections.EmptyList <StringBuilder>(); } }
private static IList <FacetField> RandomCategories(Random random) { // add random categories from the two dimensions, ensuring that the same // category is not added twice. int numFacetsA = random.Next(3) + 1; // 1-3 int numFacetsB = random.Next(2) + 1; // 1-2 JCG.List <FacetField> categories_a = new JCG.List <FacetField>(); categories_a.AddRange(CATEGORIES_A); JCG.List <FacetField> categories_b = new JCG.List <FacetField>(); categories_b.AddRange(CATEGORIES_B); categories_a.Shuffle(Random); categories_b.Shuffle(Random); List <FacetField> categories = new List <FacetField>(); categories.AddRange(categories_a.GetView(0, numFacetsA)); // LUCENENET: Checked length for correctness categories.AddRange(categories_b.GetView(0, numFacetsB)); // LUCENENET: Checked length for correctness // add the NO_PARENT categories categories.Add(CATEGORIES_C[Util.LuceneTestCase.Random.Next(NUM_CHILDREN_CP_C)]); categories.Add(CATEGORIES_D[Util.LuceneTestCase.Random.Next(NUM_CHILDREN_CP_D)]); return(categories); }
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.NextSingle()), new MemoryPostingsFormat(false, random.NextSingle()) ); 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.GetView(0, 4); // LUCENENET: Checked length for correctness } if (dvFormats.Count > 4) { dvFormats = dvFormats.GetView(0, 4); // LUCENENET: Checked length for correctness } }
public void TestRandom() { Directory dir = NewDirectory(); RandomIndexWriter w = new RandomIndexWriter( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION this, #endif Random, dir); int num = AtLeast(100); bool singleField = Random.NextBoolean(); JCG.List <Term> terms = new JCG.List <Term>(); for (int i = 0; i < num; i++) { string field = "field" + (singleField ? "1" : Random.Next(100).ToString(CultureInfo.InvariantCulture)); string @string = TestUtil.RandomRealisticUnicodeString(Random); terms.Add(new Term(field, @string)); Document doc = new Document(); doc.Add(NewStringField(field, @string, Field.Store.YES)); w.AddDocument(doc); } IndexReader reader = w.GetReader(); w.Dispose(); IndexSearcher searcher = NewSearcher(reader); int numQueries = AtLeast(10); for (int i = 0; i < numQueries; i++) { terms.Shuffle(Random); int numTerms = 1 + Random.Next(Math.Min(BooleanQuery.MaxClauseCount, terms.Count)); BooleanQuery bq = new BooleanQuery(); for (int j = 0; j < numTerms; j++) { bq.Add(new BooleanClause(new TermQuery(terms[j]), Occur.SHOULD)); } TopDocs queryResult = searcher.Search(new ConstantScoreQuery(bq), reader.MaxDoc); MatchAllDocsQuery matchAll = new MatchAllDocsQuery(); TermsFilter filter = TermsFilter(singleField, terms.GetView(0, numTerms)); // LUCENENET: Checked length for correctness TopDocs filterResult = searcher.Search(matchAll, filter, reader.MaxDoc); assertEquals(filterResult.TotalHits, queryResult.TotalHits); ScoreDoc[] scoreDocs = filterResult.ScoreDocs; for (int j = 0; j < scoreDocs.Length; j++) { assertEquals(scoreDocs[j].Doc, queryResult.ScoreDocs[j].Doc); } } reader.Dispose(); dir.Dispose(); }
public override MergeSpecification FindForcedMerges(SegmentInfos segmentInfos, int maxSegmentCount, IDictionary <SegmentCommitInfo, bool?> segmentsToMerge) { JCG.List <SegmentCommitInfo> eligibleSegments = new JCG.List <SegmentCommitInfo>(); foreach (SegmentCommitInfo info in segmentInfos.Segments) { if (segmentsToMerge.ContainsKey(info)) { eligibleSegments.Add(info); } } //System.out.println("MRMP: findMerges sis=" + segmentInfos + " eligible=" + eligibleSegments); MergeSpecification mergeSpec = null; if (eligibleSegments.Count > 1 || (eligibleSegments.Count == 1 && eligibleSegments[0].HasDeletions)) { mergeSpec = new MergeSpecification(); // Already shuffled having come out of a set but // shuffle again for good measure: eligibleSegments.Shuffle(random); int upto = 0; while (upto < eligibleSegments.Count) { int max = Math.Min(10, eligibleSegments.Count - upto); int inc = max <= 2 ? max : TestUtil.NextInt32(random, 2, max); mergeSpec.Add(new OneMerge(eligibleSegments.GetView(upto, inc))); // LUCENENET: Converted end index to length upto += inc; } } if (mergeSpec != null) { foreach (OneMerge merge in mergeSpec.Merges) { foreach (SegmentCommitInfo info in merge.Segments) { if (Debugging.AssertsEnabled) { Debugging.Assert(segmentsToMerge.ContainsKey(info)); } } } } return(mergeSpec); }
public virtual void TestNextVaryingNumberOfTerms() { IList <string> termsList = new JCG.List <string>(commonTerms.Length + mediumTerms.Length + rareTerms.Length); termsList.AddRange(commonTerms); termsList.AddRange(mediumTerms); termsList.AddRange(rareTerms); termsList.Shuffle(Random); for (int numTerms = 2; numTerms <= termsList.Count; numTerms++) { string[] terms = termsList.GetView(0, numTerms).ToArray(/*new string[0]*/); // LUCENENET: Checked length of GetView() for correctness for (int minNrShouldMatch = 1; minNrShouldMatch <= terms.Length; minNrShouldMatch++) { Scorer expected = Scorer(terms, minNrShouldMatch, true); Scorer actual = Scorer(terms, minNrShouldMatch, false); AssertNext(expected, actual); } } }