Skip to content

Commit

Permalink
remove hard checks for same soft deletes field
Browse files Browse the repository at this point in the history
  • Loading branch information
s1monw committed Dec 15, 2023
1 parent 7087f2c commit c122994
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.apache.lucene.util.ArrayUtil;
Expand Down Expand Up @@ -185,10 +184,12 @@ public static FieldInfos getMergedFieldInfos(IndexReader reader) {
return leaves.get(0).reader().getFieldInfos();
} else {
final String softDeletesField =
getAndValidateSpecialField(
"soft-deletes", leaves, r -> r.getFieldInfos().getSoftDeletesField());
final String parentField =
getAndValidateSpecialField("parent", leaves, r -> r.getFieldInfos().getParentField());
leaves.stream()
.map(l -> l.reader().getFieldInfos().getSoftDeletesField())
.filter(Objects::nonNull)
.findAny()
.orElse(null);
final String parentField = getAndValidateParentField(leaves);
final Builder builder = new Builder(new FieldNumbers(softDeletesField, parentField));
for (final LeafReaderContext ctx : leaves) {
for (FieldInfo fieldInfo : ctx.reader().getFieldInfos()) {
Expand All @@ -199,17 +200,14 @@ public static FieldInfos getMergedFieldInfos(IndexReader reader) {
}
}

private static String getAndValidateSpecialField(
String type, List<LeafReaderContext> leaves, Function<LeafReader, String> provider) {
private static String getAndValidateParentField(List<LeafReaderContext> leaves) {
boolean set = false;
String theField = null;
for (LeafReaderContext ctx : leaves) {
String field = provider.apply(ctx.reader());
String field = ctx.reader().getFieldInfos().getParentField();
if (set && Objects.equals(field, theField) == false) {
throw new IllegalStateException(
"expected "
+ type
+ " field to be \""
"expected parent doc field to be \""
+ theField
+ " \" across all segments but found a segment with different field \""
+ field
Expand Down

0 comments on commit c122994

Please sign in to comment.