Skip to content

Commit 3606763

Browse files
gf2121jpountz
andcommitted
Implement #docIDRunEnd() on PostingsEnum. (#14693)
This implements `BlockPostingsEnum#docIDRunEnd()` by comparing the delta between doc IDs and between doc counts on the various skip levels. Co-authored-by: Adrien Grand <[email protected]>
1 parent adbf9a9 commit 3606763

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lucene/core/src/java/org/apache/lucene/codecs/lucene103/Lucene103PostingsReader.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,32 @@ private void bufferIntoBitSet(int start, int end, FixedBitSet bitSet, int offset
11041104
}
11051105
}
11061106

1107+
@Override
1108+
public int docIDRunEnd() throws IOException {
1109+
// Note: this assumes that BLOCK_SIZE == 128, this bit of the code would need to be changed if
1110+
// the block size was changed.
1111+
// Hack to avoid compiler warning that both sides of the equal sign are identical.
1112+
long blockSize = BLOCK_SIZE;
1113+
assert blockSize == 2 * Long.SIZE;
1114+
boolean level0IsDense =
1115+
encoding == DeltaEncoding.UNARY
1116+
&& docBitSet.getBits()[0] == -1L
1117+
&& docBitSet.getBits()[1] == -1L;
1118+
if (level0IsDense) {
1119+
1120+
int level0DocCountUpto = docFreq - docCountLeft;
1121+
boolean level1IsDense =
1122+
level1LastDocID - level0LastDocID == level1DocCountUpto - level0DocCountUpto;
1123+
if (level1IsDense) {
1124+
return level1LastDocID + 1;
1125+
}
1126+
1127+
return level0LastDocID + 1;
1128+
}
1129+
1130+
return super.docIDRunEnd();
1131+
}
1132+
11071133
private void skipPositions(int freq) throws IOException {
11081134
// Skip positions now:
11091135
int toSkip = posPendingCount - freq;

0 commit comments

Comments
 (0)