org.apache.lucene.index

## Class SoftDeletesRetentionMergePolicy

- java.lang.Object
- - org.apache.lucene.index.MergePolicy
  - - org.apache.lucene.index.FilterMergePolicy
    - - org.apache.lucene.index.OneMergeWrappingMergePolicy
      - - org.apache.lucene.index.SoftDeletesRetentionMergePolicy

    public final class SoftDeletesRetentionMergePolicy
    extends OneMergeWrappingMergePolicy

This `MergePolicy` allows to carry over soft deleted documents across merges. The policy wraps the merge reader and marks documents as "live" that have a value in the soft delete field and match the provided query. This allows for instance to keep documents alive based on time or any other constraint in the index. The main purpose for this merge policy is to implement retention policies for document modification to vanish in the index. Using this merge policy allows to control when soft deletes are claimed by merges.

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

### Nested Class Summary

### Nested classes/interfaces inherited from class org.apache.lucene.index.MergePolicy

`MergePolicy.MergeAbortedException, MergePolicy.MergeContext, MergePolicy.MergeException, MergePolicy.MergeSpecification, MergePolicy.OneMerge, MergePolicy.OneMergeProgress`

### Field Summary

### Fields inherited from class org.apache.lucene.index.FilterMergePolicy

`in`

### Fields inherited from class org.apache.lucene.index.MergePolicy

`DEFAULT_MAX_CFS_SEGMENT_SIZE, DEFAULT_NO_CFS_RATIO, maxCFSSegmentSize, noCFSRatio`

### Constructor Summary

Constructors
Constructor and Description
`SoftDeletesRetentionMergePolicy(String field, Supplier<Query> retentionQuerySupplier, MergePolicy in)` Creates a new `SoftDeletesRetentionMergePolicy`

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `keepFullyDeletedSegment(IOSupplier<CodecReader> readerIOSupplier)` Returns true if the segment represented by the given CodecReader should be keep even if it's fully deleted.
`int` `numDeletesToMerge(SegmentCommitInfo info, int delCount, IOSupplier<CodecReader> readerSupplier)` Returns the number of deletes that a merge would claim on the given segment.

### Methods inherited from class org.apache.lucene.index.OneMergeWrappingMergePolicy

`findForcedDeletesMerges, findForcedMerges, findFullFlushMerges, findMerges`

### Methods inherited from class org.apache.lucene.index.FilterMergePolicy

`getMaxCFSSegmentSizeMB, getNoCFSRatio, setMaxCFSSegmentSizeMB, setNoCFSRatio, size, toString, useCompoundFile`

### Methods inherited from class org.apache.lucene.index.MergePolicy

`assertDelCount, isMerged, message, segString, verbose`

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

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

### Constructor Detail

#### SoftDeletesRetentionMergePolicy

    public SoftDeletesRetentionMergePolicy(String field,
                                           Supplier<Query> retentionQuerySupplier,
                                           MergePolicy in)

Creates a new `SoftDeletesRetentionMergePolicy`

Parameters:
  `field` - the soft deletes field
  `retentionQuerySupplier` - a query supplier for the retention query
  `in` - the wrapped MergePolicy

### Method Detail

#### keepFullyDeletedSegment

    public boolean keepFullyDeletedSegment(IOSupplier<CodecReader> readerIOSupplier)
                                    throws IOException

Description copied from class: `MergePolicy`
Returns true if the segment represented by the given CodecReader should be keep even if it's fully deleted. This is useful for testing of for instance if the merge policy implements retention policies for soft deletes.

Overrides:
  `keepFullyDeletedSegment` in class `FilterMergePolicy`
Throws:
  `IOException`

#### numDeletesToMerge

    public int numDeletesToMerge(SegmentCommitInfo info,
                                 int delCount,
                                 IOSupplier<CodecReader> readerSupplier)
                          throws IOException

Description copied from class: `MergePolicy`
Returns the number of deletes that a merge would claim on the given segment. This method will by default return the sum of the del count on disk and the pending delete count. Yet, subclasses that wrap merge readers might modify this to reflect deletes that are carried over to the target segment in the case of soft deletes. Soft deletes all deletes to survive across merges in order to control when the soft-deleted data is claimed.

Overrides:
  `numDeletesToMerge` in class `FilterMergePolicy`
Parameters:
  `info` - the segment info that identifies the segment
  `delCount` - the number deleted documents for this segment
  `readerSupplier` - a supplier that allows to obtain a `CodecReader` for this segment
Throws:
  `IOException`
See Also:
  `IndexWriter.softUpdateDocument(Term, Iterable, Field...)`, `IndexWriterConfig.setSoftDeletesField(String)`