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
Modifier and TypeClassDescriptionstatic interface
Simple interface that is executed for eachTP
InfoStream
component message. -
Field Summary
-
Constructor Summary
ConstructorDescriptionRandomIndexWriter
(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.long
addDocuments
(Iterable<? extends Iterable<? extends IndexableField>> docs) long
addIndexes
(CodecReader... readers) long
addIndexes
(Directory... dirs) void
close()
Close this writer.long
commit()
long
commit
(boolean flushConcurrently) long
long
deleteDocuments
(Term term) long
final void
flush()
Writes all in-memory segments to theDirectory
.void
forceMerge
(int maxSegmentCount) Forces a forceMerge.void
void
forceMergeDeletes
(boolean doWait) getReader
(boolean applyDeletions, boolean writeAllDeletes) static IndexWriter
mockIndexWriter
(Random r, Directory dir, IndexWriterConfig conf, RandomIndexWriter.TestPoint testPoint) Returns an indexwriter that enables the specified test pointstatic IndexWriter
mockIndexWriter
(Directory dir, IndexWriterConfig conf, Random r) Returns an indexwriter that randomly mixes up thread scheduling (by yielding at test points)void
setDoRandomForceMerge
(boolean v) void
setDoRandomForceMergeAssert
(boolean v) long
updateBinaryDocValue
(Term term, String field, BytesRef value) <T extends IndexableField>
longupdateDocument
(Term t, Iterable<T> doc) Updates a document.long
updateDocuments
(Term delTerm, Iterable<? extends Iterable<? extends IndexableField>> docs) long
updateDocValues
(Term term, Field... updates) long
updateNumericDocValue
(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:
close
in interfaceAutoCloseable
- Specified by:
close
in 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
-