rlucene 0.1.0-alpha.3

A Rust port of Apache Lucene, a full-text search engine library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
use crate::core::codecs::live_docs_format::LiveDocsFormat;
use crate::core::codecs::{Codec, CodecLiveDocsBits};
use crate::core::index::codec_reader::CodecReader;
use crate::core::index::doc_values_field_updates::{DocValuesFieldIteratorEnum, MergedIterator};
use crate::core::index::field_info::FieldInfo;
use crate::core::index::field_infos::FieldInfos;
use crate::core::index::index_reader::{Identity, IndexReader};
use crate::core::index::leaf_reader::LeafReader;
use crate::core::index::pending_soft_deletes::PendingSoftDeletes;
use crate::core::index::segment_commit_info::SegmentCommitInfo;
use crate::core::index::segment_reader::{DefaultLeafReader, SegmentReader};
use crate::core::store::IO_CONTEXT_DEFAULT;

use crate::core::store::directory::Directory;
use crate::core::store::tracking_directory_wrapper::TrackingDirectoryWrapper;
use crate::core::util::bits::Bits;
use crate::core::util::error::lucene_error::{LuceneError, Result};
use crate::core::util::fixed_bit_set::FixedBitSet;
use crate::core::util::{HasIdentity, IOUtils};
use std::fmt;
use std::fmt::{Display, Formatter};
use std::sync::Arc;

pub(crate) type DocBits = Arc<CodecLiveDocsBits>;

enum LiveDocsState {
  // Read-only live docs.
  ReadOnly(DocBits),
  // Writable live docs.
  Writable(FixedBitSet),
}

impl HasIdentity for LiveDocsState {
  fn identity(&self) -> &Identity {
    match self {
      Self::ReadOnly(bits) => bits.identity(),
      Self::Writable(bits) => bits.identity(),
    }
  }
}

impl Bits for LiveDocsState {
  fn get(&self, index: usize) -> Result<bool> {
    match self {
      Self::ReadOnly(bits) => bits.get(index),
      Self::Writable(bits) => bits.get(index),
    }
  }

  fn length(&self) -> usize {
    match self {
      Self::ReadOnly(bits) => bits.length(),
      Self::Writable(bits) => bits.length(),
    }
  }

  fn fixed_bit_set(&self) -> Option<&FixedBitSet> {
    match self {
      Self::ReadOnly(bits) => bits.fixed_bit_set(),
      Self::Writable(bits) => Some(bits),
    }
  }

  fn copy_of(&self) -> Result<FixedBitSet> {
    match self {
      Self::ReadOnly(bits) => bits.copy_of(),
      Self::Writable(bits) => bits.copy_of(),
    }
  }
}

/// This struct handles accounting and applies pending deletes for live segment readers.
pub(crate) struct PendingDeletes {
  // SegmentInfo::id
  pub(crate) info_id: Arc<str>,
  live_docs: Option<LiveDocsState>,
  pub(crate) pending_delete_count: i32,
  pub(crate) live_docs_initialized: bool,
  pub(crate) max_doc: i32,
}
impl PendingDeletes {
  pub(crate) fn from_reader<D>(
    reader: &SegmentReader<D>,
    info: &SegmentCommitInfo<D>,
  ) -> Result<Self>
  where
    D: Directory,
  {
    let mut v = Self::with(
      Arc::clone(&reader.original_si_id),
      reader.get_live_docs()?,
      true,
      info.info.max_doc()?,
    );
    v.pending_delete_count = reader.num_deleted_docs()? - info.get_del_count();
    Ok(v)
  }
  pub(crate) fn new<D>(info: &SegmentCommitInfo<D>) -> Result<Self> {
    Ok(PendingDeletes::with(
      Arc::clone(&info.info.id_key),
      None,
      !info.has_deletions(),
      info.info.max_doc()?,
    ))
    // if we don't have deletions we can mark it as initialized since we might receive deletes on a
    // segment
    // without having a reader opened on it ie. after a merge when we apply the deletes that IW
    // received while merging.
    // For segments that were published we enforce a reader in the
    // BufferedUpdatesStream.SegmentState ctor
  }

  pub(crate) fn with(
    info_id: Arc<str>,
    live_docs: Option<DocBits>,
    live_docs_initialized: bool,
    max_doc: i32,
  ) -> Self {
    PendingDeletes {
      info_id,
      live_docs: live_docs.map(LiveDocsState::ReadOnly),
      pending_delete_count: 0,
      live_docs_initialized,
      max_doc,
    }
  }
  pub(crate) fn get_mutable_bits(&mut self) -> Result<&mut FixedBitSet> {
    // If we pull mutable bits but we haven't been initialized something is completely off.
    debug_assert!(
      self.live_docs_initialized,
      "can't delete if liveDocs are not initialized",
    );
    let writable_live_docs = match self.live_docs.as_ref() {
      Some(LiveDocsState::ReadOnly(bits)) => Some(bits.copy_of()?),
      Some(LiveDocsState::Writable(_)) => None,
      None => {
        let max_doc = self.max_doc as usize;
        Some(FixedBitSet::with_set_prefix(max_doc, max_doc))
      },
    };
    if let Some(writable_live_docs) = writable_live_docs {
      self.live_docs = Some(LiveDocsState::Writable(writable_live_docs));
    }
    match self.live_docs.as_mut() {
      Some(LiveDocsState::Writable(bits)) => Ok(bits),
      _ => Err(LuceneError::illegal_state(
        "live_docs should be FixedBitSet",
      )),
    }
  }

  fn assert_check_live_docs<T>(
    &self,
    bits: &T,
    expected_length: i32,
    expected_delete_count: i32,
  ) -> Result<bool>
  where
    T: Bits,
  {
    debug_assert_eq!(
      bits.length(),
      expected_length as usize,
      "length: {} != expected: {}",
      bits.length(),
      expected_length
    );

    let mut deleted = 0;
    for i in 0..bits.length() {
      if !bits.get(i)? {
        deleted += 1;
      }
    }

    debug_assert_eq!(
      deleted, expected_delete_count,
      "deleted: {deleted} != expected: {expected_delete_count}"
    );

    Ok(true)
  }
}
impl PendingDeletesBase for PendingDeletes {
  fn get_info_id(&self) -> &str {
    &self.info_id
  }

  fn delete<D>(&mut self, doc_id: i32, _info: &SegmentCommitInfo<D>) -> Result<bool> {
    debug_assert!(self.max_doc > 0);

    let mutable_bits = self.get_mutable_bits()?;
    let doc_index = doc_id as usize;
    debug_assert!(mutable_bits.length() > 0);

    debug_assert!(
      (0..mutable_bits.length()).contains(&doc_index),
      "out of bounds: docID={} liveDocsLength={} seg={} maxDoc={}",
      doc_id,
      mutable_bits.length(),
      self.info_id,
      self.max_doc
    );

    let did_delete = mutable_bits.get_and_clear(doc_index);
    if did_delete {
      self.pending_delete_count += 1;
    }
    Ok(did_delete)
  }

  fn get_hard_live_docs(&mut self) -> Option<DocBits> {
    self.get_live_docs()
  }

  fn get_live_docs(&mut self) -> Option<DocBits> {
    // Prevent modifications to the returned live docs
    self.live_docs.take().map(|live_docs| {
      let bits = match live_docs {
        LiveDocsState::ReadOnly(bits) => bits,
        LiveDocsState::Writable(bits) => {
          #[cfg(not(test))]
          {
            Arc::new(bits.to_read_only_bits())
          }
          #[cfg(test)]
          {
            Arc::new(CodecLiveDocsBits::Lucene90(bits.to_read_only_bits()))
          }
        },
      };
      self.live_docs = Some(LiveDocsState::ReadOnly(bits.clone()));
      bits
    })
  }

  fn num_pending_deletes(&self) -> i32 {
    self.pending_delete_count
  }

  fn on_new_reader<D>(
    &mut self,
    reader: &SegmentReader<D>,
    info: &SegmentCommitInfo<D>,
  ) -> Result<()>
  where
    D: Directory,
  {
    if !self.live_docs_initialized {
      debug_assert!(!matches!(&self.live_docs, Some(LiveDocsState::Writable(_))));
      if reader.has_deletions()? {
        // we only initialize this once either in the ctor or here
        // if we use the live docs from a reader it has to be in a situation where we don't
        // have any existing live docs
        debug_assert_eq!(
          self.pending_delete_count, 0,
          "pendingDeleteCount: {}",
          self.pending_delete_count
        );
        self.live_docs = reader.get_live_docs()?.map(LiveDocsState::ReadOnly);

        if let Some(bits) = &self.live_docs {
          let max_doc = info.info.max_doc()?;
          let del_count = info.get_del_count();
          debug_assert!(
            self
              .assert_check_live_docs(bits, max_doc, del_count)
              .unwrap_or(false)
          );
        }
      }
      self.live_docs_initialized = true;
    }
    Ok(())
  }
  /// Resets the pending docs
  fn drop_changes(&mut self) {
    self.pending_delete_count = 0;
  }

  fn write_live_docs<D1, D2>(&mut self, dir: D1, info: &mut SegmentCommitInfo<D2>) -> Result<bool>
  where
    D1: Directory,
  {
    if self.pending_delete_count == 0 {
      return Ok(false);
    }

    let live_docs = match self.live_docs.as_ref() {
      Some(ld) => ld,
      None => return Err(LuceneError::illegal_state("liveDocs must be initialized")),
    };
    debug_assert!(info.info.max_doc()? == self.max_doc);
    // We have new deletes
    debug_assert_eq!(
      live_docs.length(),
      info.info.max_doc()? as usize,
      "liveDocs.length must match maxDoc"
    );
    // Do this so we can delete any created files on
    // error; this saves all codecs from having to do
    // it:
    let tracking_dir = TrackingDirectoryWrapper::new(dir);
    // We can write directly to the actual name (vs to a
    // .tmp & renaming it) because the file is not live
    // until segments file is written:
    let mut success = false;
    let write_res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| -> Result<()> {
      let codec = info.info.get_codec()?;
      codec.live_docs_format().write_live_docs(
        live_docs,
        &tracking_dir,
        info,
        self.pending_delete_count,
        IO_CONTEXT_DEFAULT.as_ref().map_err(Clone::clone)?,
      )?;
      success = true;
      Ok(())
    }));

    if !success {
      // Advance only the nextWriteDelGen so that a 2nd
      // attempt to write will write to a new file
      info.advance_next_write_del_gen();
      // Delete any partially created file(s):
      IOUtils::delete_files_ignoring_exceptions(
        &tracking_dir.in_,
        tracking_dir.take_created_files(),
      );
    }
    unwrap_caught_result!(write_res)?;
    // If we hit an exc in the line above (eg disk full)
    // then info's delGen remains pointing to the previous
    // (successfully written) del docs:
    info.advance_del_gen();
    let new_del_count = info.get_del_count() + self.pending_delete_count;
    info.set_del_count(new_del_count)?;
    self.drop_changes();

    Ok(true)
  }

  fn is_fully_deleted<D>(
    &mut self,
    info: &SegmentCommitInfo<D>,
    _reader: Option<&DefaultLeafReader<D>>,
    _field_infos: Option<FieldInfos>,
    _on_new_reader: bool,
  ) -> Result<bool>
  where
    D: Directory,
  {
    debug_assert!(info.info.max_doc()? == self.max_doc);
    Ok(self.get_del_count(info) == info.info.max_doc()?)
  }

  fn num_deletes_to_merge<D>(
    &mut self,
    _info: &SegmentCommitInfo<D>,
    _reader: Option<&DefaultLeafReader<D>>,
    _field_infos: Option<FieldInfos>,
    _on_new_reader: bool,
  ) -> Result<()>
  where
    D: Directory,
  {
    Ok(())
  }

  fn max_doc(&self) -> i32 {
    self.max_doc
  }

  fn must_init_on_delete(&self) -> bool {
    false
  }
}
impl fmt::Display for PendingDeletes {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    write!(
      f,
      "{}(seg={} numPendingDeletes={} writeable={})",
      std::any::type_name::<Self>(),
      self.info_id,
      self.pending_delete_count,
      matches!(&self.live_docs, Some(LiveDocsState::Writable(_)))
    )
  }
}

pub(crate) trait PendingDeletesBase: Display {
  fn get_info_id(&self) -> &str;
  /// Marks a document as deleted in this segment and return true if a document got actually deleted or if the document was already deleted.
  fn delete<D>(&mut self, doc_id: i32, info: &SegmentCommitInfo<D>) -> Result<bool>;
  /// Returns a snapshot of the hard live docs.
  fn get_hard_live_docs(&mut self) -> Option<DocBits>;
  /// Returns a snapshot of the current live docs.
  fn get_live_docs(&mut self) -> Option<DocBits>;
  /// Returns the number of pending deletes that are not yet flushed to disk.
  fn num_pending_deletes(&self) -> i32;
  /// Called once a new reader is opened for this segment ie. when deletes or updates are applied.
  fn on_new_reader<D>(
    &mut self,
    reader: &SegmentReader<D>,
    info: &SegmentCommitInfo<D>,
  ) -> Result<()>
  where
    D: Directory;
  fn drop_changes(&mut self);
  /// Writes the live docs to disk and returns `true` if any new docs were written.
  fn write_live_docs<D1, D2>(&mut self, dir: D1, info: &mut SegmentCommitInfo<D2>) -> Result<bool>
  where
    D1: Directory;
  fn is_fully_deleted<D>(
    &mut self,
    info: &SegmentCommitInfo<D>,
    reader: Option<&DefaultLeafReader<D>>,
    field_infos: Option<FieldInfos>,
    on_new_reader: bool,
  ) -> Result<bool>
  where
    D: Directory;

  fn num_deletes_to_merge<D>(
    &mut self,
    info: &SegmentCommitInfo<D>,
    reader: Option<&DefaultLeafReader<D>>,
    field_infos: Option<FieldInfos>,
    on_new_reader: bool,
  ) -> Result<()>
  where
    D: Directory;

  /// Returns true if the given reader needs to be refreshed to see the latest deletes
  fn needs_refresh<D>(
    &mut self,
    reader: &SegmentReader<D>,
    info: &SegmentCommitInfo<D>,
  ) -> Result<bool>
  where
    D: Directory,
  {
    let live_docs_changed = match (reader.get_live_docs()?, self.get_live_docs()) {
      (None, None) => false,
      (Some(reader_bits), Some(current_bits)) => reader_bits.identity() != current_bits.identity(),
      _ => true,
    };
    Ok(live_docs_changed || reader.num_deleted_docs()? != self.get_del_count(info))
  }
  /// Returns the number of deleted docs in the segment.
  fn get_del_count<D>(&self, info: &SegmentCommitInfo<D>) -> i32 {
    info.get_del_count() + info.get_soft_del_count() + self.num_pending_deletes()
  }
  /// Returns the number of live documents in this segment
  fn num_docs<D>(&self, info: &SegmentCommitInfo<D>) -> Result<i32> {
    debug_assert!(info.info.max_doc()? == self.max_doc());
    let max_doc = info.info.max_doc()?;
    Ok(max_doc - self.get_del_count(info))
  }
  // Call only from assert!
  fn verify_doc_counts<D, T>(&mut self, reader: &T, info: &SegmentCommitInfo<D>) -> Result<bool>
  where
    T: CodecReader,
  {
    debug_assert!(info.info.max_doc()? == self.max_doc());
    let max_doc = info.info.max_doc()?;
    let mut count = 0;
    match self.get_live_docs() {
      Some(bits) => {
        for doc_id in 0..max_doc {
          if bits.get(doc_id as usize)? {
            count += 1;
          }
        }
      },
      _ => {
        count = max_doc;
      },
    }

    debug_assert_eq!(
      self.num_docs(info)?,
      count,
      "info.maxDoc={} info.getDelCount={} info.getSoftDelCount={} pendingDeletes={} count={} numDocs={}",
      max_doc,
      info.get_del_count(),
      info.get_soft_del_count(),
      self.num_pending_deletes(),
      count,
      self.num_docs(info)?
    );

    debug_assert_eq!(
      reader.num_docs()?,
      self.num_docs(info)?,
      "reader.numDocs={} numDocs={}",
      reader.num_docs()?,
      self.num_docs(info)?
    );

    debug_assert!(
      reader.num_deleted_docs()? <= max_doc,
      "delCount={} info.maxDoc={} pendingDeleteCount={} info.getDelCount={}",
      reader.num_deleted_docs()?,
      max_doc,
      self.num_pending_deletes(),
      info.get_del_count()
    );
    Ok(true)
  }
  fn max_doc(&self) -> i32;
  fn on_doc_values_update<D>(
    &mut self,
    _field_info: &FieldInfo,
    _iterator: Option<MergedIterator<DocValuesFieldIteratorEnum>>,
    _info: &mut SegmentCommitInfo<D>,
  ) -> Result<()> {
    Ok(())
  }
  /// Returns `true` if this `PendingDeletes` must be initialized before [`delete`](Self::delete);
  /// otherwise it is ready to accept deletes.
  /// A `PendingDeletes` can be initialized by providing it a reader via [`on_new_reader`](Self::on_new_reader).
  fn must_init_on_delete(&self) -> bool;
}

pub(crate) enum PendingDeletesEnum {
  PD(PendingDeletes),
  Soft(PendingSoftDeletes),
}
impl PendingDeletesEnum {
  pub(crate) fn dv_gen(&self) -> Result<i64> {
    match self {
      PendingDeletesEnum::PD(_a) => Err(LuceneError::unsupported_operation("no dvGen for PD")),
      PendingDeletesEnum::Soft(b) => Ok(b.dv_generation),
    }
  }
  pub(crate) fn field(&self) -> Result<&str> {
    match self {
      PendingDeletesEnum::PD(_a) => Err(LuceneError::unsupported_operation("no dvGen for PD")),
      PendingDeletesEnum::Soft(b) => Ok(&b.field),
    }
  }
}

impl Display for PendingDeletesEnum {
  fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    match self {
      PendingDeletesEnum::PD(a) => a.fmt(f),
      PendingDeletesEnum::Soft(b) => b.fmt(f),
    }
  }
}

impl PendingDeletesBase for PendingDeletesEnum {
  fn get_info_id(&self) -> &str {
    match self {
      PendingDeletesEnum::PD(a) => a.get_info_id(),
      PendingDeletesEnum::Soft(b) => b.get_info_id(),
    }
  }

  fn delete<D>(&mut self, doc_id: i32, info: &SegmentCommitInfo<D>) -> Result<bool> {
    match self {
      PendingDeletesEnum::PD(a) => a.delete(doc_id, info),
      PendingDeletesEnum::Soft(b) => b.delete(doc_id, info),
    }
  }

  fn get_hard_live_docs(&mut self) -> Option<DocBits> {
    match self {
      PendingDeletesEnum::PD(a) => a.get_hard_live_docs(),
      PendingDeletesEnum::Soft(b) => b.get_hard_live_docs(),
    }
  }

  fn get_live_docs(&mut self) -> Option<DocBits> {
    match self {
      PendingDeletesEnum::PD(a) => a.get_live_docs(),
      PendingDeletesEnum::Soft(b) => b.get_live_docs(),
    }
  }

  fn num_pending_deletes(&self) -> i32 {
    match self {
      PendingDeletesEnum::PD(a) => a.num_pending_deletes(),
      PendingDeletesEnum::Soft(b) => b.num_pending_deletes(),
    }
  }

  fn on_new_reader<D>(
    &mut self,
    reader: &SegmentReader<D>,
    info: &SegmentCommitInfo<D>,
  ) -> Result<()>
  where
    D: Directory,
  {
    match self {
      PendingDeletesEnum::PD(a) => a.on_new_reader(reader, info),
      PendingDeletesEnum::Soft(b) => b.on_new_reader(reader, info),
    }
  }

  fn drop_changes(&mut self) {
    match self {
      PendingDeletesEnum::PD(a) => a.drop_changes(),
      PendingDeletesEnum::Soft(b) => b.drop_changes(),
    }
  }

  fn write_live_docs<D1, D2>(&mut self, dir: D1, info: &mut SegmentCommitInfo<D2>) -> Result<bool>
  where
    D1: Directory,
  {
    match self {
      PendingDeletesEnum::PD(a) => a.write_live_docs(dir, info),
      PendingDeletesEnum::Soft(b) => b.write_live_docs(dir, info),
    }
  }

  fn is_fully_deleted<D>(
    &mut self,
    info: &SegmentCommitInfo<D>,
    reader: Option<&DefaultLeafReader<D>>,
    field_infos: Option<FieldInfos>,
    on_new_reader: bool,
  ) -> Result<bool>
  where
    D: Directory,
  {
    match self {
      PendingDeletesEnum::PD(a) => a.is_fully_deleted(info, reader, field_infos, on_new_reader),
      PendingDeletesEnum::Soft(b) => b.is_fully_deleted(info, reader, field_infos, on_new_reader),
    }
  }

  fn num_deletes_to_merge<D>(
    &mut self,
    info: &SegmentCommitInfo<D>,
    reader: Option<&DefaultLeafReader<D>>,
    field_infos: Option<FieldInfos>,
    on_new_reader: bool,
  ) -> Result<()>
  where
    D: Directory,
  {
    match self {
      PendingDeletesEnum::PD(a) => a.num_deletes_to_merge(info, reader, field_infos, on_new_reader),
      PendingDeletesEnum::Soft(b) => {
        b.num_deletes_to_merge(info, reader, field_infos, on_new_reader)
      },
    }
  }

  fn max_doc(&self) -> i32 {
    match self {
      PendingDeletesEnum::PD(a) => a.max_doc(),
      PendingDeletesEnum::Soft(b) => b.max_doc(),
    }
  }

  fn on_doc_values_update<D>(
    &mut self,
    info: &FieldInfo,
    iterator: Option<MergedIterator<DocValuesFieldIteratorEnum>>,
    segment_info: &mut SegmentCommitInfo<D>,
  ) -> Result<()> {
    match self {
      PendingDeletesEnum::PD(a) => a.on_doc_values_update(info, iterator, segment_info),
      PendingDeletesEnum::Soft(b) => b.on_doc_values_update(info, iterator, segment_info),
    }
  }

  fn must_init_on_delete(&self) -> bool {
    match self {
      PendingDeletesEnum::PD(a) => a.must_init_on_delete(),
      PendingDeletesEnum::Soft(b) => b.must_init_on_delete(),
    }
  }
}