From 6643f031721f2125ec12984bf951add27d5f48e4 Mon Sep 17 00:00:00 2001 From: Håvard Pettersen Date: Fri, 5 Jan 2024 15:28:37 +0000 Subject: take strictness into account for flow/cost/sorting use common code with adapters make cost calculation const (sort index, not children) empty AND/ANDNOT estimate now equals input flow --- searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp | 4 ++-- .../src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'searchlib/src/tests/queryeval/blueprint') diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp index f800e124bdc..bbd2744119a 100644 --- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp @@ -24,10 +24,10 @@ class MyOr : public IntermediateBlueprint private: public: double calculate_cost() const final { - return cost_of(get_children(), OrFlow()); + return OrFlow::cost_of(get_children()); } double calculate_relative_estimate() const final { - return estimate_of(get_children(), OrFlow()); + return OrFlow::estimate_of(get_children()); } HitEstimate combine(const std::vector &data) const override { return max(data); diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp index ab1c004c721..ed2bfdeca6f 100644 --- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp @@ -1289,7 +1289,6 @@ 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); @@ -1380,7 +1379,7 @@ TEST("cost for ONEAR") { } TEST("cost for WEAKAND") { - verify_cost(make::WEAKAND(1000), calc_cost({{1.1, 0.8},{1.2, 0.7},{1.3, 0.5}})); + verify_cost(make::WEAKAND(1000), calc_cost({{1.3, 0.5},{1.2, 0.7},{1.1, 0.8}})); } TEST_MAIN() { TEST_DEBUG("lhs.out", "rhs.out"); TEST_RUN_ALL(); } -- cgit v1.2.3 From 7a8871c3b9259d05e5cf606e943d69e0e7a160fe Mon Sep 17 00:00:00 2001 From: Håvard Pettersen Date: Mon, 15 Jan 2024 18:16:03 +0000 Subject: make sure empty AND/OR/ANDNOT flow estimates 0.0 regardless of input flow --- .../tests/queryeval/blueprint/intermediate_blueprints_test.cpp | 1 + searchlib/src/tests/queryeval/flow/queryeval_flow_test.cpp | 6 +++--- searchlib/src/vespa/searchlib/queryeval/flow.h | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'searchlib/src/tests/queryeval/blueprint') 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(adapter, children); @@ -200,11 +200,13 @@ class OrFlow : public FlowMixin{ 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(adapter, children, 1); -- cgit v1.2.3