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 IndexWriter
w
-
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 void
addDocument(Document doc)
Adds a Document.void
addDocuments(Collection<Document> docs)
void
addIndexes(IndexReader... readers)
void
addIndexes(Directory... dirs)
void
close()
Close this writer.void
commit()
void
deleteAll()
void
deleteDocuments(Term term)
void
deleteDocuments(Query q)
void
forceMerge(int maxSegmentCount)
Forces a forceMerge.void
forceMergeDeletes()
void
forceMergeDeletes(boolean doWait)
IndexReader
getReader()
IndexReader
getReader(boolean applyDeletions)
int
maxDoc()
int
numDocs()
void
setDoRandomForceMerge(boolean v)
void
setDoRandomForceMergeAssert(boolean v)
void
updateDocument(Term t, Document doc)
Updates a document.void
updateDocuments(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:
CorruptIndexException
IOException
-
addIndexes
public void addIndexes(IndexReader... readers) throws CorruptIndexException, IOException
- Throws:
CorruptIndexException
IOException
-
deleteDocuments
public void deleteDocuments(Term term) throws CorruptIndexException, IOException
- Throws:
CorruptIndexException
IOException
-
deleteDocuments
public void deleteDocuments(Query q) throws CorruptIndexException, IOException
- Throws:
CorruptIndexException
IOException
-
commit
public void commit() throws CorruptIndexException, IOException
- Throws:
CorruptIndexException
IOException
-
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 IOException
Close this writer.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- See Also:
IndexWriter.close()
-
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)
-
-