summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2021-11-05 11:52:11 +0000
committerHåvard Pettersen <havardpe@oath.com>2021-11-05 11:52:11 +0000
commit4ddf77357c15153ddc19f3ec0b7bddba2aa82620 (patch)
tree73cc34550e4f64a58c37e87f5b089627747335b1
parentd180ceae0bf8f782aa0c3f27ab65c2ae0ef052b9 (diff)
test conversion of match features to protobuf reply
-rw-r--r--searchlib/src/tests/engine/proto_converter/proto_converter_test.cpp128
1 files changed, 79 insertions, 49 deletions
diff --git a/searchlib/src/tests/engine/proto_converter/proto_converter_test.cpp b/searchlib/src/tests/engine/proto_converter/proto_converter_test.cpp
index 132c020bb8a..093e7831ad4 100644
--- a/searchlib/src/tests/engine/proto_converter/proto_converter_test.cpp
+++ b/searchlib/src/tests/engine/proto_converter/proto_converter_test.cpp
@@ -26,7 +26,17 @@ using vespalib::slime::BinaryFormat;
//-----------------------------------------------------------------------------
-struct SearchRequestTest : ::testing::Test {
+struct ProtoConverterTest : ::testing::Test {
+ static constexpr size_t gid_len = document::GlobalId::LENGTH;
+ char id0[gid_len] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12};
+ char id1[gid_len] = {11,12,13,14,15,16,17,18,19,20,21,22};
+ char id2[gid_len] = {21,22,23,24,25,26,27,28,29,30,31,32};
+ static_assert(gid_len == 12);
+};
+
+//-----------------------------------------------------------------------------
+
+struct SearchRequestTest : ProtoConverterTest {
Converter::ProtoSearchRequest proto;
SearchRequest request;
void convert() { Converter::search_request_from_proto(proto, request); }
@@ -179,9 +189,36 @@ TEST_F(SearchRequestTest, require_that_query_tree_blob_is_converted) {
//-----------------------------------------------------------------------------
-struct SearchReplyTest : ::testing::Test {
+struct SearchReplyTest : ProtoConverterTest {
SearchReply reply;
Converter::ProtoSearchReply proto;
+ void fill_hits() {
+ reply.hits.resize(3);
+ reply.hits[0].gid = document::GlobalId(id0);
+ reply.hits[0].metric = 100.0;
+ reply.hits[1].gid = document::GlobalId(id1);
+ reply.hits[1].metric = 50.0;
+ reply.hits[2].gid = document::GlobalId(id2);
+ reply.hits[2].metric = 10.0;
+ }
+ void fill_sort_data() {
+ vespalib::string sort_data("fooxybar");
+ reply.sortData.assign(sort_data.begin(), sort_data.end());
+ reply.sortIndex.push_back(0);
+ reply.sortIndex.push_back(3); // hit1: 'foo'
+ reply.sortIndex.push_back(5); // hit2: 'xy'
+ reply.sortIndex.push_back(8); // hit3: 'bar'
+ }
+ void fill_match_features() {
+ reply.match_features.names = {"my_double", "my_data"};
+ reply.match_features.values.resize(2 * 3);
+ reply.match_features.values[0].set_double(10);
+ reply.match_features.values[1].set_data("data1");
+ reply.match_features.values[2].set_double(20);
+ reply.match_features.values[3].set_data("data2");
+ reply.match_features.values[4].set_double(30);
+ reply.match_features.values[5].set_data("data3");
+ }
void convert() { Converter::search_reply_to_proto(reply, proto); }
};
@@ -232,63 +269,61 @@ TEST_F(SearchReplyTest, require_that_multiple_degraded_reasons_are_converted) {
}
TEST_F(SearchReplyTest, require_that_hits_are_converted) {
- constexpr size_t len = document::GlobalId::LENGTH;
- ASSERT_EQ(len, 12);
- char id0[len] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12};
- char id1[len] = {11,12,13,14,15,16,17,18,19,20,21,22};
- char id2[len] = {21,22,23,24,25,26,27,28,29,30,31,32};
- reply.hits.resize(3);
- reply.hits[0].gid = document::GlobalId(id0);
- reply.hits[0].metric = 100.0;
- reply.hits[1].gid = document::GlobalId(id1);
- reply.hits[1].metric = 50.0;
- reply.hits[2].gid = document::GlobalId(id2);
- reply.hits[2].metric = 10.0;
+ fill_hits();
convert();
ASSERT_EQ(proto.hits_size(), 3);
- EXPECT_EQ(proto.hits(0).global_id(), std::string(id0, len));
+ EXPECT_EQ(proto.hits(0).global_id(), std::string(id0, gid_len));
EXPECT_EQ(proto.hits(0).relevance(), 100.0);
EXPECT_TRUE(proto.hits(0).sort_data().empty());
- EXPECT_EQ(proto.hits(1).global_id(), std::string(id1, len));
+ EXPECT_EQ(proto.hits(1).global_id(), std::string(id1, gid_len));
EXPECT_EQ(proto.hits(1).relevance(), 50.0);
EXPECT_TRUE(proto.hits(1).sort_data().empty());
- EXPECT_EQ(proto.hits(2).global_id(), std::string(id2, len));
+ EXPECT_EQ(proto.hits(2).global_id(), std::string(id2, gid_len));
EXPECT_EQ(proto.hits(2).relevance(), 10.0);
EXPECT_TRUE(proto.hits(2).sort_data().empty());
}
TEST_F(SearchReplyTest, require_that_hits_with_sort_data_are_converted) {
- constexpr size_t len = document::GlobalId::LENGTH;
- ASSERT_EQ(len, 12);
- char id0[len] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12};
- char id1[len] = {11,12,13,14,15,16,17,18,19,20,21,22};
- char id2[len] = {21,22,23,24,25,26,27,28,29,30,31,32};
- reply.hits.resize(3);
- reply.hits[0].gid = document::GlobalId(id0);
- reply.hits[0].metric = 100.0;
- reply.hits[1].gid = document::GlobalId(id1);
- reply.hits[1].metric = 50.0;
- reply.hits[2].gid = document::GlobalId(id2);
- reply.hits[2].metric = 10.0;
- vespalib::string sort_data("fooxybar");
- reply.sortData.assign(sort_data.begin(), sort_data.end());
- reply.sortIndex.push_back(0);
- reply.sortIndex.push_back(3); // hit1: 'foo'
- reply.sortIndex.push_back(5); // hit2: 'xy'
- reply.sortIndex.push_back(8); // hit3: 'bar'
+ fill_hits();
+ fill_sort_data();
convert();
ASSERT_EQ(proto.hits_size(), 3);
- EXPECT_EQ(proto.hits(0).global_id(), std::string(id0, len));
+ EXPECT_EQ(proto.hits(0).global_id(), std::string(id0, gid_len));
EXPECT_EQ(proto.hits(0).relevance(), 100.0);
EXPECT_EQ(proto.hits(0).sort_data(), "foo");
- EXPECT_EQ(proto.hits(1).global_id(), std::string(id1, len));
+ EXPECT_EQ(proto.hits(1).global_id(), std::string(id1, gid_len));
EXPECT_EQ(proto.hits(1).relevance(), 50.0);
EXPECT_EQ(proto.hits(1).sort_data(), "xy");
- EXPECT_EQ(proto.hits(2).global_id(), std::string(id2, len));
+ EXPECT_EQ(proto.hits(2).global_id(), std::string(id2, gid_len));
EXPECT_EQ(proto.hits(2).relevance(), 10.0);
EXPECT_EQ(proto.hits(2).sort_data(), "bar");
}
+TEST_F(SearchReplyTest, require_that_match_features_are_converted) {
+ fill_hits();
+ fill_match_features();
+ convert();
+ ASSERT_EQ(proto.match_feature_names_size(), 2);
+ EXPECT_EQ(proto.match_feature_names(0), "my_double");
+ EXPECT_EQ(proto.match_feature_names(1), "my_data");
+ ASSERT_EQ(proto.hits_size(), 3);
+ ASSERT_EQ(proto.hits(0).match_features_size(), 2);
+ EXPECT_EQ(proto.hits(0).match_features(0).number(), 10.0);
+ EXPECT_EQ(proto.hits(0).match_features(0).tensor(), "");
+ EXPECT_EQ(proto.hits(0).match_features(1).number(), 0.0);
+ EXPECT_EQ(proto.hits(0).match_features(1).tensor(), "data1");
+ ASSERT_EQ(proto.hits(1).match_features_size(), 2);
+ EXPECT_EQ(proto.hits(1).match_features(0).number(), 20.0);
+ EXPECT_EQ(proto.hits(1).match_features(0).tensor(), "");
+ EXPECT_EQ(proto.hits(1).match_features(1).number(), 0.0);
+ EXPECT_EQ(proto.hits(1).match_features(1).tensor(), "data2");
+ ASSERT_EQ(proto.hits(2).match_features_size(), 2);
+ EXPECT_EQ(proto.hits(2).match_features(0).number(), 30.0);
+ EXPECT_EQ(proto.hits(2).match_features(0).tensor(), "");
+ EXPECT_EQ(proto.hits(2).match_features(1).number(), 0.0);
+ EXPECT_EQ(proto.hits(2).match_features(1).tensor(), "data3");
+}
+
TEST_F(SearchReplyTest, require_that_grouping_blob_is_converted) {
vespalib::string tmp("grouping-result");
reply.groupResult.assign(tmp.begin(), tmp.end());
@@ -318,7 +353,7 @@ TEST_F(SearchReplyTest, require_that_issues_are_converted_to_errors) {
//-----------------------------------------------------------------------------
-struct DocsumRequestTest : ::testing::Test {
+struct DocsumRequestTest : ProtoConverterTest {
Converter::ProtoDocsumRequest proto;
DocsumRequest request;
DocsumRequestTest() : proto(), request() {}
@@ -460,14 +495,9 @@ TEST_F(DocsumRequestTest, require_that_query_tree_blob_is_converted) {
}
TEST_F(DocsumRequestTest, require_that_global_ids_are_converted) {
- constexpr size_t len = document::GlobalId::LENGTH;
- ASSERT_EQ(len, 12);
- char id0[len] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12};
- char id1[len] = {11,12,13,14,15,16,17,18,19,20,21,22};
- char id2[len] = {21,22,23,24,25,26,27,28,29,30,31,32};
- proto.add_global_ids(id0, len);
- proto.add_global_ids(id1, len);
- proto.add_global_ids(id2, len);
+ proto.add_global_ids(id0, gid_len);
+ proto.add_global_ids(id1, gid_len);
+ proto.add_global_ids(id2, gid_len);
convert();
ASSERT_EQ(request.hits.size(), 3);
EXPECT_EQ(request.hits[0].gid, document::GlobalId(id0));
@@ -477,7 +507,7 @@ TEST_F(DocsumRequestTest, require_that_global_ids_are_converted) {
//-----------------------------------------------------------------------------
-struct DocsumReplyTest : ::testing::Test {
+struct DocsumReplyTest : ProtoConverterTest {
Slime &slime;
DocsumReply reply;
Converter::ProtoDocsumReply proto;
@@ -522,7 +552,7 @@ TEST_F(DocsumReplyTest, require_that_issues_are_converted_to_errors) {
//-----------------------------------------------------------------------------
-struct MonitorReplyTest : ::testing::Test {
+struct MonitorReplyTest : ProtoConverterTest {
MonitorReply reply;
Converter::ProtoMonitorReply proto;
void convert() { Converter::monitor_reply_to_proto(reply, proto); }