## org.apache.lucene.index
Class RandomIndexWriter

    java.lang.Object
      org.apache.lucene.index.RandomIndexWriter

All Implemented Interfaces:
  Closeable

    public class RandomIndexWriter

extends Object
implements Closeable

Silly class that randomizes the indexing experience. EG it may swap in a different merge policy/scheduler; may commit periodically; may or may not optimize in the end, may flush by doc count instead of RAM, etc.

Field Summary
`org.apache.lucene.index.IndexWriter` `w`

Constructor Summary
`RandomIndexWriter(Random r, org.apache.lucene.store.Directory dir)` create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENT and Whitespace+LowercasingAnalyzer
`RandomIndexWriter(Random r, org.apache.lucene.store.Directory dir, org.apache.lucene.analysis.Analyzer a)` create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENT
`RandomIndexWriter(Random r, org.apache.lucene.store.Directory dir, org.apache.lucene.index.IndexWriterConfig c)` create a RandomIndexWriter with the provided config
`RandomIndexWriter(Random r, org.apache.lucene.store.Directory dir, org.apache.lucene.util.Version v, org.apache.lucene.analysis.Analyzer a)` create a RandomIndexWriter with a random config

Method Summary
`void` `addDocument(org.apache.lucene.document.Document doc)` Adds a Document.
`void` `addDocuments(Collection<org.apache.lucene.document.Document> docs)`
`void` `addIndexes(org.apache.lucene.store.Directory... dirs)`
`void` `close()` Close this writer.
`void` `commit()`
`void` `deleteAll()`
`void` `deleteDocuments(org.apache.lucene.search.Query q)`
`void` `deleteDocuments(org.apache.lucene.index.Term term)`
`org.apache.lucene.index.IndexReader` `getReader()`
`org.apache.lucene.index.IndexReader` `getReader(boolean applyDeletions)`
`int` `maxDoc()`
`int` `numDocs()`
`void` `optimize()` Forces an optimize.
`void` `setDoRandomOptimize(boolean v)`
`void` `setDoRandomOptimizeAssert(boolean v)`
`void` `updateDocument(org.apache.lucene.index.Term t, org.apache.lucene.document.Document doc)` Updates a document.
`void` `updateDocuments(org.apache.lucene.index.Term delTerm, Collection<org.apache.lucene.document.Document> docs)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### w

    public org.apache.lucene.index.IndexWriter w

Constructor Detail

### RandomIndexWriter

    public RandomIndexWriter(Random r,
                             org.apache.lucene.store.Directory dir)
                      throws IOException

  create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENT and Whitespace+LowercasingAnalyzer

  Throws:
    `IOException`

### RandomIndexWriter

    public RandomIndexWriter(Random r,
                             org.apache.lucene.store.Directory dir,
                             org.apache.lucene.analysis.Analyzer a)
                      throws IOException

  create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENT

  Throws:
    `IOException`

### RandomIndexWriter

    public RandomIndexWriter(Random r,
                             org.apache.lucene.store.Directory dir,
                             org.apache.lucene.util.Version v,
                             org.apache.lucene.analysis.Analyzer a)
                      throws IOException

  create a RandomIndexWriter with a random config

  Throws:
    `IOException`

### RandomIndexWriter

    public RandomIndexWriter(Random r,
                             org.apache.lucene.store.Directory dir,
                             org.apache.lucene.index.IndexWriterConfig c)
                      throws IOException

  create a RandomIndexWriter with the provided config

  Throws:
    `IOException`

Method Detail

### addDocument

    public void addDocument(org.apache.lucene.document.Document doc)
                     throws IOException

  Adds a Document.

  Throws:
    `IOException`
  See Also:
    `IndexWriter.addDocument(Document)`

### addDocuments

    public void addDocuments(Collection<org.apache.lucene.document.Document> docs)
                      throws IOException

  Throws:
    `IOException`

### updateDocuments

    public void updateDocuments(org.apache.lucene.index.Term delTerm,
                                Collection<org.apache.lucene.document.Document> docs)
                         throws IOException

  Throws:
    `IOException`

### updateDocument

    public void updateDocument(org.apache.lucene.index.Term t,
                               org.apache.lucene.document.Document doc)
                        throws IOException

  Updates a document.

  Throws:
    `IOException`
  See Also:
    `IndexWriter.updateDocument(Term, Document)`

### addIndexes

    public void addIndexes(org.apache.lucene.store.Directory... dirs)
                    throws org.apache.lucene.index.CorruptIndexException,
                           IOException

  Throws:
    `org.apache.lucene.index.CorruptIndexException`
    `IOException`

### deleteDocuments

    public void deleteDocuments(org.apache.lucene.index.Term term)
                         throws org.apache.lucene.index.CorruptIndexException,
                                IOException

  Throws:
    `org.apache.lucene.index.CorruptIndexException`
    `IOException`

### deleteDocuments

    public void deleteDocuments(org.apache.lucene.search.Query q)
                         throws org.apache.lucene.index.CorruptIndexException,
                                IOException

  Throws:
    `org.apache.lucene.index.CorruptIndexException`
    `IOException`

### commit

    public void commit()
                throws org.apache.lucene.index.CorruptIndexException,
                       IOException

  Throws:
    `org.apache.lucene.index.CorruptIndexException`
    `IOException`

### numDocs

    public int numDocs()
                throws IOException

  Throws:
    `IOException`

### maxDoc

    public int maxDoc()

### deleteAll

    public void deleteAll()
                   throws IOException

  Throws:
    `IOException`

### setDoRandomOptimize

    public void setDoRandomOptimize(boolean v)

### setDoRandomOptimizeAssert

    public void setDoRandomOptimizeAssert(boolean v)

### getReader

    public org.apache.lucene.index.IndexReader getReader()
                                                  throws IOException

  Throws:
    `IOException`

### getReader

    public org.apache.lucene.index.IndexReader getReader(boolean applyDeletions)
                                                  throws IOException

  Throws:
    `IOException`

### close

    public void close()
               throws IOException

  Close this writer.

  Specified by:
    `close` in interface `Closeable`
  Throws:
    `IOException`
  See Also:
    `IndexWriter.close()`

### optimize

    public void optimize()
                  throws IOException

  Forces an optimize.

  NOTE: this should be avoided in tests unless absolutely necessary, as it will result in less test coverage.

  Throws:
    `IOException`
  See Also:
    `IndexWriter.optimize()`

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.