Package org.apache.lucene.tests.index
Class RandomIndexWriter
java.lang.Object
org.apache.lucene.tests.index.RandomIndexWriter
- All Implemented Interfaces:
Closeable,AutoCloseable
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 ClassesModifier and TypeClassDescriptionstatic interfaceSimple interface that is executed for eachTPInfoStreamcomponent message. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRandomIndexWriter(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
Modifier and TypeMethodDescription<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) longlongdeleteDocuments(Term term) longfinal voidflush()Writes all in-memory segments to theDirectory.voidforceMerge(int maxSegmentCount) Forces a forceMerge.voidvoidforceMergeDeletes(boolean doWait) getReader(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 Details
-
w
-
-
Constructor Details
-
RandomIndexWriter
create a RandomIndexWriter with a random config: Uses MockAnalyzer- Throws:
IOException
-
RandomIndexWriter
create a RandomIndexWriter with a random config- Throws:
IOException
-
RandomIndexWriter
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 Details
-
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
Adds a Document.- Throws:
IOException- See Also:
-
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
Updates a document.- Throws:
IOException- See Also:
-
addIndexes
- Throws:
IOException
-
addIndexes
- Throws:
IOException
-
updateNumericDocValue
- Throws:
IOException
-
updateBinaryDocValue
- Throws:
IOException
-
updateDocValues
- Throws:
IOException
-
deleteDocuments
- Throws:
IOException
-
deleteDocuments
- Throws:
IOException
-
commit
- Throws:
IOException
-
commit
- Throws:
IOException
-
getDocStats
-
deleteAll
- Throws:
IOException
-
getReader
- Throws:
IOException
-
forceMergeDeletes
- Throws:
IOException
-
forceMergeDeletes
- 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
Close this writer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- See Also:
-
forceMerge
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:
-
flush
Writes all in-memory segments to theDirectory.- Throws:
IOException
-