Package 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 Description IndexWriterw
-
Constructor Summary
Constructors Constructor Description RandomIndexWriter(Random r, Directory dir)create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENT and Whitespace+LowercasingAnalyzerRandomIndexWriter(Random r, Directory dir, Analyzer a)create a RandomIndexWriter with a random config: Uses TEST_VERSION_CURRENTRandomIndexWriter(Random r, Directory dir, IndexWriterConfig c)create a RandomIndexWriter with the provided configRandomIndexWriter(Random r, Directory dir, Version v, Analyzer a)create a RandomIndexWriter with a random config
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDocument(Document doc)Adds a Document.voidaddDocuments(Collection<Document> docs)voidaddIndexes(IndexReader... readers)voidaddIndexes(Directory... dirs)voidclose()Close this writer.voidcommit()voiddeleteAll()voiddeleteDocuments(Term term)voiddeleteDocuments(Query q)voidforceMerge(int maxSegmentCount)Forces a forceMerge.voidforceMergeDeletes()voidforceMergeDeletes(boolean doWait)IndexReadergetReader()IndexReadergetReader(boolean applyDeletions)intmaxDoc()intnumDocs()voidsetDoRandomForceMerge(boolean v)voidsetDoRandomForceMergeAssert(boolean v)voidupdateDocument(Term t, Document doc)Updates a document.voidupdateDocuments(Term delTerm, Collection<Document> docs)
-
-
-
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 Whitespace+LowercasingAnalyzer- 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 void addDocument(Document doc) throws IOException
Adds a Document.- Throws:
IOException- See Also:
IndexWriter.addDocument(Document)
-
addDocuments
public void addDocuments(Collection<Document> docs) throws IOException
- Throws:
IOException
-
updateDocuments
public void updateDocuments(Term delTerm, Collection<Document> docs) throws IOException
- Throws:
IOException
-
updateDocument
public void updateDocument(Term t, Document doc) throws IOException
Updates a document.- Throws:
IOException- See Also:
IndexWriter.updateDocument(Term, Document)
-
addIndexes
public void addIndexes(Directory... dirs) throws CorruptIndexException, IOException
- Throws:
CorruptIndexExceptionIOException
-
addIndexes
public void addIndexes(IndexReader... readers) throws CorruptIndexException, IOException
- Throws:
CorruptIndexExceptionIOException
-
deleteDocuments
public void deleteDocuments(Term term) throws CorruptIndexException, IOException
- Throws:
CorruptIndexExceptionIOException
-
deleteDocuments
public void deleteDocuments(Query q) throws CorruptIndexException, IOException
- Throws:
CorruptIndexExceptionIOException
-
commit
public void commit() throws CorruptIndexException, IOException- Throws:
CorruptIndexExceptionIOException
-
numDocs
public int numDocs() throws IOException- Throws:
IOException
-
maxDoc
public int maxDoc()
-
deleteAll
public void deleteAll() 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 IndexReader getReader() throws IOException
- Throws:
IOException
-
getReader
public IndexReader getReader(boolean applyDeletions) 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)
-
-