diff options
author | Olli Virtanen <olli.virtanen@oath.com> | 2019-05-15 21:53:26 +0200 |
---|---|---|
committer | Olli Virtanen <olli.virtanen@oath.com> | 2019-05-15 21:53:26 +0200 |
commit | 2219ea79b5ac9584d503af3d6f61c859a470eb0c (patch) | |
tree | 73bf33347308d15068a075a34d748eb6d987ca55 /container-search | |
parent | 81cda304c2c58e381f334a90817dd1ea63a56fe0 (diff) |
Another null check and a minimal test
Diffstat (limited to 'container-search')
2 files changed, 35 insertions, 1 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java index 9404eb845bc..5ef4562f040 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java @@ -148,7 +148,9 @@ public class ProtobufSerialization { } MapConverter.convertMapStrings(featureMap, builder::addFeatureOverrides); MapConverter.convertMapTensors(featureMap, builder::addTensorFeatureOverrides); - MapConverter.convertStringMultiMap(query.getPresentation().getHighlight().getHighlightTerms(), builder::addHighlightTerms); + if (query.getPresentation().getHighlight() != null) { + MapConverter.convertStringMultiMap(query.getPresentation().getHighlight().getHighlightTerms(), builder::addHighlightTerms); + } mergeRankProperties(ranking, builder::addRankProperties, builder::addTensorRankProperties); } diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/ProtobufSerializationTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/rpc/ProtobufSerializationTest.java new file mode 100644 index 00000000000..3882612ddef --- /dev/null +++ b/container-search/src/test/java/com/yahoo/search/dispatch/rpc/ProtobufSerializationTest.java @@ -0,0 +1,32 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +package com.yahoo.search.dispatch.rpc; + +import com.yahoo.document.GlobalId; +import com.yahoo.document.idstring.IdString; +import com.yahoo.prelude.fastsearch.FastHit; +import com.yahoo.search.Query; +import org.junit.Test; + +import java.io.IOException; +import java.util.Collections; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + +/** + * @author ollivir + */ +public class ProtobufSerializationTest { + @Test + public void testDocsumSerialization() throws IOException { + Query q = new Query("search/?query=test&hits=10&offset=3"); + var builder = ProtobufSerialization.createDocsumRequestBuilder(q, "server", "summary", true); + builder.setTimeout(0); + var hit = new FastHit(); + hit.setGlobalId(new GlobalId(IdString.createIdString("doc:namespace:id"))); + var bytes = ProtobufSerialization.serializeDocsumRequest(builder, Collections.singletonList(hit)); + + assertThat(bytes.length, equalTo(41)); + } +} |