Apache Solr open-source search software
remove the crutch
Robert Muirad04c854ec89
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat2.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat2.javaindex c324f7909a7..00bbcf3b8da 100644--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat2.java+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat2.java@@ -47,7 +47,6 @@ public class TestBlockPostingsFormat2 extends LuceneTestCase {iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));iwc.setCodec(_TestUtil.alwaysPostingsFormat(new Lucene41PostingsFormat()));iw = new RandomIndexWriter(random(), dir, iwc);- iw.setAddDocValuesFields(false);iw.setDoRandomForceMerge(false); // we will ourselves}diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.javaindex 4f9ddf4bed4..c9b4d27d942 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java@@ -79,12 +79,8 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {}public void testOneNumber() throws IOException {- Analyzer analyzer = new MockAnalyzer(random());-Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!- IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);Document doc = new Document();String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";String text = "This is the text to be indexed. " + longTerm;@@ -115,12 +111,8 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {}public void testOneFloat() throws IOException {- Analyzer analyzer = new MockAnalyzer(random());-Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!- IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);Document doc = new Document();String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";String text = "This is the text to be indexed. " + longTerm;@@ -151,12 +143,8 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {}public void testTwoNumbers() throws IOException {- Analyzer analyzer = new MockAnalyzer(random());-Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!- IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);Document doc = new Document();String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";String text = "This is the text to be indexed. " + longTerm;@@ -190,12 +178,8 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {}public void testTwoFieldsMixed() throws IOException {- Analyzer analyzer = new MockAnalyzer(random());-Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!- IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);Document doc = new Document();String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";String text = "This is the text to be indexed. " + longTerm;@@ -231,12 +215,8 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {}public void testThreeFieldsMixed() throws IOException {- Analyzer analyzer = new MockAnalyzer(random());-Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!- IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);Document doc = new Document();String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";String text = "This is the text to be indexed. " + longTerm;@@ -277,12 +257,8 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {}public void testThreeFieldsMixed2() throws IOException {- Analyzer analyzer = new MockAnalyzer(random());-Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!- IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);Document doc = new Document();String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";String text = "This is the text to be indexed. " + longTerm;@@ -326,10 +302,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new NumericDocValuesField("dv", 1));iwriter.addDocument(doc);@@ -354,10 +329,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(newField("id", "0", StringField.TYPE_STORED));doc.add(new NumericDocValuesField("dv", -10));@@ -393,10 +367,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new NumericDocValuesField("dv", Long.MIN_VALUE));iwriter.addDocument(doc);@@ -421,10 +394,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new NumericDocValuesField("dv", -8841491950446638677L));iwriter.addDocument(doc);@@ -449,9 +421,8 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";String text = "This is the text to be indexed. " + longTerm;@@ -487,10 +458,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(newField("id", "0", StringField.TYPE_STORED));doc.add(new BinaryDocValuesField("dv", new BytesRef("hello world 1")));@@ -528,9 +498,8 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";String text = "This is the text to be indexed. " + longTerm;@@ -566,10 +535,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 1")));iwriter.addDocument(doc);@@ -597,10 +565,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 1")));iwriter.addDocument(doc);@@ -635,10 +602,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(newField("id", "0", StringField.TYPE_STORED));doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 1")));@@ -681,10 +647,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new BinaryDocValuesField("dv", new BytesRef("hello\nworld\r1")));iwriter.addDocument(doc);@@ -706,10 +671,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new SortedDocValuesField("dv", new BytesRef("hello world 2")));iwriter.addDocument(doc);@@ -734,10 +698,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new SortedDocValuesField("dv", new BytesRef("")));iwriter.addDocument(doc);@@ -765,10 +728,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new BinaryDocValuesField("dv", new BytesRef("")));iwriter.addDocument(doc);@@ -796,10 +758,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();byte bytes[] = new byte[32766];BytesRef b = new BytesRef(bytes);@@ -824,10 +785,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();byte bytes[] = new byte[32766];BytesRef b = new BytesRef(bytes);@@ -851,10 +811,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new BinaryDocValuesField("dv", new BytesRef("boo!")));iwriter.addDocument(doc);@@ -878,10 +837,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new SortedDocValuesField("dv", new BytesRef("boo!")));iwriter.addDocument(doc);@@ -905,10 +863,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new BinaryDocValuesField("dv", new BytesRef("foo!")));iwriter.addDocument(doc);@@ -939,10 +896,9 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {Analyzer analyzer = new MockAnalyzer(random());Directory directory = newDirectory();- // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);conf.setMergePolicy(newLogMergePolicy());- IndexWriter iwriter = new IndexWriter(directory, conf);+ RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);Document doc = new Document();doc.add(new SortedDocValuesField("dv", new BytesRef("foo!")));iwriter.addDocument(doc);@@ -1016,7 +972,7 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {public void testRandomSortedBytes() throws IOException {Directory dir = newDirectory();IndexWriterConfig cfg = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));- IndexWriter w = new IndexWriter(dir, cfg);+ RandomIndexWriter w = new RandomIndexWriter(random(), dir, cfg);int numDocs = atLeast(100);BytesRefHash hash = new BytesRefHash();Map<String, String> docToString = new HashMap<String, String>();@@ -1090,7 +1046,7 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {private void doTestNumericsVsStoredFields(long minValue, long maxValue) throws Exception {Directory dir = newDirectory();IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));- IndexWriter writer = new IndexWriter(dir, conf);+ RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);Document doc = new Document();Field idField = new StringField("id", "", Field.Store.NO);Field storedField = newStringField("stored", "", Field.Store.YES);@@ -1157,7 +1113,7 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {private void doTestBinaryVsStoredFields(int minLength, int maxLength) throws Exception {Directory dir = newDirectory();IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));- IndexWriter writer = new IndexWriter(dir, conf);+ RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);Document doc = new Document();Field idField = new StringField("id", "", Field.Store.NO);Field storedField = new StoredField("stored", new byte[0]);@@ -1222,7 +1178,7 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {private void doTestSortedVsStoredFields(int minLength, int maxLength) throws Exception {Directory dir = newDirectory();IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));- IndexWriter writer = new IndexWriter(dir, conf);+ RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);Document doc = new Document();Field idField = new StringField("id", "", Field.Store.NO);Field storedField = new StoredField("stored", new byte[0]);diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java b/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.javaindex eb508433f97..59964f40b7c 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java@@ -53,11 +53,6 @@ public class RandomIndexWriter implements Closeable {int flushAt;private double flushAtFactor = 1.0;private boolean getReaderCalled;- private final int fixedBytesLength;- private final long docValuesFieldPrefix;- // nocommit: remove this test coverage hack once we have a- // good set of real tests.- private volatile boolean doDocValues;private final Codec codec; // sugar// Randomly calls Thread.yield so we mixup thread scheduling@@ -105,49 +100,12 @@ public class RandomIndexWriter implements Closeable {System.out.println("RIW dir=" + dir + " config=" + w.getConfig());System.out.println("codec default=" + codec.getName());}- /* TODO: find some way to make this random...- * This must be fixed across all fixed bytes- * fields in one index. so if you open another writer- * this might change if I use r.nextInt(x)- * maybe we can peek at the existing files here?- */- fixedBytesLength = 17;-- // NOTE: this means up to 13 * 5 unique fields (we have- // 13 different DV types):- docValuesFieldPrefix = r.nextInt(5);- switchDoDocValues();// Make sure we sometimes test indices that don't get// any forced merges:doRandomForceMerge = r.nextBoolean();}- private boolean addDocValuesFields = true;-- /**- * set to false if you don't want RandomIndexWriter- * adding docvalues fields.- */- public void setAddDocValuesFields(boolean v) {- addDocValuesFields = v;- switchDoDocValues();- }-- private void switchDoDocValues() {- if (addDocValuesFields == false) {- doDocValues = false;- return;- }- // randomly enable / disable docValues- doDocValues = LuceneTestCase.rarely(r);- if (LuceneTestCase.VERBOSE) {- if (doDocValues) {- System.out.println("NOTE: RIW: turning on random DocValues fields");- }- }- }-/*** Adds a Document.* @see IndexWriter#addDocument(org.apache.lucene.index.IndexDocument)@@ -157,9 +115,6 @@ public class RandomIndexWriter implements Closeable {}public <T extends IndexableField> void addDocument(final IndexDocument doc, Analyzer a) throws IOException {- if (doDocValues && doc instanceof Document) {- randomPerDocFieldValues((Document) doc);- }if (r.nextInt(5) == 3) {// TODO: maybe, we should simply buffer up added docs// (but we need to clone them), and only when@@ -200,43 +155,6 @@ public class RandomIndexWriter implements Closeable {maybeCommit();}- private BytesRef getFixedRandomBytes() {- final String randomUnicodeString = _TestUtil.randomFixedByteLengthUnicodeString(r, fixedBytesLength);- BytesRef fixedRef = new BytesRef(randomUnicodeString);- if (fixedRef.length > fixedBytesLength) {- fixedRef = new BytesRef(fixedRef.bytes, 0, fixedBytesLength);- } else {- fixedRef.grow(fixedBytesLength);- fixedRef.length = fixedBytesLength;- }- return fixedRef;- }-- private void randomPerDocFieldValues(Document doc) {-- DocValuesType[] values = DocValuesType.values();- DocValuesType type = values[r.nextInt(values.length)];- String name = "random_" + type.name() + "" + docValuesFieldPrefix;- if (doc.getField(name) != null) {- return;- }- final Field f;- switch (type) {- case BINARY:- f = new BinaryDocValuesField(name, new BytesRef(_TestUtil.randomUnicodeString(r, 20)));- break;- case SORTED:- f = new SortedDocValuesField(name, new BytesRef(_TestUtil.randomUnicodeString(r, 20)));- break;- case NUMERIC:- f = new NumericDocValuesField(name, r.nextLong());- break;- default:- throw new IllegalArgumentException("no such type: " + type);- }- doc.add(f);- }-private void maybeCommit() throws IOException {if (docCount++ == flushAt) {if (LuceneTestCase.VERBOSE) {@@ -248,7 +166,6 @@ public class RandomIndexWriter implements Closeable {// gradually but exponentially increase time b/w flushesflushAtFactor *= 1.05;}- switchDoDocValues();}}@@ -267,9 +184,6 @@ public class RandomIndexWriter implements Closeable {* @see IndexWriter#updateDocument(Term, org.apache.lucene.index.IndexDocument)*/public <T extends IndexableField> void updateDocument(Term t, final IndexDocument doc) throws IOException {- if (doDocValues) {- randomPerDocFieldValues((Document) doc);- }if (r.nextInt(5) == 3) {w.updateDocuments(t, new Iterable<IndexDocument>() {@@ -323,7 +237,6 @@ public class RandomIndexWriter implements Closeable {public void commit() throws IOException {w.commit();- switchDoDocValues();}public int numDocs() {@@ -380,7 +293,6 @@ public class RandomIndexWriter implements Closeable {assert !doRandomForceMergeAssert || w.getSegmentCount() <= limit: "limit=" + limit + " actual=" + w.getSegmentCount();}}- switchDoDocValues();}public DirectoryReader getReader(boolean applyDeletions) throws IOException {@@ -401,7 +313,6 @@ public class RandomIndexWriter implements Closeable {System.out.println("RIW.getReader: open new reader");}w.commit();- switchDoDocValues();if (r.nextBoolean()) {return DirectoryReader.open(w.getDirectory(), _TestUtil.nextInt(r, 1, 10));} else {