aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/features/ranking_expression/ranking_expression_test.cpp
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2021-05-12 10:12:27 +0000
committerHåvard Pettersen <havardpe@oath.com>2021-05-20 10:19:26 +0000
commita6babd7ec4b48975fc5d6f2994b91bf3bfd2052c (patch)
treefc7f9baeaa4bc246d748e43fc51c3d5e6d108869 /searchlib/src/tests/features/ranking_expression/ranking_expression_test.cpp
parenteeb4067cc6ab6bbd0cc03b4a9ef9eaad27677cb1 (diff)
external ranking expressions
loaded from potentially compressed files
Diffstat (limited to 'searchlib/src/tests/features/ranking_expression/ranking_expression_test.cpp')
-rw-r--r--searchlib/src/tests/features/ranking_expression/ranking_expression_test.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/searchlib/src/tests/features/ranking_expression/ranking_expression_test.cpp b/searchlib/src/tests/features/ranking_expression/ranking_expression_test.cpp
index 251040ecfa7..6baa6581edf 100644
--- a/searchlib/src/tests/features/ranking_expression/ranking_expression_test.cpp
+++ b/searchlib/src/tests/features/ranking_expression/ranking_expression_test.cpp
@@ -67,28 +67,38 @@ struct SetupResult {
RankingExpressionBlueprint rank;
DummyDependencyHandler deps;
bool setup_ok;
- SetupResult(const TypeMap &object_inputs, const vespalib::string &expression);
+ SetupResult(const TypeMap &object_inputs, const vespalib::string &expression,
+ bool external_expression = false);
~SetupResult();
};
SetupResult::SetupResult(const TypeMap &object_inputs,
- const vespalib::string &expression)
+ const vespalib::string &expression,
+ bool external_expression)
: stash(), index_env(), query_env(&index_env), rank(make_replacer()), deps(rank), setup_ok(false)
{
rank.setName("self");
- index_env.getProperties().add("self.rankingScript", expression);
for (const auto &input: object_inputs) {
deps.define_object_input(input.first, ValueType::from_spec(input.second));
}
- setup_ok = rank.setup(index_env, {});
+ std::vector<vespalib::string> params;
+ if (external_expression) {
+ params.push_back("my_expr");
+ index_env.addRankingExpression("my_expr", expression);
+ } else {
+ index_env.getProperties().add("self.rankingScript", expression);
+ }
+ Blueprint &bp = rank;
+ setup_ok = bp.setup(index_env, params);
EXPECT_TRUE(!deps.accept_type_mismatch);
}
SetupResult::~SetupResult() = default;
void verify_output_type(const TypeMap &object_inputs,
- const vespalib::string &expression, const FeatureType &expect)
+ const vespalib::string &expression, const FeatureType &expect,
+ bool external_expression = false)
{
- SetupResult result(object_inputs, expression);
+ SetupResult result(object_inputs, expression, external_expression);
EXPECT_TRUE(result.setup_ok);
EXPECT_EQUAL(1u, result.deps.output.size());
ASSERT_EQUAL(1u, result.deps.output_type.size());
@@ -126,6 +136,13 @@ TEST("require that ranking expression can resolve to concrete complex type") {
FeatureType::object(ValueType::from_spec("tensor(x{},y{},z{})"))));
}
+TEST("require that ranking expression can be external") {
+ TEST_DO(verify_output_type({}, "a*b", FeatureType::number(), true));
+ TEST_DO(verify_output_type({{"b", "double"}}, "a*b", FeatureType::object(ValueType::double_type()), true));
+ TEST_DO(verify_output_type({{"a", "tensor(x{},y{})"}, {"b", "tensor(y{},z{})"}}, "a*b",
+ FeatureType::object(ValueType::from_spec("tensor(x{},y{},z{})")), true));
+}
+
TEST("require that setup fails for incompatible types") {
TEST_DO(verify_setup_fail({{"a", "tensor(x{},y{})"}, {"b", "tensor(y[10],z{})"}}, "a*b"));
}