diff options
author | Håvard Pettersen <havardpe@yahooinc.com> | 2024-01-15 18:16:03 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@yahooinc.com> | 2024-01-15 18:16:03 +0000 |
commit | 7a8871c3b9259d05e5cf606e943d69e0e7a160fe (patch) | |
tree | 53f7593b56d9bb16e4ab26bd3959f2e6632be447 | |
parent | 6643f031721f2125ec12984bf951add27d5f48e4 (diff) |
make sure empty AND/OR/ANDNOT flow estimates 0.0 regardless of input flow
3 files changed, 10 insertions, 7 deletions
diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp index ed2bfdeca6f..856ac2391f8 100644 --- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp @@ -1289,6 +1289,7 @@ TEST("require that OR blueprint use saturated sum as estimate") { } void verify_relative_estimate(make &&mk, double expect) { + EXPECT_EQUAL(mk.making->estimate(), 0.0); Blueprint::UP bp = std::move(mk).leafs({200,300,950}); bp->setDocIdLimit(1000); EXPECT_EQUAL(bp->estimate(), expect); diff --git a/searchlib/src/tests/queryeval/flow/queryeval_flow_test.cpp b/searchlib/src/tests/queryeval/flow/queryeval_flow_test.cpp index c92f85357b5..9a9adeac2bc 100644 --- a/searchlib/src/tests/queryeval/flow/queryeval_flow_test.cpp +++ b/searchlib/src/tests/queryeval/flow/queryeval_flow_test.cpp @@ -156,7 +156,7 @@ TEST(FlowTest, basic_and_flow) { for (double in: {1.0, 0.5, 0.25}) { for (bool strict: {false, true}) { verify_flow(AndFlow(in, strict), {0.4, 0.7, 0.2}, - {{in, in, strict}, + {{in, 0.0, strict}, {in*0.4, in*0.4, false}, {in*0.4*0.7, in*0.4*0.7, false}, {in*0.4*0.7*0.2, in*0.4*0.7*0.2, false}}); @@ -168,7 +168,7 @@ TEST(FlowTest, basic_or_flow) { for (double in: {1.0, 0.5, 0.25}) { for (bool strict: {false, true}) { verify_flow(OrFlow(in, strict), {0.4, 0.7, 0.2}, - {{in, 1.0-in, strict}, + {{in, 0.0, strict}, {in*0.6, 1.0-in*0.6, strict}, {in*0.6*0.3, 1.0-in*0.6*0.3, strict}, {in*0.6*0.3*0.8, 1.0-in*0.6*0.3*0.8, strict}}); @@ -180,7 +180,7 @@ TEST(FlowTest, basic_and_not_flow) { for (double in: {1.0, 0.5, 0.25}) { for (bool strict: {false, true}) { verify_flow(AndNotFlow(in, strict), {0.4, 0.7, 0.2}, - {{in, in, strict}, + {{in, 0.0, strict}, {in*0.4, in*0.4, false}, {in*0.4*0.3, in*0.4*0.3, false}, {in*0.4*0.3*0.8, in*0.4*0.3*0.8, false}}); diff --git a/searchlib/src/vespa/searchlib/queryeval/flow.h b/searchlib/src/vespa/searchlib/queryeval/flow.h index d711cd74221..86ce6f8b93b 100644 --- a/searchlib/src/vespa/searchlib/queryeval/flow.h +++ b/searchlib/src/vespa/searchlib/queryeval/flow.h @@ -177,7 +177,7 @@ public: return _strict && _first; } double estimate() const noexcept { - return _flow; + return _first ? 0.0 : _flow; } static void sort(auto adapter, auto &children, bool strict) { flow::sort<flow::MinAndCost>(adapter, children); @@ -200,11 +200,13 @@ class OrFlow : public FlowMixin<OrFlow>{ private: double _flow; bool _strict; + bool _first; public: OrFlow(double in, bool strict) noexcept - : _flow(in), _strict(strict) {} + : _flow(in), _strict(strict), _first(true) {} void add(double est) noexcept { _flow *= (1.0 - est); + _first = false; } double flow() const noexcept { return _flow; @@ -213,7 +215,7 @@ public: return _strict; } double estimate() const noexcept { - return (1.0 - _flow); + return _first ? 0.0 : (1.0 - _flow); } static void sort(auto adapter, auto &children, bool strict) { if (strict) { @@ -247,7 +249,7 @@ public: return _strict && _first; } double estimate() const noexcept { - return _flow; + return _first ? 0.0 : _flow; } static void sort(auto adapter, auto &children, bool) { flow::sort_partial<flow::MinOrCost>(adapter, children, 1); |