@@ -338,6 +338,7 @@ public String toString() {
338
338
static SortedSetDocValues insertOrd (final SortedSetDocValues values , final long insertedOrd , final BytesRef missingValue ) {
339
339
return new AbstractSortedSetDocValues () {
340
340
341
+ private int ordCount = 0 ;
341
342
private boolean hasOrds ;
342
343
private long nextMissingOrd ;
343
344
@@ -365,6 +366,9 @@ public int docValueCount() {
365
366
@ Override
366
367
public long nextOrd () throws IOException {
367
368
if (hasOrds ) {
369
+ if (++ordCount == values .getValueCount ()) {
370
+ throw new IllegalStateException ("Called nextOrd after docValueCount" );
371
+ }
368
372
final long ord = values .nextOrd ();
369
373
if (ord < insertedOrd ) {
370
374
return ord ;
@@ -374,6 +378,9 @@ public long nextOrd() throws IOException {
374
378
return ord + 1 ;
375
379
}
376
380
} else {
381
+ if (nextMissingOrd == SortedSetDocValues .NO_MORE_DOCS ) {
382
+ throw new IllegalStateException ("Called nextOrd after docValueCount" );
383
+ }
377
384
// we want to return the next missing ord but set this to
378
385
// NO_MORE_DOCS so on the next call we indicate there are no
379
386
// more values
@@ -386,6 +393,7 @@ public long nextOrd() throws IOException {
386
393
@ Override
387
394
public boolean advanceExact (int doc ) throws IOException {
388
395
hasOrds = values .advanceExact (doc );
396
+ ordCount = 0 ;
389
397
nextMissingOrd = insertedOrd ;
390
398
// always return true because we want to return a value even if
391
399
// the document does not have a value
0 commit comments