diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSort.java b/lucene/core/src/test/org/apache/lucene/search/TestSort.java index f0c8b7a3970..7909cc89899 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSort.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSort.java @@ -1331,187 +1331,4 @@ public class TestSort extends LuceneTestCase { } assertEquals(msg, expectedResult, buff.toString()); } - - private static class RandomFilter extends Filter { - private final Random random; - private float density; - private final List docValues; - public final List matchValues = Collections.synchronizedList(new ArrayList()); - - // density should be 0.0 ... 1.0 - public RandomFilter(Random random, float density, List docValues) { - this.random = random; - this.density = density; - this.docValues = docValues; - } - - @Override - public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException { - final int maxDoc = context.reader().maxDoc(); - final FieldCache.Ints idSource = FieldCache.DEFAULT.getInts(context.reader(), "id", false); - assertNotNull(idSource); - final FixedBitSet bits = new FixedBitSet(maxDoc); - for(int docID=0;docID seen = new HashSet(); + final int maxLength = _TestUtil.nextInt(random, 5, 100); + if (VERBOSE) { + System.out.println("TEST: NUM_DOCS=" + NUM_DOCS + " maxLength=" + maxLength + " allowDups=" + allowDups); + } + + int numDocs = 0; + final List docValues = new ArrayList(); + // TODO: deletions + while (numDocs < NUM_DOCS) { + final String s; + if (random.nextBoolean()) { + s = _TestUtil.randomSimpleString(random, maxLength); + } else { + s = _TestUtil.randomUnicodeString(random, maxLength); + } + final BytesRef br = new BytesRef(s); + + if (!allowDups) { + if (seen.contains(s)) { + continue; + } + seen.add(s); + } + + if (VERBOSE) { + System.out.println(" " + numDocs + ": s=" + s); + } + + final Document doc = new Document(); + doc.add(new SortedDocValuesField("stringdv", br)); + doc.add(newStringField("string", s, Field.Store.NO)); + doc.add(new NumericDocValuesField("id", numDocs)); + docValues.add(br); + writer.addDocument(doc); + numDocs++; + + if (random.nextInt(40) == 17) { + // force flush + writer.getReader().close(); + } + } + + final IndexReader r = writer.getReader(); + writer.close(); + if (VERBOSE) { + System.out.println(" reader=" + r); + } + + final IndexSearcher s = newSearcher(r, false); + final int ITERS = atLeast(100); + for(int iter=0;iter docValues; + public final List matchValues = Collections.synchronizedList(new ArrayList()); + + // density should be 0.0 ... 1.0 + public RandomFilter(Random random, float density, List docValues) { + this.random = random; + this.density = density; + this.docValues = docValues; + } + + @Override + public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException { + final int maxDoc = context.reader().maxDoc(); + final FieldCache.Ints idSource = FieldCache.DEFAULT.getInts(context.reader(), "id", false); + assertNotNull(idSource); + final FixedBitSet bits = new FixedBitSet(maxDoc); + for(int docID=0;docID