Skip to content

Commit

Permalink
Delta code postings offsets.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpountz committed Jan 26, 2024
1 parent 4c3a1de commit 25ca1ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void write(Fields fields, NormsProducer norms) throws IOException {
continue;
}
long proxOffset = hasPositions ? prox.getFilePointer() : -1L;
long postingsPointer = postingsOut.size();
long postingsStartPointer = postingsOut.size();
writer.write(pe, postingsOut);
termsOut.writeVInt(term.length);
termsOut.writeBytes(term.bytes, term.offset, term.length);
Expand All @@ -145,7 +145,7 @@ public void write(Fields fields, NormsProducer norms) throws IOException {
if (hasPositions) {
termsOut.writeLong(proxOffset);
}
termsOut.writeLong(postingsPointer);
termsOut.writeVLong(postingsOut.size() - postingsStartPointer);
++numPending;
maxTermLength = Math.max(maxTermLength, term.length);
++numTerms;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ private void reset() throws IOException {
state.blockIndex = -1;
state.termIndexInBlock = 0;
state.numTermsInBlock = -1;
state.postingsFP = 0;
state.postingsBytes = 0;
state.blockPostingsFP = 0;
state.blockPostingsBytes = 0;
}

private long findBlockIndex(BytesRef target) throws IOException {
Expand Down Expand Up @@ -439,7 +439,7 @@ public BytesRef next() throws IOException {
return null; // exhausted
}
if (state.blockIndex > 0) {
index.seek(state.postingsFP + state.postingsBytes);
index.seek(state.blockPostingsFP + state.blockPostingsBytes);
}
loadFrame();
} else if (state.blockIndex != loadedFrameIndex) {
Expand Down Expand Up @@ -467,9 +467,11 @@ private void loadFrame() throws IOException {
state.numTermsInBlock = index.readVInt();
final long originalTermsBytes = index.readVLong();
final long termBytes = index.readVLong();
state.postingsBytes = index.readVLong();
state.blockPostingsBytes = index.readVLong();
long termsFP = index.getFilePointer();
state.postingsFP = termsFP + termBytes;
state.blockPostingsFP = termsFP + termBytes;
state.docOffset = state.blockPostingsFP;
state.termPostingsBytes = 0L;
decompressTerms((int) termBytes, (int) originalTermsBytes);
loadedFrameIndex = state.blockIndex;
}
Expand All @@ -478,7 +480,9 @@ private void resetFrame() throws IOException {
assert loadedFrameIndex == state.blockIndex : loadedFrameIndex + " != " + state.blockIndex;
state.termIndexInBlock = 0;
termsReader.setPosition(0);
index.seek(state.postingsFP);
state.docOffset = state.blockPostingsFP;
state.termPostingsBytes = 0L;
index.seek(state.blockPostingsFP);
}

private void scanNextTermInCurrentFrame() throws IOException {
Expand All @@ -495,7 +499,8 @@ private void scanNextTermInCurrentFrame() throws IOException {
if (meta.options.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) {
state.proxOffset = termsReader.readLong();
}
state.docOffset = state.postingsFP + termsReader.readLong();
state.docOffset += state.termPostingsBytes;
state.termPostingsBytes = termsReader.readVLong();
state.termIndexInBlock++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ public static final class InlineTermState extends BlockTermState {
public long termIndexInBlock;
public long numTermsInBlock;

public long postingsFP;
public long postingsBytes;
public long blockPostingsFP;
public long blockPostingsBytes;

public long termPostingsBytes;
public long docOffset;
public long proxOffset;

Expand All @@ -77,9 +78,10 @@ public void copyFrom(TermState _other) {
this.blockIndex = state.blockIndex;
this.termIndexInBlock = state.termIndexInBlock;
this.numTermsInBlock = state.numTermsInBlock;
this.postingsFP = state.postingsFP;
this.postingsBytes = state.postingsBytes;
this.blockPostingsFP = state.blockPostingsFP;
this.blockPostingsBytes = state.blockPostingsBytes;
this.docOffset = state.docOffset;
this.termPostingsBytes = state.termPostingsBytes;
this.proxOffset = state.proxOffset;
}

Expand Down

0 comments on commit 25ca1ee

Please sign in to comment.