org.apache.lucene.index

## Class RandomIndexWriter

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

- All Implemented Interfaces:
    Closeable, AutoCloseable

      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 forceMerge in the end, may flush by doc count instead of RAM, etc.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `IndexWriter` | `w`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RandomIndexWriter(Random r, Directory dir)` create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENT and MockAnalyzer
    `RandomIndexWriter(Random r, Directory dir, Analyzer a)` create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENT
    `RandomIndexWriter(Random r, Directory dir, IndexWriterConfig c)` create a RandomIndexWriter with the provided config
    `RandomIndexWriter(Random r, Directory dir, Version v, Analyzer a)` create a RandomIndexWriter with a random config

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T extends IndexableField> void` | `addDocument(Iterable<T> doc)` Adds a Document.
    `<T extends IndexableField> void` | `addDocument(Iterable<T> doc, Analyzer a)`
    `void` | `addDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs)`
    `void` | `addIndexes(Directory... dirs)`
    `void` | `addIndexes(IndexReader... readers)`
    `void` | `close()` Close this writer.
    `void` | `commit()`
    `void` | `deleteAll()`
    `void` | `deleteDocuments(Query q)`
    `void` | `deleteDocuments(Term term)`
    `void` | `forceMerge(int maxSegmentCount)` Forces a forceMerge.
    `void` | `forceMergeDeletes()`
    `void` | `forceMergeDeletes(boolean doWait)`
    `DirectoryReader` | `getReader()`
    `DirectoryReader` | `getReader(boolean applyDeletions)`
    `int` | `maxDoc()`
    `int` | `numDocs()`
    `void` | `setDoRandomForceMerge(boolean v)`
    `void` | `setDoRandomForceMergeAssert(boolean v)`
    `<T extends IndexableField> void` | `updateDocument(Term t, Iterable<T> doc)` Updates a document.
    `void` | `updateDocuments(Term delTerm, Iterable<? extends Iterable<? extends IndexableField>> docs)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### w

          public IndexWriter w

  - ### Constructor Detail

    - #### RandomIndexWriter

          public RandomIndexWriter(Random r,
                           Directory dir)
                            throws IOException

      create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENT and MockAnalyzer
      Throws:
        `IOException`

    - #### RandomIndexWriter

          public RandomIndexWriter(Random r,
                           Directory dir,
                           Analyzer a)
                            throws IOException

      create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENT
      Throws:
        `IOException`

    - #### RandomIndexWriter

          public RandomIndexWriter(Random r,
                           Directory dir,
                           Version v,
                           Analyzer a)
                            throws IOException

      create a RandomIndexWriter with a random config
      Throws:
        `IOException`

    - #### RandomIndexWriter

          public RandomIndexWriter(Random r,
                           Directory dir,
                           IndexWriterConfig c)
                            throws IOException

      create a RandomIndexWriter with the provided config
      Throws:
        `IOException`

  - ### Method Detail

    - #### addDocument

          public <T extends IndexableField> void addDocument(Iterable<T> doc)
                           throws IOException

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

    - #### addDocument

          public <T extends IndexableField> void addDocument(Iterable<T> doc,
                                                    Analyzer a)
                           throws IOException

      Throws:
        `IOException`

    - #### addDocuments

          public void addDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs)
                            throws IOException

      Throws:
        `IOException`

    - #### updateDocuments

          public void updateDocuments(Term delTerm,
                             Iterable<? extends Iterable<? extends IndexableField>> docs)
                               throws IOException

      Throws:
        `IOException`

    - #### updateDocument

          public <T extends IndexableField> void updateDocument(Term t,
                                                       Iterable<T> doc)
                              throws IOException

      Updates a document.
      Throws:
        `IOException`
      See Also:
        `IndexWriter.updateDocument(Term, Iterable)`

    - #### addIndexes

          public void addIndexes(Directory... dirs)
                          throws IOException

      Throws:
        `IOException`

    - #### addIndexes

          public void addIndexes(IndexReader... readers)
                          throws IOException

      Throws:
        `IOException`

    - #### deleteDocuments

          public void deleteDocuments(Term term)
                               throws IOException

      Throws:
        `IOException`

    - #### deleteDocuments

          public void deleteDocuments(Query q)
                               throws IOException

      Throws:
        `IOException`

    - #### commit

          public void commit()
                      throws IOException

      Throws:
        `IOException`

    - #### numDocs

          public int numDocs()

    - #### maxDoc

          public int maxDoc()

    - #### deleteAll

          public void deleteAll()
                         throws IOException

      Throws:
        `IOException`

    - #### getReader

          public DirectoryReader getReader()
                                    throws IOException

      Throws:
        `IOException`

    - #### forceMergeDeletes

          public void forceMergeDeletes(boolean doWait)
                                 throws IOException

      Throws:
        `IOException`

    - #### forceMergeDeletes

          public void forceMergeDeletes()
                                 throws IOException

      Throws:
        `IOException`

    - #### setDoRandomForceMerge

          public void setDoRandomForceMerge(boolean v)

    - #### setDoRandomForceMergeAssert

          public void setDoRandomForceMergeAssert(boolean v)

    - #### getReader

          public DirectoryReader getReader(boolean applyDeletions)
                                    throws IOException

      Throws:
        `IOException`

    - #### close

          public void close()
                     throws IOException

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

    - #### forceMerge

          public void forceMerge(int maxSegmentCount)
                          throws IOException

      Forces a forceMerge.

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

      Throws:
        `IOException`
      See Also:
        `IndexWriter.forceMerge(int)`

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