summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@yahooinc.com>2023-12-06 12:41:24 +0000
committerHåvard Pettersen <havardpe@yahooinc.com>2023-12-08 13:45:27 +0000
commit94a774815c48d711ba55ea384cace396bd8d651a (patch)
treec380e8d52d7685e1ad725e0fdf0072e5e5a952e3 /searchlib/src/tests
parent8d9c697019bc52ce02001048eb263077a7c4b98e (diff)
relative estimate
Diffstat (limited to 'searchlib/src/tests')
-rw-r--r--searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp9
-rw-r--r--searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp56
-rw-r--r--searchlib/src/tests/queryeval/filter_search/filter_search_test.cpp1
-rw-r--r--searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp2
4 files changed, 62 insertions, 6 deletions
diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
index 372b76fa9af..2d621fa1011 100644
--- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
+++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
@@ -22,6 +22,7 @@ class MyOr : public IntermediateBlueprint
{
private:
public:
+ double calculate_relative_estimate() const final { return 0.5; }
HitEstimate combine(const std::vector<HitEstimate> &data) const override {
return max(data);
}
@@ -639,6 +640,7 @@ getExpectedBlueprint()
" estimate: HitEstimate {\n"
" empty: false\n"
" estHits: 9\n"
+ " relative_estimate: 0.5\n"
" cost_tier: 1\n"
" tree_size: 2\n"
" allow_termwise_eval: false\n"
@@ -658,6 +660,7 @@ getExpectedBlueprint()
" estimate: HitEstimate {\n"
" empty: false\n"
" estHits: 9\n"
+ " relative_estimate: 0.5\n"
" cost_tier: 1\n"
" tree_size: 1\n"
" allow_termwise_eval: true\n"
@@ -687,6 +690,7 @@ getExpectedSlimeBlueprint() {
" '[type]': 'HitEstimate',"
" empty: false,"
" estHits: 9,"
+ " relative_estimate: 0.5,"
" cost_tier: 1,"
" tree_size: 2,"
" allow_termwise_eval: false"
@@ -711,6 +715,7 @@ getExpectedSlimeBlueprint() {
" '[type]': 'HitEstimate',"
" empty: false,"
" estHits: 9,"
+ " relative_estimate: 0.5,"
" cost_tier: 1,"
" tree_size: 1,"
" allow_termwise_eval: true"
@@ -767,9 +772,9 @@ TEST("requireThatDocIdLimitInjectionWorks")
}
TEST("Control object sizes") {
- EXPECT_EQUAL(32u, sizeof(Blueprint::State));
+ EXPECT_EQUAL(40u, sizeof(Blueprint::State));
EXPECT_EQUAL(32u, sizeof(Blueprint));
- EXPECT_EQUAL(64u, sizeof(LeafBlueprint));
+ EXPECT_EQUAL(72u, sizeof(LeafBlueprint));
}
TEST_MAIN() {
diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
index 38e7e27163d..5078672e84e 100644
--- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
+++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
@@ -157,9 +157,9 @@ TEST("test Or propagates updated histestimate") {
EXPECT_TRUE(child.executeInfo.isStrict());
}
EXPECT_EQUAL(1.0f, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).executeInfo.hitRate());
- EXPECT_EQUAL(1.0f, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).executeInfo.hitRate());
- EXPECT_EQUAL(3.0f/5.0f, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(2)).executeInfo.hitRate());
- EXPECT_EQUAL(3.0f*42.0f/(5.0f*50.0f), dynamic_cast<const RememberExecuteInfo &>(bp->getChild(3)).executeInfo.hitRate());
+ EXPECT_APPROX(0.5f, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).executeInfo.hitRate(), 1e-6);
+ EXPECT_APPROX(0.5*3.0f/5.0f, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(2)).executeInfo.hitRate(), 1e-6);
+ EXPECT_APPROX(0.5*3.0f*42.0f/(5.0f*50.0f), dynamic_cast<const RememberExecuteInfo &>(bp->getChild(3)).executeInfo.hitRate(), 1e-6);
}
TEST("test And Blueprint") {
@@ -644,7 +644,11 @@ struct make {
child->setSourceId(source_tag);
source_tag = invalid_source;
}
- making->addChild(std::move(child));
+ if (auto *weak_and = making->asWeakAnd()) {
+ weak_and->addTerm(std::move(child), 1);
+ } else {
+ making->addChild(std::move(child));
+ }
return std::move(*this);
}
make &&leaf(uint32_t estimate) && {
@@ -661,6 +665,9 @@ struct make {
static make RANK() { return make(std::make_unique<RankBlueprint>()); }
static make ANDNOT() { return make(std::make_unique<AndNotBlueprint>()); }
static make SB(ISourceSelector &selector) { return make(std::make_unique<SourceBlenderBlueprint>(selector)); }
+ static make NEAR(uint32_t window) { return make(std::make_unique<NearBlueprint>(window)); }
+ static make ONEAR(uint32_t window) { return make(std::make_unique<ONearBlueprint>(window)); }
+ static make WEAKAND(uint32_t n) { return make(std::make_unique<WeakAndBlueprint>(n)); }
};
TEST("AND AND collapsing") {
@@ -1181,4 +1188,45 @@ TEST("require that OR blueprint use saturated sum as estimate") {
TEST_DO(verify_or_est({{100, false},{300, false},{200, false}}, {300, false}));
}
+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);
+}
+
+TEST("relative estimate for OR") {
+ verify_relative_estimate(make::OR(), 1.0-0.8*0.7*0.5);
+}
+
+TEST("relative estimate for AND") {
+ verify_relative_estimate(make::AND(), 0.2*0.3*0.5);
+}
+
+TEST("relative estimate for RANK") {
+ verify_relative_estimate(make::RANK(), 0.2);
+}
+
+TEST("relative estimate for ANDNOT") {
+ verify_relative_estimate(make::ANDNOT(), 0.2);
+}
+
+TEST("relative estimate for SB") {
+ InvalidSelector sel;
+ verify_relative_estimate(make::SB(sel), 1.0-0.8*0.7*0.5);
+}
+
+TEST("relative estimate for NEAR") {
+ verify_relative_estimate(make::NEAR(1), 0.2*0.3*0.5);
+}
+
+TEST("relative estimate for ONEAR") {
+ verify_relative_estimate(make::ONEAR(1), 0.2*0.3*0.5);
+}
+
+TEST("relative estimate for WEAKAND") {
+ verify_relative_estimate(make::WEAKAND(1000), 1.0-0.8*0.7*0.5);
+ verify_relative_estimate(make::WEAKAND(50), 0.05);
+}
+
TEST_MAIN() { TEST_DEBUG("lhs.out", "rhs.out"); TEST_RUN_ALL(); }
diff --git a/searchlib/src/tests/queryeval/filter_search/filter_search_test.cpp b/searchlib/src/tests/queryeval/filter_search/filter_search_test.cpp
index 5933122d7a2..f910ff5be1b 100644
--- a/searchlib/src/tests/queryeval/filter_search/filter_search_test.cpp
+++ b/searchlib/src/tests/queryeval/filter_search/filter_search_test.cpp
@@ -47,6 +47,7 @@ concept ChildCollector = requires(T a, std::unique_ptr<Blueprint> bp) {
// inherit Blueprint to capture the default filter factory
struct DefaultBlueprint : Blueprint {
+ double calculate_relative_estimate() const override { abort(); }
void optimize(Blueprint* &, OptimizePass) override { abort(); }
const State &getState() const override { abort(); }
void fetchPostings(const ExecuteInfo &) override { abort(); }
diff --git a/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp b/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp
index 58f22f19da1..2a59a578ec9 100644
--- a/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp
+++ b/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp
@@ -594,6 +594,7 @@ TEST_F("require that asString() on blueprint works", BlueprintAsStringFixture)
" estimate: HitEstimate {\n"
" empty: false\n"
" estHits: 2\n"
+ " relative_estimate: 0.5\n"
" cost_tier: 1\n"
" tree_size: 2\n"
" allow_termwise_eval: false\n"
@@ -616,6 +617,7 @@ TEST_F("require that asString() on blueprint works", BlueprintAsStringFixture)
" estimate: HitEstimate {\n"
" empty: false\n"
" estHits: 2\n"
+ " relative_estimate: 0.5\n"
" cost_tier: 1\n"
" tree_size: 1\n"
" allow_termwise_eval: true\n"