Class 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.
    • 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)
        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 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 class FilterMergePolicy
        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 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:
        java.io.IOException
        See Also:
        IndexWriter.softUpdateDocument(Term, Iterable, Field...), IndexWriterConfig.setSoftDeletesField(String)