summaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/matching
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahooinc.com>2022-01-13 14:24:23 +0000
committerArne H Juul <arnej@yahooinc.com>2022-01-13 14:24:23 +0000
commitfadbc04edb6d32693def55c9aef2fd28cc5ef6dd (patch)
tree7b0946a00c9efa3e16e3a1f5d9427582c4b20e20 /searchcore/src/tests/proton/matching
parent6b41f3777adf98b25b75d83e60358b3cc51d0531 (diff)
remap feature names
* in ExtractFeatures, map the names of match and summary features according to the rename mapping exposed from RankSetup.
Diffstat (limited to 'searchcore/src/tests/proton/matching')
-rw-r--r--searchcore/src/tests/proton/matching/matching_test.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/searchcore/src/tests/proton/matching/matching_test.cpp b/searchcore/src/tests/proton/matching/matching_test.cpp
index 1123871b91e..09bb67dbac9 100644
--- a/searchcore/src/tests/proton/matching/matching_test.cpp
+++ b/searchcore/src/tests/proton/matching/matching_test.cpp
@@ -220,6 +220,13 @@ struct MyWorld {
config.add(indexproperties::match::Feature::NAME, "rankingExpression(\"tensor(x[3])(x)\")");
}
+ void setup_feature_renames() {
+ config.add(indexproperties::feature_rename::Rename::NAME, "matches(f1)");
+ config.add(indexproperties::feature_rename::Rename::NAME, "foobar");
+ config.add(indexproperties::feature_rename::Rename::NAME, "rankingExpression(\"tensor(x[3])(x)\")");
+ config.add(indexproperties::feature_rename::Rename::NAME, "tensor(x[3])(x)");
+ }
+
static void verify_match_features(SearchReply &reply, const vespalib::string &matched_field) {
if (reply.hits.empty()) {
EXPECT_EQUAL(reply.match_features.names.size(), 0u);
@@ -251,6 +258,23 @@ struct MyWorld {
}
}
+ static void verify_match_feature_renames(SearchReply &reply, const vespalib::string &matched_field) {
+ if (reply.hits.empty()) {
+ EXPECT_EQUAL(reply.match_features.names.size(), 0u);
+ EXPECT_EQUAL(reply.match_features.values.size(), 0u);
+ } else {
+ ASSERT_EQUAL(reply.match_features.names.size(), 5u);
+ EXPECT_EQUAL(reply.match_features.names[3], "foobar");
+ EXPECT_EQUAL(reply.match_features.names[4], "tensor(x[3])(x)");
+ ASSERT_EQUAL(reply.match_features.values.size(), 5 * reply.hits.size());
+ for (size_t i = 0; i < reply.hits.size(); ++i) {
+ const auto *f = &reply.match_features.values[i * 5];
+ EXPECT_EQUAL(f[3].as_double(), double(matched_field == "f1"));
+ EXPECT_TRUE(f[4].is_data());
+ }
+ }
+ }
+
void setup_match_phase_limiting(const vespalib::string &attribute, size_t max_hits, bool descending)
{
inject_match_phase_limiting(config, attribute, max_hits, descending);
@@ -495,6 +519,18 @@ TEST("require that match features are calculated (multi-threaded)") {
}
}
+TEST("require that match features can be renamed") {
+ MyWorld world;
+ world.basicSetup();
+ world.basicResults();
+ world.setup_match_features();
+ world.setup_feature_renames();
+ SearchRequest::SP request = world.createSimpleRequest("f1", "spread");
+ SearchReply::UP reply = world.performSearch(request, 1);
+ EXPECT_GREATER(reply->hits.size(), 0u);
+ world.verify_match_feature_renames(*reply, "f1");
+}
+
TEST("require that no hits gives no match feature names") {
MyWorld world;
world.basicSetup();
@@ -782,6 +818,26 @@ TEST("require that search session can be cached") {
EXPECT_EQUAL("a", session->getSessionId());
}
+TEST("require that summary features can be renamed") {
+ MyWorld world;
+ world.basicSetup();
+ world.setup_feature_renames();
+ world.basicResults();
+ DocsumRequest::SP req = world.createSimpleDocsumRequest("f1", "foo");
+ FeatureSet::SP fs = world.getSummaryFeatures(req);
+ const FeatureSet::Value * f = nullptr;
+ EXPECT_EQUAL(5u, fs->numFeatures());
+ EXPECT_EQUAL("attribute(a1)", fs->getNames()[0]);
+ EXPECT_EQUAL("foobar", fs->getNames()[1]);
+ EXPECT_EQUAL("rankingExpression(\"reduce(tensor(x[3])(x),sum)\")", fs->getNames()[2]);
+ EXPECT_EQUAL("tensor(x[3])(x)", fs->getNames()[3]);
+ EXPECT_EQUAL(3u, fs->numDocs());
+ f = fs->getFeaturesByDocId(30);
+ EXPECT_TRUE(f != nullptr);
+ EXPECT_TRUE(f[2].is_double());
+ EXPECT_TRUE(f[3].is_data());
+}
+
TEST("require that getSummaryFeatures can use cached query setup") {
MyWorld world;
world.basicSetup();