fix bug in term vector api, payloads were not handled correctly when 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 #3873
This commit is contained in:
parent
4e7a1788ea
commit
719d1e0318
|
@ -27,7 +27,6 @@ import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.RamUsageEstimator;
|
import org.apache.lucene.util.RamUsageEstimator;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.hppc.HppcMaps;
|
|
||||||
import org.elasticsearch.common.io.stream.BytesStreamInput;
|
import org.elasticsearch.common.io.stream.BytesStreamInput;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -246,7 +245,6 @@ public final class TermVectorFields extends Fields {
|
||||||
}
|
}
|
||||||
if (hasPayloads) {
|
if (hasPayloads) {
|
||||||
int payloadLength = input.readVInt();
|
int payloadLength = input.readVInt();
|
||||||
if (payloadLength > 0) {
|
|
||||||
if (payloads[i] == null) {
|
if (payloads[i] == null) {
|
||||||
payloads[i] = new BytesRef(payloadLength);
|
payloads[i] = new BytesRef(payloadLength);
|
||||||
} else {
|
} else {
|
||||||
|
@ -258,7 +256,6 @@ public final class TermVectorFields extends Fields {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void growBuffers() {
|
private void growBuffers() {
|
||||||
|
|
||||||
|
|
|
@ -246,7 +246,7 @@ public class TermVectorResponse extends ActionResponse implements ToXContent {
|
||||||
builder.field(FieldStrings.START_OFFSET, currentStartOffset[i]);
|
builder.field(FieldStrings.START_OFFSET, currentStartOffset[i]);
|
||||||
builder.field(FieldStrings.END_OFFSET, currentEndOffset[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.field(FieldStrings.PAYLOAD, currentPayloads[i]);
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
|
@ -149,7 +149,6 @@ final class TermVectorWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writePayload(BytesRef payload) throws IOException {
|
private void writePayload(BytesRef payload) throws IOException {
|
||||||
assert (payload != null);
|
|
||||||
if (payload != null) {
|
if (payload != null) {
|
||||||
output.writeVInt(payload.length);
|
output.writeVInt(payload.length);
|
||||||
output.writeBytes(payload.bytes, payload.offset, payload.length);
|
output.writeBytes(payload.bytes, payload.offset, payload.length);
|
||||||
|
|
Loading…
Reference in New Issue