fix term vector api for missing payloads

This commit is contained in:
Britta Weber 2013-10-01 16:30:53 +02:00
parent f8a129961e
commit f91fd3b9ed
2 changed files with 9 additions and 3 deletions

View File

@ -246,7 +246,7 @@ public class TermVectorResponse extends ActionResponse implements ToXContent {
builder.field(FieldStrings.START_OFFSET, currentStartOffset[i]);
builder.field(FieldStrings.END_OFFSET, currentEndOffset[i]);
}
if (curTerms.hasPayloads()) {
if (curTerms.hasPayloads() && (currentPayloads[i] != null)) {
builder.field(FieldStrings.PAYLOAD, currentPayloads[i]);
}
builder.endObject();
@ -266,8 +266,12 @@ public class TermVectorResponse extends ActionResponse implements ToXContent {
currentEndOffset[j] = posEnum.endOffset();
}
if (curTerms.hasPayloads()) {
BytesRef curPaypoad = posEnum.getPayload();
currentPayloads[j] = new BytesArray(curPaypoad.bytes, 0, curPaypoad.length);
BytesRef curPayload = posEnum.getPayload();
if (curPayload != null) {
currentPayloads[j] = new BytesArray(curPayload.bytes, 0, curPayload.length);
} else {
currentPayloads[j] = null;
}
}
}

View File

@ -153,6 +153,8 @@ final class TermVectorWriter {
if (payload != null) {
output.writeVInt(payload.length);
output.writeBytes(payload.bytes, payload.offset, payload.length);
} else {
output.writeVInt(0);
}
}