diff --git a/server/src/main/java/org/opensearch/search/fetch/FetchSearchResult.java b/server/src/main/java/org/opensearch/search/fetch/FetchSearchResult.java index b64638972ed49..fa8759e73cb3b 100644 --- a/server/src/main/java/org/opensearch/search/fetch/FetchSearchResult.java +++ b/server/src/main/java/org/opensearch/search/fetch/FetchSearchResult.java @@ -35,6 +35,7 @@ import org.opensearch.common.annotation.PublicApi; import org.opensearch.core.common.io.stream.StreamInput; import org.opensearch.core.common.io.stream.StreamOutput; +import org.opensearch.proto.search.fetch.FetchSearchResultProtoDef; import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; import org.opensearch.search.SearchPhaseResult; @@ -42,6 +43,9 @@ import org.opensearch.search.internal.ShardSearchContextId; import org.opensearch.search.query.QuerySearchResult; +import org.opensearch.transport.protobuf.FetchSearchResultProtobuf; +import org.opensearch.transport.protobuf.SearchHitsProtobuf; + import java.io.IOException; /** @@ -58,12 +62,33 @@ public class FetchSearchResult extends SearchPhaseResult { public FetchSearchResult() {} + //////////////////////////////////////////////// + //////////////////////////////////////////////// + //////////////////////////////////////////////// + public FetchSearchResult(StreamInput in) throws IOException { - super(in); - contextId = new ShardSearchContextId(in); - hits = new SearchHits(in); + System.out.println("FetchSearchResult In - PROTOBUF"); + FetchSearchResultProtoDef.FetchSearchResultProto proto = FetchSearchResultProtoDef.FetchSearchResultProto.parseFrom(in); + hits = new SearchHitsProtobuf(proto.getHits()); + } + + FetchSearchResultProtoDef.FetchSearchResultProto toProto() { + FetchSearchResultProtoDef.FetchSearchResultProto.Builder builder = FetchSearchResultProtoDef.FetchSearchResultProto.newBuilder() + .setHits(new SearchHitsProtobuf(hits).toProto()) + .setCounter(this.counter); + return builder.build(); } + @Override + public void writeTo(StreamOutput out) throws IOException { + System.out.println("FetchSearchResult Out - PROTOBUF"); + toProto().writeTo(out); + } + + //////////////////////////////////////////////// + //////////////////////////////////////////////// + //////////////////////////////////////////////// + public FetchSearchResult(ShardSearchContextId id, SearchShardTarget shardTarget) { this.contextId = id; setSearchShardTarget(shardTarget); @@ -103,10 +128,4 @@ public FetchSearchResult initCounter() { public int counterGetAndIncrement() { return counter++; } - - @Override - public void writeTo(StreamOutput out) throws IOException { - contextId.writeTo(out); - hits.writeTo(out); - } } diff --git a/server/src/main/java/org/opensearch/transport/protobuf/SearchHitsProtobuf.java b/server/src/main/java/org/opensearch/transport/protobuf/SearchHitsProtobuf.java index 413801c732922..560ab5560a5e8 100644 --- a/server/src/main/java/org/opensearch/transport/protobuf/SearchHitsProtobuf.java +++ b/server/src/main/java/org/opensearch/transport/protobuf/SearchHitsProtobuf.java @@ -59,7 +59,7 @@ public void fromProtobufStream(StreamInput in) throws IOException { fromProto(proto); } - SearchHitsProto toProto() { + public SearchHitsProto toProto() { SearchHitsProto.Builder builder = SearchHitsProto.newBuilder().setMaxScore(maxScore); for (SearchHit hit : hits) {