@BeforeClass
  public static void beforeClass() throws Exception {
    directory = newDirectory();
    RandomIndexWriter writer =
        new RandomIndexWriter(
            random,
            directory,
            newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))
                .setMergePolicy(newLogMergePolicy()));
    for (int i = 0; i < docFields.length; i++) {
      Document doc = new Document();
      doc.add(newField(field, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
      writer.addDocument(doc);
    }
    writer.close();
    littleReader = IndexReader.open(directory);
    searcher = new IndexSearcher(littleReader);

    // Make big index
    dir2 = new MockDirectoryWrapper(random, new RAMDirectory(directory));

    // First multiply small test index:
    mulFactor = 1;
    int docCount = 0;
    do {
      final Directory copy = new MockDirectoryWrapper(random, new RAMDirectory(dir2));
      RandomIndexWriter w = new RandomIndexWriter(random, dir2);
      w.addIndexes(copy);
      docCount = w.maxDoc();
      w.close();
      mulFactor *= 2;
    } while (docCount < 3000);

    RandomIndexWriter w =
        new RandomIndexWriter(
            random,
            dir2,
            newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))
                .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000)));
    Document doc = new Document();
    doc.add(newField("field2", "xxx", Field.Store.NO, Field.Index.ANALYZED));
    for (int i = 0; i < NUM_EXTRA_DOCS / 2; i++) {
      w.addDocument(doc);
    }
    doc = new Document();
    doc.add(newField("field2", "big bad bug", Field.Store.NO, Field.Index.ANALYZED));
    for (int i = 0; i < NUM_EXTRA_DOCS / 2; i++) {
      w.addDocument(doc);
    }
    reader = w.getReader();
    bigSearcher = newSearcher(reader);
    w.close();
  }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   dir = newDirectory();
   iw = new RandomIndexWriter(random(), dir);
   Document doc = new Document();
   Field idField = new StringField("id", "", Field.Store.NO);
   doc.add(idField);
   // add 500 docs with id 0..499
   for (int i = 0; i < 500; i++) {
     idField.setStringValue(Integer.toString(i));
     iw.addDocument(doc);
   }
   // delete 20 of them
   for (int i = 0; i < 20; i++) {
     iw.deleteDocuments(new Term("id", Integer.toString(random().nextInt(iw.maxDoc()))));
   }
   ir = iw.getReader();
   is = newSearcher(ir);
 }