Skip to content

Commit 06afbe7

Browse files
gf2121jpountz
andauthored
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 12c3041 commit 06afbe7

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
@@ -1097,6 +1097,32 @@ private void bufferIntoBitSet(int start, int end, FixedBitSet bitSet, int offset
10971097
}
10981098
}
10991099

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

0 commit comments

Comments
 (0)