Class 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 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)
      • 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
      • addIndexes

        public void addIndexes​(org.apache.lucene.index.IndexReader... readers)
                        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
      • maxDoc

        public int maxDoc()
      • forceMergeDeletes

        public void forceMergeDeletes​(boolean doWait)
                               throws IOException
        Throws:
        IOException
      • setDoRandomForceMerge

        public void setDoRandomForceMerge​(boolean v)
      • setDoRandomForceMergeAssert

        public void setDoRandomForceMergeAssert​(boolean v)
      • getReader

        public org.apache.lucene.index.IndexReader getReader​(boolean applyDeletions)
                                                      throws IOException
        Throws:
        IOException
      • 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)