aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@yahooinc.com>2022-05-12 13:23:30 +0000
committerHåvard Pettersen <havardpe@yahooinc.com>2022-05-13 10:01:12 +0000
commitcd0e19b2ba89d64fa34a0c1bb5422c0a86718266 (patch)
tree95882fe50867c451f3cfb51e4df500b4b83dd7fc /searchlib/src/tests
parent8946ed0fafae193df1ae758ead1edc98bbd2b2d8 (diff)
support default tensor values for query feature
Diffstat (limited to 'searchlib/src/tests')
-rw-r--r--searchlib/src/tests/features/tensor/tensor_test.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/searchlib/src/tests/features/tensor/tensor_test.cpp b/searchlib/src/tests/features/tensor/tensor_test.cpp
index 1f9db526ec4..a8c4d6714d8 100644
--- a/searchlib/src/tests/features/tensor/tensor_test.cpp
+++ b/searchlib/src/tests/features/tensor/tensor_test.cpp
@@ -87,6 +87,10 @@ struct ExecFixture
void setQueryTensorType(const vespalib::string &queryFeatureName, const vespalib::string &type) {
type::QueryFeature::set(test.getIndexEnv().getProperties(), queryFeatureName, type);
}
+ void setQueryTensorDefault(const vespalib::string &tensorName, const vespalib::string &expr) {
+ vespalib::string key = "query(" + tensorName + ")";
+ test.getIndexEnv().getProperties().add(key, expr);
+ }
void setupAttributeVectors() {
std::vector<AttributePtr> attrs;
attrs.push_back(createTensorAttribute("tensorattr", "tensor(x{})"));
@@ -149,6 +153,8 @@ struct ExecFixture
.add({{"x", "0"},{"y", "1"}}, 13 )
.add({{"x", "1"},{"y", "0"}}, 17 )));
setQueryTensorType("null", "tensor(q{})");
+ setQueryTensorType("with_default", "tensor(x[3])");
+ setQueryTensorDefault("with_default", "tensor(x[3])(x+1)");
}
const Value &extractTensor(uint32_t docid) {
Value::CREF value = test.resolveObjectFeature(docid);
@@ -187,6 +193,15 @@ TEST_F("require that tensor from query can be extracted as tensor in query featu
.add({{"q", "e"}}, 13), spec_from_value(f.execute()));
}
+TEST_F("require that tensor from query can have default value",
+ ExecFixture("query(with_default)"))
+{
+ EXPECT_EQUAL(TensorSpec("tensor(x[3])")
+ .add({{"x", 0}}, 1)
+ .add({{"x", 1}}, 2)
+ .add({{"x", 2}}, 3), spec_from_value(f.execute()));
+}
+
TEST_F("require that empty tensor is created if attribute does not exists",
ExecFixture("attribute(null)"))
{