parent
edf1c82007
commit
c7c120c781
|
@ -165,7 +165,7 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
|
|||
}
|
||||
highlightBuilder = in.readOptionalWriteable(HighlightBuilder::new);
|
||||
query = in.readQuery();
|
||||
innerHitsBuilder = in.readOptionalWriteable(InnerHitsBuilder.PROTO::readFrom);
|
||||
innerHitsBuilder = in.readOptionalWriteable(InnerHitsBuilder::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -433,11 +433,6 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
|
|||
innerHits.setChildInnerHits(childInnerHits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InnerHitBuilder readFrom(StreamInput in) throws IOException {
|
||||
return new InnerHitBuilder(in);
|
||||
}
|
||||
|
||||
private void setupInnerHitsContext(QueryShardContext context, InnerHitsContext.BaseInnerHits innerHitsContext) throws IOException {
|
||||
innerHitsContext.from(from);
|
||||
innerHitsContext.size(size);
|
||||
|
|
|
@ -29,15 +29,11 @@ import org.elasticsearch.common.xcontent.XContentParser.Token;
|
|||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class InnerHitsBuilder extends ToXContentToBytes implements Writeable<InnerHitsBuilder> {
|
||||
|
||||
public final static InnerHitsBuilder PROTO = new InnerHitsBuilder(Collections.emptyMap());
|
||||
|
||||
private final Map<String, InnerHitBuilder> innerHitsBuilders;
|
||||
|
||||
public InnerHitsBuilder() {
|
||||
|
@ -48,6 +44,26 @@ public final class InnerHitsBuilder extends ToXContentToBytes implements Writeab
|
|||
this.innerHitsBuilders = Objects.requireNonNull(innerHitsBuilders);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public InnerHitsBuilder(StreamInput in) throws IOException {
|
||||
int size = in.readVInt();
|
||||
innerHitsBuilders = new HashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
innerHitsBuilders.put(in.readString(), new InnerHitBuilder(in));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(innerHitsBuilders.size());
|
||||
for (Map.Entry<String, InnerHitBuilder> entry : innerHitsBuilders.entrySet()) {
|
||||
out.writeString(entry.getKey());
|
||||
entry.getValue().writeTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
public InnerHitsBuilder addInnerHit(String name, InnerHitBuilder builder) {
|
||||
Objects.requireNonNull(name);
|
||||
Objects.requireNonNull(builder);
|
||||
|
@ -59,16 +75,6 @@ public final class InnerHitsBuilder extends ToXContentToBytes implements Writeab
|
|||
return innerHitsBuilders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InnerHitsBuilder readFrom(StreamInput in) throws IOException {
|
||||
int size = in.readVInt();
|
||||
Map<String, InnerHitBuilder> innerHitsBuilders = new HashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
innerHitsBuilders.put(in.readString(), new InnerHitBuilder(in));
|
||||
}
|
||||
return new InnerHitsBuilder(innerHitsBuilders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
|
@ -79,15 +85,6 @@ public final class InnerHitsBuilder extends ToXContentToBytes implements Writeab
|
|||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(innerHitsBuilders.size());
|
||||
for (Map.Entry<String, InnerHitBuilder> entry : innerHitsBuilders.entrySet()) {
|
||||
out.writeString(entry.getKey());
|
||||
entry.getValue().writeTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -211,7 +211,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
|
|||
}
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
innerHitsBuilder = InnerHitsBuilder.PROTO.readFrom(in);
|
||||
innerHitsBuilder = new InnerHitsBuilder(in);
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
minScore = in.readFloat();
|
||||
|
|
|
@ -132,7 +132,7 @@ public class InnerHitsBuilderTests extends ESTestCase {
|
|||
try (BytesStreamOutput output = new BytesStreamOutput()) {
|
||||
original.writeTo(output);
|
||||
try (StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) {
|
||||
return InnerHitsBuilder.PROTO.readFrom(in);
|
||||
return new InnerHitsBuilder(in);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue