jpountz commented on code in PR #13901:
URL: https://github.com/apache/lucene/pull/13901#discussion_r1799409756
##########
lucene/core/src/java/org/apache/lucene/codecs/lucene912/Lucene912PostingsReader.java:
##########
@@ -429,9 +403,44 @@ public PostingsEnum reset(IntBlockTermState termState, int
flags) throws IOExcep
}
level1DocCountUpto = 0;
docBufferUpto = BLOCK_SIZE;
- freqFP = -1;
return this;
}
+ }
+
+ final class BlockDocsEnum extends AbstractPostingsEnum {
+
+ private final long[] freqBuffer = new long[BLOCK_SIZE];
+
+ private boolean needsFreq; // true if the caller actually needs frequencies
+ private long freqFP;
+
+ public BlockDocsEnum(FieldInfo fieldInfo) {
+ super(fieldInfo);
+ }
+
+ public boolean canReuse(IndexInput docIn, FieldInfo fieldInfo) {
+ final IndexOptions options = fieldInfo.getIndexOptions();
+ return docIn == Lucene912PostingsReader.this.docIn
+ && indexHasFreq == (options.compareTo(IndexOptions.DOCS_AND_FREQS)
>= 0);
+ }
+
+ public PostingsEnum reset(IntBlockTermState termState, int flags) throws
IOException {
+ startReset(termState);
+ if (pforUtil == null && docFreq >= BLOCK_SIZE) {
+ pforUtil = new PForUtil(new ForUtil());
+ forDeltaUtil = new ForDeltaUtil();
+ }
+ totalTermFreq = indexHasFreq ? termState.totalTermFreq : docFreq;
+
+ this.needsFreq = PostingsEnum.featureRequested(flags,
PostingsEnum.FREQS);
+ if (indexHasFreq == false || needsFreq == false) {
+ // Filling this buffer may not be cheap when doing primary key
lookups, so we make sure to
+ // not fill more than `docFreq` entries.
+ Arrays.fill(freqBuffer, 0, Math.min(ForUtil.BLOCK_SIZE, docFreq), 1);
+ }
+ freqFP = -1;
+ return finishReset(termState);
Review Comment:
Now readers of this code need to look up 3 different places to understand
what `reset()` does: `startReset()`, `reset()` and `finishReset()`. Can we find
more meaningful names to the two helper methods or keep the code duplicated for
the sake of making it easier to read?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]