MergePolicy.OneMerge (Lucene 10.5.1 core API)
Description: declaration: package: org.apache.lucene.index, class: MergePolicy, class: OneMerge

Package org.apache.lucene.index

# Class MergePolicy.OneMerge

java.lang.Object
org.apache.lucene.index.MergePolicy.OneMerge

Enclosing class:
  `MergePolicy`

public static class MergePolicy.OneMerge extends Object
OneMerge provides the information necessary to perform an individual primitive merge operation, resulting in a single new segment. The merge spec includes the subset of segments to be merged as well as whether the new segment should use the compound file format.

WARNING: This API is experimental and might change in incompatible ways in the next release.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `long`
  `estimatedMergeBytes`
  Estimated size in bytes of the merged segment.
  `final List<SegmentCommitInfo>`
  `segments`
  Segments to be merged.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  ``
  `OneMerge(List<SegmentCommitInfo> segments)`
  Sole constructor.
  ``
  `OneMerge(CodecReader... codecReaders)`
  Create a OneMerge directly from CodecReaders.
  `protected`
  `OneMerge(MergePolicy.OneMerge oneMerge)`
  Constructor for wrapping.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `checkAborted()`
  Checks if merge has been aborted and throws a merge exception if so.
  `SegmentCommitInfo`
  `getMergeInfo()`
  Returns the `SegmentCommitInfo` for the merged segment, or null if it hasn't been set yet.
  `MergePolicy.OneMergeProgress`
  `getMergeProgress()`
  Returns a `MergePolicy.OneMergeProgress` instance for this merge, which provides statistics of the merge threads (run time vs.
  `MergeInfo`
  `getStoreMergeInfo()`
  Return `MergeInfo` describing this merge.
  `boolean`
  `isAborted()`
  Returns true if this merge was or should be aborted.
  `void`
  `mergeFinished(boolean success, boolean segmentDropped)`
  Called by `IndexWriter` after the merge is done and all readers have been closed.
  `void`
  `mergeInit()`
  Called by `IndexWriter` after the merge started and from the thread that will be executing the merge.
  `Sorter.DocMap`
  `reorder(CodecReader reader, Directory dir, Executor executor)`
  Extend this method if you wish to renumber doc IDs.
  `String`
  `segString()`
  Returns a readable description of the current merge state.
  `void`
  `setAborted()`
  Marks this merge as aborted.
  `void`
  `setMergeInfo(SegmentCommitInfo info)`
  Expert: Sets the `SegmentCommitInfo` of the merged segment.
  `long`
  `totalBytesSize()`
  Returns the total size in bytes of this merge.
  `int`
  `totalNumDocs()`
  Returns the total number of documents that are included with this merge.
  `CodecReader`
  `wrapForMerge(CodecReader reader)`
  Wrap a reader prior to merging in order to add/remove fields or documents.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### estimatedMergeBytes

    public volatile long estimatedMergeBytes
    Estimated size in bytes of the merged segment.

  - ### segments

    public final List<SegmentCommitInfo> segments
    Segments to be merged.

- ## Constructor Details

  - ### OneMerge

    public OneMerge(List<SegmentCommitInfo> segments)
    Sole constructor.
    Parameters:
      `segments` - List of `SegmentCommitInfo`s to be merged.

  - ### OneMerge

    public OneMerge(CodecReader... codecReaders)
    Create a OneMerge directly from CodecReaders. Used to merge incoming readers in `IndexWriter.addIndexes(CodecReader...)`. This OneMerge works directly on readers and has an empty segments list.
    Parameters:
      `codecReaders` - Codec readers to merge

  - ### OneMerge

    protected OneMerge(MergePolicy.OneMerge oneMerge)
    Constructor for wrapping.

- ## Method Details

  - ### mergeInit

    public void mergeInit() throws IOException
    Called by `IndexWriter` after the merge started and from the thread that will be executing the merge.
    Throws:
      `IOException`

  - ### mergeFinished

    public void mergeFinished(boolean success, boolean segmentDropped) throws IOException
    Called by `IndexWriter` after the merge is done and all readers have been closed.
    Parameters:
      `success` - true iff the merge finished successfully i.e. was committed
      `segmentDropped` - true iff the merged segment was dropped since it was fully deleted
    Throws:
      `IOException`

  - ### wrapForMerge

    public CodecReader wrapForMerge(CodecReader reader) throws IOException
    Wrap a reader prior to merging in order to add/remove fields or documents.

    NOTE: It is illegal to reorder doc IDs here, use `reorder(CodecReader,Directory,Executor)` instead.

    Throws:
      `IOException`

  - ### reorder

    public Sorter.DocMap reorder(CodecReader reader, Directory dir, Executor executor) throws IOException
    Extend this method if you wish to renumber doc IDs. This method will be called when index sorting is disabled on a merged view of the `MergePolicy.OneMerge`. A `null` return value indicates that doc IDs should not be reordered.

    NOTE: Returning a non-null value here disables several optimizations and increases the merging overhead.

    Parameters:
      `reader` - The reader to reorder.
      `dir` - The `Directory` of the index, which may be used to create temporary files.
      `executor` - An executor that can be used to parallelize the reordering logic. May be `null` if no concurrency is supported.
    Throws:
      `IOException`
    WARNING: This API is experimental and might change in incompatible ways in the next release.

  - ### setMergeInfo

    public void setMergeInfo(SegmentCommitInfo info)
    Expert: Sets the `SegmentCommitInfo` of the merged segment. Allows sub-classes to e.g. `add diagnostic` properties.

  - ### getMergeInfo

    public SegmentCommitInfo getMergeInfo()
    Returns the `SegmentCommitInfo` for the merged segment, or null if it hasn't been set yet.

  - ### segString

    public String segString()
    Returns a readable description of the current merge state.

  - ### totalBytesSize

    public long totalBytesSize()
    Returns the total size in bytes of this merge. Note that this does not indicate the size of the merged segment, but the input total size. This is only set once the merge is initialized by IndexWriter.

  - ### totalNumDocs

    public int totalNumDocs()
    Returns the total number of documents that are included with this merge. Note that this does not indicate the number of documents after the merge.

  - ### getStoreMergeInfo

    public MergeInfo getStoreMergeInfo()
    Return `MergeInfo` describing this merge.

  - ### isAborted

    public boolean isAborted()
    Returns true if this merge was or should be aborted.

  - ### setAborted

    public void setAborted()
    Marks this merge as aborted. The merge thread should terminate at the soonest possible moment.

  - ### checkAborted

    public void checkAborted() throws MergePolicy.MergeAbortedException
    Checks if merge has been aborted and throws a merge exception if so.
    Throws:
      `MergePolicy.MergeAbortedException`

  - ### getMergeProgress

    public MergePolicy.OneMergeProgress getMergeProgress()
    Returns a `MergePolicy.OneMergeProgress` instance for this merge, which provides statistics of the merge threads (run time vs. sleep time) if merging is throttled.