Apache Lucene open-source search software
don't load MultiDocValues for norms if one leaf reader omits norms
Simon Willnauer8913c0c5971d
diff --git a/lucene/src/java/org/apache/lucene/index/MultiDocValues.java b/lucene/src/java/org/apache/lucene/index/MultiDocValues.javaindex e0fa37d6393..317c9a56b95 100644--- a/lucene/src/java/org/apache/lucene/index/MultiDocValues.java+++ b/lucene/src/java/org/apache/lucene/index/MultiDocValues.java@@ -46,6 +46,12 @@ public class MultiDocValues extends DocValues {public DocValues pull(IndexReader reader, String field) throws IOException {return reader.normValues(field);}++ public boolean stopLoadingOnNull(IndexReader reader, String field) throws IOException {+ // for norms we drop all norms if one leaf reader has no norms and the field is present+ Fields fields = reader.fields();+ return (fields != null && fields.terms(field) != null);+ }};public static class DocValuesSlice {@@ -65,6 +71,10 @@ public class MultiDocValues extends DocValues {public DocValues pull(IndexReader reader, String field) throws IOException {return reader.docValues(field);}++ public boolean stopLoadingOnNull(IndexReader reader, String field) throws IOException {+ return false;+ }}private DocValuesSlice[] slices;@@ -123,12 +133,19 @@ public class MultiDocValues extends DocValues {// potentially incompatible typesnew ReaderUtil.Gather(r) {+ boolean stop = false;@Overrideprotected void add(int base, IndexReader r) throws IOException {+ if (stop) {+ return;+ }final DocValues d = puller.pull(r, field);if (d != null) {TypePromoter incoming = TypePromoter.create(d.type(), d.getValueSize());promotedType[0] = promotedType[0].promote(incoming);+ } else if (puller.stopLoadingOnNull(r, field)){+ promotedType[0] = TypePromoter.getIdentityPromoter(); // set to identity to return null+ stop = true;}slices.add(new DocValuesSlice(d, base, r.maxDoc()));}