mirror of https://github.com/apache/lucene.git
LUCENE-8484: Only drop fully deleted segments in SoftDeletesDirectoryReaderWrapper
This specializes the change in LUCENE-8484 since there are valid usecases where filtered reader should not modify the number of readers if a higher level reader wants to expose the deleted or soft-deleted docs.
This commit is contained in:
parent
7223a8bf7a
commit
c8b47e2024
|
@ -18,7 +18,6 @@ package org.apache.lucene.index;
|
|||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -51,16 +50,20 @@ public abstract class FilterDirectoryReader extends DirectoryReader {
|
|||
*/
|
||||
public static abstract class SubReaderWrapper {
|
||||
|
||||
private LeafReader[] wrap(List<? extends LeafReader> readers) {
|
||||
List<LeafReader> wrapped = new ArrayList<>(readers.size());
|
||||
/**
|
||||
* Wraps a list of LeafReaders
|
||||
* @return an array of wrapped LeafReaders. The returned array might contain less elements compared to the given
|
||||
* reader list if an entire reader is filtered out.
|
||||
*/
|
||||
protected LeafReader[] wrap(List<? extends LeafReader> readers) {
|
||||
LeafReader[] wrapped = new LeafReader[readers.size()];
|
||||
int i = 0;
|
||||
for (LeafReader reader : readers) {
|
||||
LeafReader wrap = wrap(reader);
|
||||
assert wrap != null;
|
||||
if (wrap.numDocs() > 0) {
|
||||
wrapped.add(wrap);
|
||||
wrapped[i++] = wrap;
|
||||
}
|
||||
}
|
||||
return wrapped.toArray(new LeafReader[0]);
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
/** Constructor */
|
||||
|
|
|
@ -19,8 +19,10 @@ package org.apache.lucene.index;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -86,6 +88,18 @@ public final class SoftDeletesDirectoryReaderWrapper extends FilterDirectoryRead
|
|||
this.field = field;
|
||||
}
|
||||
|
||||
protected LeafReader[] wrap(List<? extends LeafReader> readers) {
|
||||
List<LeafReader> wrapped = new ArrayList<>(readers.size());
|
||||
for (LeafReader reader : readers) {
|
||||
LeafReader wrap = wrap(reader);
|
||||
assert wrap != null;
|
||||
if (wrap.numDocs() != 0) {
|
||||
wrapped.add(wrap);
|
||||
}
|
||||
}
|
||||
return wrapped.toArray(new LeafReader[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LeafReader wrap(LeafReader reader) {
|
||||
CacheHelper readerCacheHelper = reader.getReaderCacheHelper();
|
||||
|
|
Loading…
Reference in New Issue