Package org.apache.lucene.tests.index
Class RandomIndexWriter
- java.lang.Object
-
- org.apache.lucene.tests.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRandomIndexWriter.TestPointSimple interface that is executed for eachTPInfoStreamcomponent message.
-
Field Summary
Fields Modifier and Type Field Description IndexWriterw
-
Constructor Summary
Constructors Constructor Description RandomIndexWriter(Random r, Directory dir)create a RandomIndexWriter with a random config: Uses MockAnalyzerRandomIndexWriter(Random r, Directory dir, Analyzer a)create a RandomIndexWriter with a random configRandomIndexWriter(Random r, Directory dir, IndexWriterConfig c)create a RandomIndexWriter with the provided configRandomIndexWriter(Random r, Directory dir, IndexWriterConfig c, boolean useSoftDeletes)create a RandomIndexWriter with the provided config
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends IndexableField>
longaddDocument(Iterable<T> doc)Adds a Document.longaddDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs)longaddIndexes(CodecReader... readers)longaddIndexes(Directory... dirs)voidclose()Close this writer.longcommit()longcommit(boolean flushConcurrently)longdeleteAll()longdeleteDocuments(Term term)longdeleteDocuments(Query q)voidflush()Writes all in-memory segments to theDirectory.voidforceMerge(int maxSegmentCount)Forces a forceMerge.voidforceMergeDeletes()voidforceMergeDeletes(boolean doWait)IndexWriter.DocStatsgetDocStats()DirectoryReadergetReader()DirectoryReadergetReader(boolean applyDeletions, boolean writeAllDeletes)static IndexWritermockIndexWriter(Random r, Directory dir, IndexWriterConfig conf, RandomIndexWriter.TestPoint testPoint)Returns an indexwriter that enables the specified test pointstatic IndexWritermockIndexWriter(Directory dir, IndexWriterConfig conf, Random r)Returns an indexwriter that randomly mixes up thread scheduling (by yielding at test points)voidsetDoRandomForceMerge(boolean v)voidsetDoRandomForceMergeAssert(boolean v)longupdateBinaryDocValue(Term term, String field, BytesRef value)<T extends IndexableField>
longupdateDocument(Term t, Iterable<T> doc)Updates a document.longupdateDocuments(Term delTerm, Iterable<? extends Iterable<? extends IndexableField>> docs)longupdateDocValues(Term term, Field... updates)longupdateNumericDocValue(Term term, String field, Long value)
-
-
-
Field Detail
-
w
public final IndexWriter w
-
-
Constructor Detail
-
RandomIndexWriter
public RandomIndexWriter(Random r, Directory dir) throws IOException
create a RandomIndexWriter with a random config: Uses MockAnalyzer- Throws:
IOException
-
RandomIndexWriter
public RandomIndexWriter(Random r, Directory dir, 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
-
RandomIndexWriter
public RandomIndexWriter(Random r, Directory dir, IndexWriterConfig c, boolean useSoftDeletes) throws IOException
create a RandomIndexWriter with the provided config- Throws:
IOException
-
-
Method Detail
-
mockIndexWriter
public static IndexWriter mockIndexWriter(Directory dir, IndexWriterConfig conf, Random r) throws IOException
Returns an indexwriter that randomly mixes up thread scheduling (by yielding at test points)- Throws:
IOException
-
mockIndexWriter
public static IndexWriter mockIndexWriter(Random r, Directory dir, IndexWriterConfig conf, RandomIndexWriter.TestPoint testPoint) throws IOException
Returns an indexwriter that enables the specified test point- Throws:
IOException
-
addDocument
public <T extends IndexableField> long addDocument(Iterable<T> doc) throws IOException
Adds a Document.- Throws:
IOException- See Also:
IndexWriter.addDocument(Iterable)
-
addDocuments
public long addDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs) throws IOException
- Throws:
IOException
-
updateDocuments
public long updateDocuments(Term delTerm, Iterable<? extends Iterable<? extends IndexableField>> docs) throws IOException
- Throws:
IOException
-
updateDocument
public <T extends IndexableField> long updateDocument(Term t, Iterable<T> doc) throws IOException
Updates a document.- Throws:
IOException- See Also:
IndexWriter.updateDocument(Term, Iterable)
-
addIndexes
public long addIndexes(Directory... dirs) throws IOException
- Throws:
IOException
-
addIndexes
public long addIndexes(CodecReader... readers) throws IOException
- Throws:
IOException
-
updateNumericDocValue
public long updateNumericDocValue(Term term, String field, Long value) throws IOException
- Throws:
IOException
-
updateBinaryDocValue
public long updateBinaryDocValue(Term term, String field, BytesRef value) throws IOException
- Throws:
IOException
-
updateDocValues
public long updateDocValues(Term term, Field... updates) throws IOException
- Throws:
IOException
-
deleteDocuments
public long deleteDocuments(Term term) throws IOException
- Throws:
IOException
-
deleteDocuments
public long deleteDocuments(Query q) throws IOException
- Throws:
IOException
-
commit
public long commit() throws IOException- Throws:
IOException
-
commit
public long commit(boolean flushConcurrently) throws IOException- Throws:
IOException
-
getDocStats
public IndexWriter.DocStats getDocStats()
-
deleteAll
public long 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, boolean writeAllDeletes) throws IOException
- Throws:
IOException
-
close
public void close() throws IOExceptionClose this writer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- See Also:
IndexWriter.close()
-
forceMerge
public void forceMerge(int maxSegmentCount) throws IOExceptionForces 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)
-
flush
public final void flush() throws IOExceptionWrites all in-memory segments to theDirectory.- Throws:
IOException
-
-