diff options
author | Håvard Pettersen <havardpe@oath.com> | 2021-05-12 10:12:27 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2021-05-20 10:19:26 +0000 |
commit | a6babd7ec4b48975fc5d6f2994b91bf3bfd2052c (patch) | |
tree | fc7f9baeaa4bc246d748e43fc51c3d5e6d108869 /searchcore/src/tests/proton/verify_ranksetup | |
parent | eeb4067cc6ab6bbd0cc03b4a9ef9eaad27677cb1 (diff) |
external ranking expressions
loaded from potentially compressed files
Diffstat (limited to 'searchcore/src/tests/proton/verify_ranksetup')
3 files changed, 38 insertions, 0 deletions
diff --git a/searchcore/src/tests/proton/verify_ranksetup/bad_ranking_expression b/searchcore/src/tests/proton/verify_ranksetup/bad_ranking_expression new file mode 100644 index 00000000000..475b311dc84 --- /dev/null +++ b/searchcore/src/tests/proton/verify_ranksetup/bad_ranking_expression @@ -0,0 +1 @@ +join(constant(my_tensor),attribute(date),f(t,d)(join(t,d,f(x,y)(x+y)))) diff --git a/searchcore/src/tests/proton/verify_ranksetup/good_ranking_expression b/searchcore/src/tests/proton/verify_ranksetup/good_ranking_expression new file mode 100644 index 00000000000..f6712be7a82 --- /dev/null +++ b/searchcore/src/tests/proton/verify_ranksetup/good_ranking_expression @@ -0,0 +1 @@ +join(constant(my_tensor),attribute(date),f(t,d)(t+d)) diff --git a/searchcore/src/tests/proton/verify_ranksetup/verify_ranksetup_test.cpp b/searchcore/src/tests/proton/verify_ranksetup/verify_ranksetup_test.cpp index c46990732b7..31557f13a54 100644 --- a/searchcore/src/tests/proton/verify_ranksetup/verify_ranksetup_test.cpp +++ b/searchcore/src/tests/proton/verify_ranksetup/verify_ranksetup_test.cpp @@ -71,6 +71,7 @@ struct Setup { std::map<std::string,std::string> properties; std::map<std::string,std::string> constants; std::vector<bool> extra_profiles; + std::map<std::string,std::string> ranking_expressions; std::map<std::string,OnnxModel> onnx_models; Setup(); ~Setup(); @@ -96,6 +97,9 @@ struct Setup { void rank_expr(const std::string &name, const std::string &expr) { property(fmt("rankingExpression(%s).rankingScript", name.c_str()), expr); } + void ext_rank_expr(const std::string &name, const std::string &file) { + ranking_expressions.insert_or_assign(name, TEST_PATH(file)); + } void first_phase(const std::string &feature) { property(rank::FirstPhase::NAME, feature); } @@ -157,6 +161,14 @@ struct Setup { ++idx; } } + void write_ranking_expressions(const Writer &out) { + size_t idx = 0; + for (const auto &entry: ranking_expressions) { + out.fmt("expression[%zu].name \"%s\"\n", idx, entry.first.c_str()); + out.fmt("expression[%zu].fileref \"expr_ref_%zu\"\n", idx, idx); + ++idx; + } + } void write_onnx_models(const Writer &out) { size_t idx = 0; for (const auto &entry: onnx_models) { @@ -179,6 +191,12 @@ struct Setup { } void write_self_cfg(const Writer &out) { size_t idx = 0; + for (const auto &entry: ranking_expressions) { + out.fmt("file[%zu].ref \"expr_ref_%zu\"\n", idx, idx); + out.fmt("file[%zu].path \"%s\"\n", idx, entry.second.c_str()); + ++idx; + } + idx = 0; for (const auto &entry: onnx_models) { out.fmt("file[%zu].ref \"onnx_ref_%zu\"\n", idx, idx); out.fmt("file[%zu].path \"%s\"\n", idx, entry.second.file_path().c_str()); @@ -190,6 +208,7 @@ struct Setup { write_indexschema(Writer(gen_dir + "/indexschema.cfg")); write_rank_profiles(Writer(gen_dir + "/rank-profiles.cfg")); write_ranking_constants(Writer(gen_dir + "/ranking-constants.cfg")); + write_ranking_expressions(Writer(gen_dir + "/ranking-expressions.cfg")); write_onnx_models(Writer(gen_dir + "/onnx-models.cfg")); write_self_cfg(Writer(gen_dir + "/verify-ranksetup.cfg")); } @@ -358,6 +377,23 @@ TEST_F("require that imported attribute field can be used by rank feature", Simp //----------------------------------------------------------------------------- +TEST_F("require that external ranking expression can be verified", SimpleSetup()) { + f.ext_rank_expr("my_expr", "good_ranking_expression"); + f.verify_valid({"rankingExpression(my_expr)"}); +} + +TEST_F("require that external ranking expression can fail verification", SimpleSetup()) { + f.ext_rank_expr("my_expr", "bad_ranking_expression"); + f.verify_invalid({"rankingExpression(my_expr)"}); +} + +TEST_F("require that missing expression file fails verification", SimpleSetup()) { + f.ext_rank_expr("my_expr", "missing_ranking_expression_file"); + f.verify_invalid({"rankingExpression(my_expr)"}); +} + +//----------------------------------------------------------------------------- + TEST_F("require that onnx model can be verified", OnnxSetup()) { f.rank_expr("query_tensor", "tensor<float>(a[1],b[4]):[[1,2,3,4]]"); f.rank_expr("attribute_tensor", "tensor<float>(a[4],b[1]):[[5],[6],[7],[8]]"); |