diff options
Diffstat (limited to 'searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp')
-rw-r--r-- | searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp | 285 |
1 files changed, 172 insertions, 113 deletions
diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp index a663944938c..51e22dbcf2c 100644 --- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp @@ -8,7 +8,6 @@ #include <vespa/searchlib/queryeval/leaf_blueprints.h> #include <vespa/searchlib/queryeval/equiv_blueprint.h> #include <vespa/searchlib/queryeval/multisearch.h> -#include <vespa/searchlib/queryeval/andnotsearch.h> #include <vespa/searchlib/queryeval/wand/weak_and_search.h> #include <vespa/searchlib/queryeval/fake_requestcontext.h> #include <vespa/searchlib/test/diskindex/testdiskindex.h> @@ -74,13 +73,13 @@ TEST("test AndNot Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); } @@ -120,12 +119,14 @@ TEST("test And propagates updated histestimate") { bp.addChild(ap(MyLeafSpec(20).create<RememberExecuteInfo>()->setSourceId(2))); bp.addChild(ap(MyLeafSpec(200).create<RememberExecuteInfo>()->setSourceId(2))); bp.addChild(ap(MyLeafSpec(2000).create<RememberExecuteInfo>()->setSourceId(2))); - bp.optimize_self(); + bp.optimize_self(Blueprint::OptimizePass::FIRST); + bp.optimize_self(Blueprint::OptimizePass::SECOND); + bp.optimize_self(Blueprint::OptimizePass::LAST); bp.setDocIdLimit(5000); bp.fetchPostings(ExecuteInfo::TRUE); EXPECT_EQUAL(3u, bp.childCnt()); for (uint32_t i = 0; i < bp.childCnt(); i++) { - const RememberExecuteInfo & child = dynamic_cast<const RememberExecuteInfo &>(bp.getChild(i)); + const auto & child = dynamic_cast<const RememberExecuteInfo &>(bp.getChild(i)); EXPECT_EQUAL((i == 0), child.executeInfo.isStrict()); } EXPECT_EQUAL(1.0f, dynamic_cast<const RememberExecuteInfo &>(bp.getChild(0)).executeInfo.hitRate()); @@ -133,22 +134,45 @@ TEST("test And propagates updated histestimate") { EXPECT_EQUAL(1.0f/(250*25), dynamic_cast<const RememberExecuteInfo &>(bp.getChild(2)).executeInfo.hitRate()); } +TEST("test Or propagates updated histestimate") { + OrBlueprint bp; + bp.setSourceId(2); + bp.addChild(ap(MyLeafSpec(5000).create<RememberExecuteInfo>()->setSourceId(2))); + bp.addChild(ap(MyLeafSpec(2000).create<RememberExecuteInfo>()->setSourceId(2))); + bp.addChild(ap(MyLeafSpec(800).create<RememberExecuteInfo>()->setSourceId(2))); + bp.addChild(ap(MyLeafSpec(20).create<RememberExecuteInfo>()->setSourceId(2))); + bp.optimize_self(Blueprint::OptimizePass::FIRST); + bp.optimize_self(Blueprint::OptimizePass::SECOND); + bp.optimize_self(Blueprint::OptimizePass::LAST); + bp.setDocIdLimit(5000); + bp.fetchPostings(ExecuteInfo::TRUE); + EXPECT_EQUAL(4u, bp.childCnt()); + for (uint32_t i = 0; i < bp.childCnt(); i++) { + const auto & child = dynamic_cast<const RememberExecuteInfo &>(bp.getChild(i)); + 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()); +} + TEST("test And Blueprint") { AndBlueprint b; { // combine std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(5u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); } @@ -187,16 +211,16 @@ TEST("test Or Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); } @@ -259,16 +283,16 @@ TEST("test Near Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(5u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); } @@ -300,16 +324,16 @@ TEST("test ONear Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(5u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); } @@ -341,16 +365,16 @@ TEST("test Rank Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); } @@ -391,16 +415,16 @@ TEST("test SourceBlender Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); } @@ -453,60 +477,60 @@ TEST("test SourceBlender below AND optimization") { auto selector_1 = std::make_unique<InvalidSelector>(); // the one auto selector_2 = std::make_unique<InvalidSelector>(); // not the one //------------------------------------------------------------------------- - AndBlueprint *top = new AndBlueprint(); + auto *top = new AndBlueprint(); Blueprint::UP top_bp(top); top->addChild(ap(MyLeafSpec(2).create())); top->addChild(ap(MyLeafSpec(1).create())); top->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); top->addChild(ap(blender)); } //------------------------------------------------------------------------- - AndBlueprint *expect = new AndBlueprint(); + auto *expect = new AndBlueprint(); Blueprint::UP expect_bp(expect); expect->addChild(ap(MyLeafSpec(1).create())); expect->addChild(ap(MyLeafSpec(2).create())); expect->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); expect->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender(new SourceBlenderBlueprint(*selector_1)); + auto *blender(new SourceBlenderBlueprint(*selector_1)); { - AndBlueprint *sub_and = new AndBlueprint(); + auto *sub_and = new AndBlueprint(); sub_and->setSourceId(3); sub_and->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); sub_and->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); blender->addChild(ap(sub_and)); } { - AndBlueprint *sub_and = new AndBlueprint(); + auto *sub_and = new AndBlueprint(); sub_and->setSourceId(2); sub_and->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); sub_and->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); @@ -514,7 +538,7 @@ TEST("test SourceBlender below AND optimization") { blender->addChild(ap(sub_and)); } { - AndBlueprint *sub_and = new AndBlueprint(); + auto *sub_and = new AndBlueprint(); sub_and->setSourceId(1); sub_and->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); sub_and->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); @@ -535,51 +559,51 @@ TEST("test SourceBlender below OR optimization") { auto selector_1 = std::make_unique<InvalidSelector>(); // the one auto selector_2 = std::make_unique<InvalidSelector>(); // not the one //------------------------------------------------------------------------- - OrBlueprint *top = new OrBlueprint(); + auto *top = new OrBlueprint(); Blueprint::UP top_up(top); top->addChild(ap(MyLeafSpec(2).create())); top->addChild(ap(MyLeafSpec(1).create())); top->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); top->addChild(ap(blender)); } //------------------------------------------------------------------------- - OrBlueprint *expect = new OrBlueprint(); + auto *expect = new OrBlueprint(); Blueprint::UP expect_up(expect); { - SourceBlenderBlueprint *blender(new SourceBlenderBlueprint(*selector_1)); + auto *blender(new SourceBlenderBlueprint(*selector_1)); { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(3); sub_and->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); sub_and->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(2); sub_and->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); sub_and->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); @@ -587,7 +611,7 @@ TEST("test SourceBlender below OR optimization") { blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(1); sub_and->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); sub_and->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); @@ -597,7 +621,7 @@ TEST("test SourceBlender below OR optimization") { expect->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); expect->addChild(ap(blender)); @@ -617,10 +641,10 @@ TEST("test SourceBlender below AND_NOT optimization") { auto selector_1 = std::make_unique<InvalidSelector>(); // the one auto selector_2 = std::make_unique<InvalidSelector>(); // not the one //------------------------------------------------------------------------- - AndNotBlueprint *top = new AndNotBlueprint(); + auto *top = new AndNotBlueprint(); Blueprint::UP top_up(top); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(42).create()->setSourceId(1))); top->addChild(ap(blender)); } @@ -628,50 +652,50 @@ TEST("test SourceBlender below AND_NOT optimization") { top->addChild(ap(MyLeafSpec(1).create())); top->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); top->addChild(ap(blender)); } //------------------------------------------------------------------------- - AndNotBlueprint *expect = new AndNotBlueprint(); + auto *expect = new AndNotBlueprint(); Blueprint::UP expect_up(expect); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(42).create()->setSourceId(1))); expect->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender(new SourceBlenderBlueprint(*selector_1)); + auto *blender(new SourceBlenderBlueprint(*selector_1)); { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(3); sub_and->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); sub_and->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(2); sub_and->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); sub_and->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); @@ -679,7 +703,7 @@ TEST("test SourceBlender below AND_NOT optimization") { blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(1); sub_and->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); sub_and->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); @@ -689,7 +713,7 @@ TEST("test SourceBlender below AND_NOT optimization") { expect->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); expect->addChild(ap(blender)); @@ -709,10 +733,10 @@ TEST("test SourceBlender below RANK optimization") { auto selector_1 = std::make_unique<InvalidSelector>(); // the one auto selector_2 = std::make_unique<InvalidSelector>(); // not the one //------------------------------------------------------------------------- - RankBlueprint *top = new RankBlueprint(); + auto *top = new RankBlueprint(); Blueprint::UP top_up(top); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(42).create()->setSourceId(1))); top->addChild(ap(blender)); } @@ -720,36 +744,36 @@ TEST("test SourceBlender below RANK optimization") { top->addChild(ap(MyLeafSpec(1).create())); top->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); top->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); blender->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); top->addChild(ap(blender)); } //------------------------------------------------------------------------- - RankBlueprint *expect = new RankBlueprint(); + auto *expect = new RankBlueprint(); Blueprint::UP expect_up(expect); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_1); + auto *blender = new SourceBlenderBlueprint(*selector_1); blender->addChild(ap(MyLeafSpec(42).create()->setSourceId(1))); expect->addChild(ap(blender)); } @@ -757,22 +781,22 @@ TEST("test SourceBlender below RANK optimization") { expect->addChild(ap(MyLeafSpec(1).create())); expect->addChild(ap(MyLeafSpec(3).create())); { - SourceBlenderBlueprint *blender = new SourceBlenderBlueprint(*selector_2); + auto *blender = new SourceBlenderBlueprint(*selector_2); blender->addChild(ap(MyLeafSpec(10).create()->setSourceId(1))); blender->addChild(ap(MyLeafSpec(20).create()->setSourceId(2))); expect->addChild(ap(blender)); } { - SourceBlenderBlueprint *blender(new SourceBlenderBlueprint(*selector_1)); + auto *blender(new SourceBlenderBlueprint(*selector_1)); { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(3); sub_and->addChild(ap(MyLeafSpec(300).create()->setSourceId(3))); sub_and->addChild(ap(MyLeafSpec(30).create()->setSourceId(3))); blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(2); sub_and->addChild(ap(MyLeafSpec(2000).create()->setSourceId(2))); sub_and->addChild(ap(MyLeafSpec(200).create()->setSourceId(2))); @@ -780,7 +804,7 @@ TEST("test SourceBlender below RANK optimization") { blender->addChild(ap(sub_and)); } { - OrBlueprint *sub_and = new OrBlueprint(); + auto *sub_and = new OrBlueprint(); sub_and->setSourceId(1); sub_and->addChild(ap(MyLeafSpec(1000).create()->setSourceId(1))); sub_and->addChild(ap(MyLeafSpec(100).create()->setSourceId(1))); @@ -826,7 +850,7 @@ TEST("test empty root node optimization and safeness") { addChild(ap(MyLeafSpec(0, true).create())). addChild(ap(MyLeafSpec(0, true).create())))); //------------------------------------------------------------------------- - Blueprint::UP expect_up(new EmptyBlueprint()); + auto expect_up = std::make_unique<EmptyBlueprint>(); //------------------------------------------------------------------------- top1_up = Blueprint::optimize(std::move(top1_up)); top2_up = Blueprint::optimize(std::move(top2_up)); @@ -851,7 +875,7 @@ TEST("and with one empty child is optimized away") { top = Blueprint::optimize(std::move(top)); Blueprint::UP expect_up(ap((new SourceBlenderBlueprint(*selector))-> addChild(ap(MyLeafSpec(10).create())). - addChild(ap(new EmptyBlueprint())))); + addChild(std::make_unique<EmptyBlueprint>()))); EXPECT_EQUAL(expect_up->asString(), top->asString()); } @@ -964,11 +988,11 @@ TEST("require that replaced blueprints retain source id") { //------------------------------------------------------------------------- // replace empty root with empty search Blueprint::UP top1_up(ap(MyLeafSpec(0, true).create()->setSourceId(13))); - Blueprint::UP expect1_up(new EmptyBlueprint()); + auto expect1_up = std::make_unique<EmptyBlueprint>(); expect1_up->setSourceId(13); //------------------------------------------------------------------------- // replace self with single child - Blueprint::UP top2_up(ap(static_cast<AndBlueprint&>((new AndBlueprint())->setSourceId(42)). + Blueprint::UP top2_up(ap(dynamic_cast<AndBlueprint&>((new AndBlueprint())->setSourceId(42)). addChild(ap(MyLeafSpec(30).create()->setSourceId(55))))); Blueprint::UP expect2_up(ap(MyLeafSpec(30).create()->setSourceId(42))); //------------------------------------------------------------------------- @@ -1017,16 +1041,16 @@ TEST("test WeakAnd Blueprint") { std::vector<Blueprint::HitEstimate> est; EXPECT_EQUAL(true, b.combine(est).empty); EXPECT_EQUAL(0u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(10, false)); + est.emplace_back(10, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(10u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(20, false)); + est.emplace_back(20, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(5, false)); + est.emplace_back(5, false); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); - est.push_back(Blueprint::HitEstimate(0, true)); + est.emplace_back(0, true); EXPECT_EQUAL(false, b.combine(est).empty); EXPECT_EQUAL(20u, b.combine(est).estHits); } @@ -1057,14 +1081,14 @@ TEST("test WeakAnd Blueprint") { { WeakAndBlueprint wa(456); MatchData::UP md = MatchData::makeTestInstance(100, 10); - wa.addTerm(Blueprint::UP(new FakeBlueprint(field, x)), 120); - wa.addTerm(Blueprint::UP(new FakeBlueprint(field, z)), 140); - wa.addTerm(Blueprint::UP(new FakeBlueprint(field, y)), 130); + wa.addTerm(std::make_unique<FakeBlueprint>(field, x), 120); + wa.addTerm(std::make_unique<FakeBlueprint>(field, z), 140); + wa.addTerm(std::make_unique<FakeBlueprint>(field, y), 130); { wa.fetchPostings(ExecuteInfo::TRUE); SearchIterator::UP search = wa.createSearch(*md, true); - EXPECT_TRUE(dynamic_cast<WeakAndSearch*>(search.get()) != 0); - WeakAndSearch &s = dynamic_cast<WeakAndSearch&>(*search); + EXPECT_TRUE(dynamic_cast<WeakAndSearch*>(search.get()) != nullptr); + auto &s = dynamic_cast<WeakAndSearch&>(*search); EXPECT_EQUAL(456u, s.getN()); ASSERT_EQUAL(3u, s.getTerms().size()); EXPECT_GREATER(s.get_max_score(0), 0.0); @@ -1085,7 +1109,7 @@ TEST("test WeakAnd Blueprint") { { wa.fetchPostings(ExecuteInfo::FALSE); SearchIterator::UP search = wa.createSearch(*md, false); - EXPECT_TRUE(dynamic_cast<WeakAndSearch*>(search.get()) != 0); + EXPECT_TRUE(dynamic_cast<WeakAndSearch*>(search.get()) != nullptr); EXPECT_TRUE(search->seek(1)); EXPECT_TRUE(search->seek(2)); EXPECT_FALSE(search->seek(3)); @@ -1195,7 +1219,7 @@ namespace { SimpleStringTerm makeTerm(const std::string & term) { - return SimpleStringTerm(term, "field", 0, search::query::Weight(0)); + return {term, "field", 0, search::query::Weight(0)}; } } @@ -1231,7 +1255,7 @@ TEST("require that children does not optimize when parents refuse them to") { SearchIterator::UP search = top_up->createSearch(*md, true); EXPECT_EQUAL("search::queryeval::EquivImpl<true>", search->getClassName()); { - const MultiSearch & e = dynamic_cast<const MultiSearch &>(*search); + const auto & e = dynamic_cast<const MultiSearch &>(*search); EXPECT_EQUAL("search::BitVectorIteratorStrictT<false>", e.getChildren()[0]->getClassName()); EXPECT_EQUAL("search::diskindex::ZcRareWordPosOccIterator<true, false>", e.getChildren()[1]->getClassName()); EXPECT_EQUAL("search::diskindex::ZcRareWordPosOccIterator<true, false>", e.getChildren()[2]->getClassName()); @@ -1241,7 +1265,7 @@ TEST("require that children does not optimize when parents refuse them to") { search = top_up->createSearch(*md, true); EXPECT_EQUAL("search::queryeval::EquivImpl<true>", search->getClassName()); { - const MultiSearch & e = dynamic_cast<const MultiSearch &>(*search); + const auto & e = dynamic_cast<const MultiSearch &>(*search); EXPECT_EQUAL("search::BitVectorIteratorStrictT<false>", e.getChildren()[0]->getClassName()); EXPECT_EQUAL("search::diskindex::ZcRareWordPosOccIterator<true, false>", e.getChildren()[1]->getClassName()); EXPECT_EQUAL("search::diskindex::ZcRareWordPosOccIterator<true, false>", e.getChildren()[2]->getClassName()); @@ -1269,7 +1293,7 @@ TEST("require_that_unpack_optimization_is_not_overruled_by_equiv") { SearchIterator::UP search = top_up->createSearch(*md, true); EXPECT_EQUAL("search::queryeval::EquivImpl<true>", search->getClassName()); { - const MultiSearch & e = dynamic_cast<const MultiSearch &>(*search); + const auto & e = dynamic_cast<const MultiSearch &>(*search); EXPECT_EQUAL("search::queryeval::OrLikeSearch<true, search::queryeval::(anonymous namespace)::FullUnpack>", e.getChildren()[0]->getClassName()); } @@ -1278,7 +1302,7 @@ TEST("require_that_unpack_optimization_is_not_overruled_by_equiv") { search = top_up->createSearch(*md, true); EXPECT_EQUAL("search::queryeval::EquivImpl<true>", search->getClassName()); { - const MultiSearch & e = dynamic_cast<const MultiSearch &>(*search); + const auto & e = dynamic_cast<const MultiSearch &>(*search); EXPECT_EQUAL("search::queryeval::OrLikeSearch<true, search::queryeval::(anonymous namespace)::SelectiveUnpack>", e.getChildren()[0]->getClassName()); } @@ -1288,7 +1312,7 @@ TEST("require_that_unpack_optimization_is_not_overruled_by_equiv") { search = top_up->createSearch(*md, true); EXPECT_EQUAL("search::queryeval::EquivImpl<true>", search->getClassName()); { - const MultiSearch & e = dynamic_cast<const MultiSearch &>(*search); + const auto & e = dynamic_cast<const MultiSearch &>(*search); EXPECT_EQUAL("search::queryeval::OrLikeSearch<true, search::queryeval::NoUnpack>", e.getChildren()[0]->getClassName()); } @@ -1344,7 +1368,7 @@ TEST("require that children of onear are not optimized") { TEST("require that ANDNOT without children is optimized to empty search") { Blueprint::UP top_up(new AndNotBlueprint()); - Blueprint::UP expect_up(new EmptyBlueprint()); + auto expect_up = std::make_unique<EmptyBlueprint>(); top_up = Blueprint::optimize(std::move(top_up)); EXPECT_EQUAL(expect_up->asString(), top_up->asString()); } @@ -1395,22 +1419,57 @@ TEST("require that highest cost tier sorts last for AND") { EXPECT_EQUAL(expect_up->asString(), top_up->asString()); } -TEST("require that intermediate cost tier is minimum cost tier of children") { - Blueprint::UP bp1( - ap((new AndBlueprint())-> - addChild(ap(MyLeafSpec(10).cost_tier(1).create())). - addChild(ap(MyLeafSpec(20).cost_tier(2).create())). - addChild(ap(MyLeafSpec(30).cost_tier(3).create())))); - Blueprint::UP bp2( - ap((new AndBlueprint())-> - addChild(ap(MyLeafSpec(10).cost_tier(3).create())). - addChild(ap(MyLeafSpec(20).cost_tier(2).create())). - addChild(ap(MyLeafSpec(30).cost_tier(2).create())))); - EXPECT_EQUAL(bp1->getState().cost_tier(), 1u); - EXPECT_EQUAL(bp2->getState().cost_tier(), 2u); +template<typename BP> +void +verifyCostTierInheritance(uint8_t expected, uint8_t expected_reverse) { + auto bp1 = std::make_unique<BP>(); + bp1->addChild(ap(MyLeafSpec(10).cost_tier(1).create())). + addChild(ap(MyLeafSpec(20).cost_tier(2).create())). + addChild(ap(MyLeafSpec(30).cost_tier(3).create())); + auto bp2 = std::make_unique<BP>(); + bp2->addChild(ap(MyLeafSpec(10).cost_tier(3).create())). + addChild(ap(MyLeafSpec(20).cost_tier(2).create())). + addChild(ap(MyLeafSpec(30).cost_tier(1).create())); + EXPECT_EQUAL(bp1->getState().cost_tier(), expected); + EXPECT_EQUAL(bp2->getState().cost_tier(), expected_reverse); +} + +TEST("require that AND cost tier is minimum cost tier of children") { + verifyCostTierInheritance<AndBlueprint>(1, 1); +} + +TEST("require that OR cost tier is maximum cost tier of children") { + verifyCostTierInheritance<OrBlueprint>(3, 3); +} + +TEST("require that Rank cost tier is first childs cost tier") { + verifyCostTierInheritance<RankBlueprint>(1, 3); +} + +TEST("require that AndNot cost tier is first childs cost tier") { + verifyCostTierInheritance<AndNotBlueprint>(1, 3); +} + +struct MySourceBlender { + InvalidSelector selector; + SourceBlenderBlueprint sb; + MySourceBlender() : selector(), sb(selector) {} + IntermediateBlueprint & + addChild(Blueprint::UP child) { + return sb.addChild(std::move(child)); + } + const Blueprint::State &getState() const { + return sb.getState(); + } + +}; + +TEST("require that SourceBlender cost tier is maximum cost tier of children") { + verifyCostTierInheritance<MySourceBlender>(3, 3); } -void verify_or_est(const std::vector<Blueprint::HitEstimate> &child_estimates, Blueprint::HitEstimate expect) { +void +verify_or_est(const std::vector<Blueprint::HitEstimate> &child_estimates, Blueprint::HitEstimate expect) { OrBlueprint my_or; my_or.setDocIdLimit(32); auto my_est = my_or.combine(child_estimates); |