Skip to content

Commit

Permalink
fix bug in term vector api, payloads were not handles correctly when …
Browse files Browse the repository at this point in the history
…some where missing

The array holding the payloads (TermVectorFields.payloads) is reused for each token. If the
previous token had payloads but the current token had not, then the payloads of the previous
token were returned, because the payloads of the previous token were never invalidated.
For example, for a field only contained two tokens each occurring once, the first having a
payload and the second not, then for the second token, the payload of the first was returned.

closes elastic#3873
  • Loading branch information
brwe committed Oct 14, 2013
1 parent 6365063 commit 32dc5cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Expand Up @@ -27,7 +27,6 @@
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.RamUsageEstimator;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.hppc.HppcMaps;
import org.elasticsearch.common.io.stream.BytesStreamInput;

import java.io.IOException;
Expand Down Expand Up @@ -246,16 +245,14 @@ private void writeInfos(final BytesStreamInput input) throws IOException {
}
if (hasPayloads) {
int payloadLength = input.readVInt();
if (payloadLength > 0) {
if (payloads[i] == null) {
payloads[i] = new BytesRef(payloadLength);
} else {
payloads[i].grow(payloadLength);
}
input.readBytes(payloads[i].bytes, 0, payloadLength);
payloads[i].length = payloadLength;
payloads[i].offset = 0;
if (payloads[i] == null) {
payloads[i] = new BytesRef(payloadLength);
} else {
payloads[i].grow(payloadLength);
}
input.readBytes(payloads[i].bytes, 0, payloadLength);
payloads[i].length = payloadLength;
payloads[i].offset = 0;
}
}
}
Expand Down
Expand Up @@ -246,7 +246,7 @@ private void buildValues(XContentBuilder builder, Terms curTerms, int termFreq)
builder.field(FieldStrings.START_OFFSET, currentStartOffset[i]);
builder.field(FieldStrings.END_OFFSET, currentEndOffset[i]);
}
if (curTerms.hasPayloads() && (currentPayloads[i] != null)) {
if (curTerms.hasPayloads() && (currentPayloads[i].length() > 0)) {
builder.field(FieldStrings.PAYLOAD, currentPayloads[i]);
}
builder.endObject();
Expand Down
Expand Up @@ -149,7 +149,6 @@ private DocsAndPositionsEnum writeTermWithDocsAndPos(TermsEnum iterator, DocsAnd
}

private void writePayload(BytesRef payload) throws IOException {
assert (payload != null);
if (payload != null) {
output.writeVInt(payload.length);
output.writeBytes(payload.bytes, payload.offset, payload.length);
Expand Down

0 comments on commit 32dc5cf

Please sign in to comment.