This is a horribly costly operation, especially when you pass a small {@code maxNumSegments}; usually you should only call this if the index is static (will no longer be changed).
Note that this requires up to 2X the index size free space in your Directory (3X if you're using compound file format). For example, if your index size is 10 MB then you need up to 20 MB free for this to complete (30 MB if you're using compound file format). Also, it's best to call {@link #commit()} afterwards,to allow IndexWriter to free up disk space.
If some but not all readers re-open while merging is underway, this will cause > 2X temporary space to be consumed as those new readers will then hold open the temporary segments at that time. It is best not to re-open readers while merging is running.
The actual temporary usage could be much less than these figures (it depends on many factors).
In general, once the this completes, the total size of the index will be less than the size of the starting index. It could be quite a bit smaller (if there were many pending deletes) or just slightly smaller.
If an Exception is hit, for example due to disk full, the index will not be corrupt and no documents will have been lost. However, it may have been partially merged (some segments were merged but not all), and it's possible that one of the segments in the index will be in non-compound format even when using compound file format. This will occur when the Exception is hit during conversion of the segment into compound format.
This call will merge those segments present in the index when the call started. If other threads are still adding documents and flushing segments, those newly created segments will not be merged unless you call forceMerge again.
NOTE: if this method hits an OutOfMemoryError you should immediately close the writer. See above for details.
NOTE: if you call {@link #close(boolean)}with false, which aborts all running merges, then any thread still running this method might hit a {@link MergePolicy.MergeAbortedException}. @throws CorruptIndexException if the index is corrupt @throws IOException if there is a low-level IO error @see MergePolicy#findMerges @param maxNumSegments maximum number of segments leftin the index after merging finishes
NOTE: this should be avoided in tests unless absolutely necessary, as it will result in less test coverage. @see IndexWriter#forceMerge(int)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|