Skip to content

Commit ec5b02e

Browse files
Some improvements to ES812PostingsReader
Removing some fields that need not exist from this class as well as cleaning up two redundant conditions and adding missing `final`.
1 parent 801b013 commit ec5b02e

File tree

1 file changed

+40
-61
lines changed

1 file changed

+40
-61
lines changed

server/src/main/java/org/elasticsearch/index/codec/postings/ES812PostingsReader.java

+40-61
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ public ImpactsEnum impacts(FieldInfo fieldInfo, BlockTermState state, int flags)
265265
return new BlockImpactsDocsEnum(fieldInfo, (IntBlockTermState) state);
266266
}
267267

268-
if (indexHasPositions
269-
&& PostingsEnum.featureRequested(flags, PostingsEnum.POSITIONS)
270-
&& (indexHasOffsets == false || PostingsEnum.featureRequested(flags, PostingsEnum.OFFSETS) == false)
268+
if ((indexHasOffsets == false || PostingsEnum.featureRequested(flags, PostingsEnum.OFFSETS) == false)
271269
&& (indexHasPayloads == false || PostingsEnum.featureRequested(flags, PostingsEnum.PAYLOADS) == false)) {
272270
return new BlockImpactsPostingsEnum(fieldInfo, (IntBlockTermState) state);
273271
}
@@ -287,8 +285,6 @@ final class BlockDocsEnum extends PostingsEnum {
287285
private ES812SkipReader skipper;
288286
private boolean skipped;
289287

290-
final IndexInput startDocIn;
291-
292288
IndexInput docIn;
293289
final boolean indexHasFreq;
294290
final boolean indexHasPos;
@@ -320,8 +316,7 @@ final class BlockDocsEnum extends PostingsEnum {
320316
private boolean isFreqsRead;
321317
private int singletonDocID; // docid when there is a single pulsed posting, otherwise -1
322318

323-
BlockDocsEnum(FieldInfo fieldInfo) throws IOException {
324-
this.startDocIn = ES812PostingsReader.this.docIn;
319+
BlockDocsEnum(FieldInfo fieldInfo) {
325320
this.docIn = null;
326321
indexHasFreq = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) >= 0;
327322
indexHasPos = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
@@ -333,7 +328,7 @@ final class BlockDocsEnum extends PostingsEnum {
333328
}
334329

335330
public boolean canReuse(IndexInput docIn, FieldInfo fieldInfo) {
336-
return docIn == startDocIn
331+
return docIn == ES812PostingsReader.this.docIn
337332
&& indexHasFreq == (fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) >= 0)
338333
&& indexHasPos == (fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0)
339334
&& indexHasPayloads == fieldInfo.hasPayloads();
@@ -348,7 +343,7 @@ public PostingsEnum reset(IntBlockTermState termState, int flags) throws IOExcep
348343
if (docFreq > 1) {
349344
if (docIn == null) {
350345
// lazy init
351-
docIn = startDocIn.clone();
346+
docIn = ES812PostingsReader.this.docIn.clone();
352347
}
353348
docIn.seek(docTermStartFP);
354349
}
@@ -379,22 +374,22 @@ public int freq() throws IOException {
379374
}
380375

381376
@Override
382-
public int nextPosition() throws IOException {
377+
public int nextPosition() {
383378
return -1;
384379
}
385380

386381
@Override
387-
public int startOffset() throws IOException {
382+
public int startOffset() {
388383
return -1;
389384
}
390385

391386
@Override
392-
public int endOffset() throws IOException {
387+
public int endOffset() {
393388
return -1;
394389
}
395390

396391
@Override
397-
public BytesRef getPayload() throws IOException {
392+
public BytesRef getPayload() {
398393
return null;
399394
}
400395

@@ -604,7 +599,7 @@ final class EverythingEnum extends PostingsEnum {
604599
private boolean needsPayloads; // true if we actually need payloads
605600
private int singletonDocID; // docid when there is a single pulsed posting, otherwise -1
606601

607-
EverythingEnum(FieldInfo fieldInfo) throws IOException {
602+
EverythingEnum(FieldInfo fieldInfo) {
608603
indexHasOffsets = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
609604
indexHasPayloads = fieldInfo.hasPayloads();
610605

@@ -690,7 +685,7 @@ public EverythingEnum reset(IntBlockTermState termState, int flags) throws IOExc
690685
}
691686

692687
@Override
693-
public int freq() throws IOException {
688+
public int freq() {
694689
return freq;
695690
}
696691

@@ -851,16 +846,13 @@ public int advance(int target) throws IOException {
851846

852847
// Now scan:
853848
long doc;
854-
while (true) {
849+
do {
855850
doc = docBuffer[docBufferUpto];
856851
freq = (int) freqBuffer[docBufferUpto];
857852
posPendingCount += freq;
858853
docBufferUpto++;
859854

860-
if (doc >= target) {
861-
break;
862-
}
863-
}
855+
} while (doc < target);
864856

865857
position = 0;
866858
lastStartOffset = 0;
@@ -1010,7 +1002,7 @@ final class BlockImpactsDocsEnum extends ImpactsEnum {
10101002

10111003
final boolean indexHasFreqs;
10121004

1013-
private int docFreq; // number of docs in this posting list
1005+
private final int docFreq; // number of docs in this posting list
10141006
private int blockUpto; // number of documents in or before the current block
10151007
private int doc; // doc we last read
10161008
private long accum; // accumulator for doc deltas
@@ -1167,7 +1159,7 @@ public int advance(int target) throws IOException {
11671159
}
11681160

11691161
@Override
1170-
public int nextPosition() throws IOException {
1162+
public int nextPosition() {
11711163
return -1;
11721164
}
11731165

@@ -1211,8 +1203,8 @@ final class BlockImpactsPostingsEnum extends ImpactsEnum {
12111203
final boolean indexHasOffsets;
12121204
final boolean indexHasPayloads;
12131205

1214-
private int docFreq; // number of docs in this posting list
1215-
private long totalTermFreq; // number of positions in this posting list
1206+
private final int docFreq; // number of docs in this posting list
1207+
private final long totalTermFreq; // number of positions in this posting list
12161208
private int docUpto; // how many docs we've read
12171209
private int doc; // doc we last read
12181210
private long accum; // accumulator for doc deltas
@@ -1227,20 +1219,10 @@ final class BlockImpactsPostingsEnum extends ImpactsEnum {
12271219
// before reading positions:
12281220
private long posPendingFP;
12291221

1230-
// Where this term's postings start in the .doc file:
1231-
private long docTermStartFP;
1232-
1233-
// Where this term's postings start in the .pos file:
1234-
private long posTermStartFP;
1235-
1236-
// Where this term's payloads/offsets start in the .pay
1237-
// file:
1238-
private long payTermStartFP;
1239-
12401222
// File pointer where the last (vInt encoded) pos delta
12411223
// block is. We need this to know whether to bulk
12421224
// decode vs vInt decode the block:
1243-
private long lastPosBlockFP;
1225+
private final long lastPosBlockFP;
12441226

12451227
private int nextSkipDoc = -1;
12461228

@@ -1255,9 +1237,13 @@ final class BlockImpactsPostingsEnum extends ImpactsEnum {
12551237
this.posIn = ES812PostingsReader.this.posIn.clone();
12561238

12571239
docFreq = termState.docFreq;
1258-
docTermStartFP = termState.docStartFP;
1259-
posTermStartFP = termState.posStartFP;
1260-
payTermStartFP = termState.payStartFP;
1240+
// Where this term's postings start in the .doc file:
1241+
long docTermStartFP = termState.docStartFP;
1242+
// Where this term's postings start in the .pos file:
1243+
long posTermStartFP = termState.posStartFP;
1244+
// Where this term's payloads/offsets start in the .pay
1245+
// file:
1246+
long payTermStartFP = termState.payStartFP;
12611247
totalTermFreq = termState.totalTermFreq;
12621248
docIn.seek(docTermStartFP);
12631249
posPendingFP = posTermStartFP;
@@ -1280,7 +1266,7 @@ final class BlockImpactsPostingsEnum extends ImpactsEnum {
12801266
}
12811267

12821268
@Override
1283-
public int freq() throws IOException {
1269+
public int freq() {
12841270
return freq;
12851271
}
12861272

@@ -1507,8 +1493,8 @@ final class BlockImpactsEverythingEnum extends ImpactsEnum {
15071493
final boolean indexHasOffsets;
15081494
final boolean indexHasPayloads;
15091495

1510-
private int docFreq; // number of docs in this posting list
1511-
private long totalTermFreq; // number of positions in this posting list
1496+
private final int docFreq; // number of docs in this posting list
1497+
private final long totalTermFreq; // number of positions in this posting list
15121498
private int docUpto; // how many docs we've read
15131499
private int posDocUpTo; // for how many docs we've read positions, offsets, and payloads
15141500
private int doc; // doc we last read
@@ -1527,20 +1513,10 @@ final class BlockImpactsEverythingEnum extends ImpactsEnum {
15271513
// before reading payloads/offsets:
15281514
private long payPendingFP;
15291515

1530-
// Where this term's postings start in the .doc file:
1531-
private long docTermStartFP;
1532-
1533-
// Where this term's postings start in the .pos file:
1534-
private long posTermStartFP;
1535-
1536-
// Where this term's payloads/offsets start in the .pay
1537-
// file:
1538-
private long payTermStartFP;
1539-
15401516
// File pointer where the last (vInt encoded) pos delta
15411517
// block is. We need this to know whether to bulk
15421518
// decode vs vInt decode the block:
1543-
private long lastPosBlockFP;
1519+
private final long lastPosBlockFP;
15441520

15451521
private int nextSkipDoc = -1;
15461522

@@ -1597,20 +1573,17 @@ final class BlockImpactsEverythingEnum extends ImpactsEnum {
15971573
}
15981574

15991575
docFreq = termState.docFreq;
1600-
docTermStartFP = termState.docStartFP;
1601-
posTermStartFP = termState.posStartFP;
1602-
payTermStartFP = termState.payStartFP;
16031576
totalTermFreq = termState.totalTermFreq;
1604-
docIn.seek(docTermStartFP);
1605-
posPendingFP = posTermStartFP;
1606-
payPendingFP = payTermStartFP;
1577+
docIn.seek(termState.docStartFP);
1578+
posPendingFP = termState.posStartFP;
1579+
payPendingFP = termState.payStartFP;
16071580
posPendingCount = 0;
16081581
if (termState.totalTermFreq < BLOCK_SIZE) {
1609-
lastPosBlockFP = posTermStartFP;
1582+
lastPosBlockFP = termState.posStartFP;
16101583
} else if (termState.totalTermFreq == BLOCK_SIZE) {
16111584
lastPosBlockFP = -1;
16121585
} else {
1613-
lastPosBlockFP = posTermStartFP + termState.lastPosBlockOffset;
1586+
lastPosBlockFP = termState.posStartFP + termState.lastPosBlockOffset;
16141587
}
16151588

16161589
doc = -1;
@@ -1621,7 +1594,13 @@ final class BlockImpactsEverythingEnum extends ImpactsEnum {
16211594
docBufferUpto = BLOCK_SIZE;
16221595

16231596
skipper = new ES812ScoreSkipReader(docIn.clone(), MAX_SKIP_LEVELS, indexHasPos, indexHasOffsets, indexHasPayloads);
1624-
skipper.init(docTermStartFP + termState.skipOffset, docTermStartFP, posTermStartFP, payTermStartFP, docFreq);
1597+
skipper.init(
1598+
termState.docStartFP + termState.skipOffset,
1599+
termState.docStartFP,
1600+
termState.posStartFP,
1601+
termState.payStartFP,
1602+
docFreq
1603+
);
16251604

16261605
if (indexHasFreq == false) {
16271606
for (int i = 0; i < ForUtil.BLOCK_SIZE; ++i) {

0 commit comments

Comments
 (0)