diff --git a/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java b/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java index 1e6671ea05c..cf425cf7cd7 100644 --- a/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java +++ b/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java @@ -450,7 +450,7 @@ public class MultiDocValues { public int getOrd(int docID) { int subIndex = ReaderUtil.subIndex(docID, docStarts); int segmentOrd = values[subIndex].getOrd(docID - docStarts[subIndex]); - return (int) mapping.getGlobalOrd(subIndex, segmentOrd); + return segmentOrd == -1 ? segmentOrd : (int) mapping.getGlobalOrd(subIndex, segmentOrd); } @Override diff --git a/lucene/core/src/test/org/apache/lucene/index/TestMultiDocValues.java b/lucene/core/src/test/org/apache/lucene/index/TestMultiDocValues.java index 8944dd66b67..0e21308bda4 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestMultiDocValues.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestMultiDocValues.java @@ -121,6 +121,9 @@ public class TestMultiDocValues extends LuceneTestCase { int numDocs = atLeast(500); for (int i = 0; i < numDocs; i++) { ref.copyChars(_TestUtil.randomUnicodeString(random())); + if (random().nextInt(7) == 0) { + iw.addDocument(new Document()); + } iw.addDocument(doc); if (random().nextInt(17) == 0) { iw.commit(); @@ -140,7 +143,7 @@ public class TestMultiDocValues extends LuceneTestCase { for (int i = 0; i < numDocs; i++) { // check ord assertEquals(single.getOrd(i), multi.getOrd(i)); - // check ord value + // check value single.get(i, expected); multi.get(i, actual); assertEquals(expected, actual);