@@ -26,7 +26,7 @@ pub struct DeleteDocuments<'t, 'u, 'i> {
2626 index : & ' i Index ,
2727 external_documents_ids : ExternalDocumentsIds < ' static > ,
2828 to_delete_docids : RoaringBitmap ,
29- disable_soft_deletion : bool ,
29+ strategy : DeletionStrategy ,
3030}
3131
3232/// Result of a [`DeleteDocuments`] operation.
@@ -36,6 +36,36 @@ pub struct DocumentDeletionResult {
3636 pub remaining_documents : u64 ,
3737}
3838
39+ /// Strategy for deleting documents.
40+ ///
41+ /// - Soft-deleted documents are simply marked as deleted without being actually removed from DB.
42+ /// - Hard-deleted documents are definitely suppressed from the DB.
43+ ///
44+ /// Soft-deleted documents trade disk space for runtime performance.
45+ ///
46+ /// Note that any of these variants can be used at any given moment for any indexation in a database.
47+ /// For instance, you can use an [`AlwaysSoft`] followed by an [`AlwaysHard`] option without issue.
48+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , Default ) ]
49+ pub enum DeletionStrategy {
50+ #[ default]
51+ /// Definitely suppress documents according to the number of size of soft-deleted documents
52+ Dynamic ,
53+ /// Never definitely suppress documents
54+ AlwaysSoft ,
55+ /// Always definitely suppress documents
56+ AlwaysHard ,
57+ }
58+
59+ impl std:: fmt:: Display for DeletionStrategy {
60+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
61+ match self {
62+ DeletionStrategy :: Dynamic => write ! ( f, "dynamic" ) ,
63+ DeletionStrategy :: AlwaysSoft => write ! ( f, "always_soft" ) ,
64+ DeletionStrategy :: AlwaysHard => write ! ( f, "always_hard" ) ,
65+ }
66+ }
67+ }
68+
3969/// Result of a [`DeleteDocuments`] operation, used for internal purposes.
4070///
4171/// It is a superset of the [`DocumentDeletionResult`] structure, giving
@@ -59,12 +89,12 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
5989 index,
6090 external_documents_ids,
6191 to_delete_docids : RoaringBitmap :: new ( ) ,
62- disable_soft_deletion : false ,
92+ strategy : Default :: default ( ) ,
6393 } )
6494 }
6595
66- pub fn disable_soft_deletion ( & mut self , disable : bool ) {
67- self . disable_soft_deletion = disable ;
96+ pub fn strategy ( & mut self , strategy : DeletionStrategy ) {
97+ self . strategy = strategy ;
6898 }
6999
70100 pub fn delete_document ( & mut self , docid : u32 ) {
0 commit comments