Package 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
ThisMergePolicy
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.
-
-
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 Modifier and Type Field Description private java.lang.String
field
private java.util.function.Supplier<Query>
retentionQuerySupplier
-
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 Description SoftDeletesRetentionMergePolicy(java.lang.String field, java.util.function.Supplier<Query> retentionQuerySupplier, MergePolicy in)
Creates a newSoftDeletesRetentionMergePolicy
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static CodecReader
applyRetentionQuery(java.lang.String softDeleteField, Query retentionQuery, CodecReader reader)
private static Scorer
getScorer(Query query, CodecReader reader)
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, 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
-
-
-
-
Field Detail
-
field
private final java.lang.String field
-
retentionQuerySupplier
private final java.util.function.Supplier<Query> retentionQuerySupplier
-
-
Constructor Detail
-
SoftDeletesRetentionMergePolicy
public SoftDeletesRetentionMergePolicy(java.lang.String field, java.util.function.Supplier<Query> retentionQuerySupplier, MergePolicy in)
Creates a newSoftDeletesRetentionMergePolicy
- Parameters:
field
- the soft deletes fieldretentionQuerySupplier
- a query supplier for the retention queryin
- the wrapped MergePolicy
-
-
Method Detail
-
keepFullyDeletedSegment
public boolean keepFullyDeletedSegment(IOSupplier<CodecReader> readerIOSupplier) throws java.io.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 classFilterMergePolicy
- Throws:
java.io.IOException
-
applyRetentionQuery
static CodecReader applyRetentionQuery(java.lang.String softDeleteField, Query retentionQuery, CodecReader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
getScorer
private static Scorer getScorer(Query query, CodecReader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
numDeletesToMerge
public int numDeletesToMerge(SegmentCommitInfo info, int delCount, IOSupplier<CodecReader> readerSupplier) throws java.io.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 classFilterMergePolicy
- Parameters:
info
- the segment info that identifies the segmentdelCount
- the number deleted documents for this segmentreaderSupplier
- a supplier that allows to obtain aCodecReader
for this segment- Throws:
java.io.IOException
- See Also:
IndexWriter.softUpdateDocument(Term, Iterable, Field...)
,IndexWriterConfig.setSoftDeletesField(String)
-
-