diff options
Diffstat (limited to 'searchlib/src/tests/queryeval')
17 files changed, 472 insertions, 348 deletions
diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp index 968e006622f..266dc6f8652 100644 --- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp @@ -17,8 +17,6 @@ using namespace search::fef; namespace { -auto opts = Blueprint::Options::all(); - //----------------------------------------------------------------------------- class MyOr : public IntermediateBlueprint @@ -45,19 +43,14 @@ public: std::sort(children.begin(), children.end(), TieredGreaterEstimate()); } - bool inheritStrict(size_t i) const override { - (void) i; - return true; - } - SearchIterator::UP createIntermediateSearch(MultiSearch::Children subSearches, - bool strict, MatchData &md) const override + MatchData &md) const override { - return std::make_unique<MySearch>("or", std::move(subSearches), &md, strict); + return std::make_unique<MySearch>("or", std::move(subSearches), &md, strict()); } - SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { - return create_default_filter(strict, constraint); + SearchIteratorUP createFilterSearch(FilterConstraint constraint) const override { + return create_default_filter(constraint); } static MyOr& create() { return *(new MyOr()); } MyOr& add(Blueprint *n) { addChild(UP(n)); return *this; } @@ -71,9 +64,9 @@ private: public: SearchIterator::UP createIntermediateSearch(MultiSearch::Children subSearches, - bool strict, MatchData &md) const override + MatchData &md) const override { - return std::make_unique<MySearch>("or", std::move(subSearches), &md, strict); + return std::make_unique<MySearch>("or", std::move(subSearches), &md, strict()); } static OtherOr& create() { return *(new OtherOr()); } @@ -95,15 +88,11 @@ public: return {}; } - bool inheritStrict(size_t i) const override { - return (i == 0); - } - SearchIterator::UP createIntermediateSearch(MultiSearch::Children subSearches, - bool strict, MatchData &md) const override + MatchData &md) const override { - return std::make_unique<MySearch>("and", std::move(subSearches), &md, strict); + return std::make_unique<MySearch>("and", std::move(subSearches), &md, strict()); } static MyAnd& create() { return *(new MyAnd()); } @@ -118,9 +107,9 @@ private: public: SearchIterator::UP createIntermediateSearch(MultiSearch::Children subSearches, - bool strict, MatchData &md) const override + MatchData &md) const override { - return std::make_unique<MySearch>("and", std::move(subSearches), &md, strict); + return std::make_unique<MySearch>("and", std::move(subSearches), &md, strict()); } static OtherAnd& create() { return *(new OtherAnd()); } @@ -133,9 +122,9 @@ class OtherAndNot : public AndNotBlueprint public: SearchIterator::UP createIntermediateSearch(MultiSearch::Children subSearches, - bool strict, MatchData &md) const override + MatchData &md) const override { - return std::make_unique<MySearch>("andnot", std::move(subSearches), &md, strict); + return std::make_unique<MySearch>("andnot", std::move(subSearches), &md, strict()); } static OtherAndNot& create() { return *(new OtherAndNot()); } @@ -153,11 +142,11 @@ struct MyTerm : SimpleLeafBlueprint { FlowStats calculate_flow_stats(uint32_t docid_limit) const override { return default_flow_stats(docid_limit, getState().estimate().estHits, 0); } - SearchIterator::UP createLeafSearch(const search::fef::TermFieldMatchDataArray &, bool) const override { + SearchIterator::UP createLeafSearch(const search::fef::TermFieldMatchDataArray &) const override { return {}; } - SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { - return create_default_filter(strict, constraint); + SearchIteratorUP createFilterSearch(FilterConstraint constraint) const override { + return create_default_filter(constraint); } }; @@ -187,8 +176,9 @@ public: SearchIterator::UP Fixture::create(const Blueprint &blueprint) { - const_cast<Blueprint &>(blueprint).fetchPostings(ExecuteInfo::TRUE); - SearchIterator::UP search = blueprint.createSearch(*_md, true); + const_cast<Blueprint &>(blueprint).null_plan(true, 1000); + const_cast<Blueprint &>(blueprint).fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = blueprint.createSearch(*_md); MySearch::verifyAndInfer(search.get(), *_md); return search; } @@ -453,7 +443,7 @@ TEST_F("testChildAndNotCollapsing", Fixture) ); TEST_DO(f.check_not_equal(*sorted, *unsorted)); unsorted->setDocIdLimit(1000); - unsorted = Blueprint::optimize_and_sort(std::move(unsorted), true, opts); + unsorted = Blueprint::optimize_and_sort(std::move(unsorted)); TEST_DO(f.check_equal(*sorted, *unsorted)); } @@ -493,7 +483,7 @@ TEST_F("testChildAndCollapsing", Fixture) TEST_DO(f.check_not_equal(*sorted, *unsorted)); unsorted->setDocIdLimit(1000); - unsorted = Blueprint::optimize_and_sort(std::move(unsorted), true, opts); + unsorted = Blueprint::optimize_and_sort(std::move(unsorted)); TEST_DO(f.check_equal(*sorted, *unsorted)); } @@ -534,7 +524,7 @@ TEST_F("testChildOrCollapsing", Fixture) unsorted->setDocIdLimit(1000); // we sort non-strict here since a strict OR does not have a // deterministic sort order. - unsorted = Blueprint::optimize_and_sort(std::move(unsorted), false, opts); + unsorted = Blueprint::optimize_and_sort(std::move(unsorted), false); TEST_DO(f.check_equal(*sorted, *unsorted)); } @@ -578,7 +568,7 @@ TEST_F("testChildSorting", Fixture) TEST_DO(f.check_not_equal(*sorted, *unsorted)); unsorted->setDocIdLimit(1000); - unsorted = Blueprint::optimize_and_sort(std::move(unsorted), true, opts); + unsorted = Blueprint::optimize_and_sort(std::move(unsorted)); TEST_DO(f.check_equal(*sorted, *unsorted)); } diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp index 6b3c068cd4d..9338436348b 100644 --- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp @@ -55,15 +55,13 @@ struct WeightOrder { }; struct RememberExecuteInfo : public MyLeaf { - bool is_strict; double hit_rate; - RememberExecuteInfo() : MyLeaf(), is_strict(false), hit_rate(0.0) {} - RememberExecuteInfo(FieldSpecBaseList fields) : MyLeaf(std::move(fields)), is_strict(false), hit_rate(0.0) {} + RememberExecuteInfo() : MyLeaf(), hit_rate(0.0) {} + RememberExecuteInfo(FieldSpecBaseList fields) : MyLeaf(std::move(fields)), hit_rate(0.0) {} void fetchPostings(const ExecuteInfo &execInfo) override { LeafBlueprint::fetchPostings(execInfo); - is_strict = execInfo.is_strict(); hit_rate = execInfo.hit_rate(); } }; @@ -75,16 +73,19 @@ bool got_global_filter(Blueprint &b) { return (static_cast<MyLeaf &>(b)).got_global_filter(); } -void check_sort_order(IntermediateBlueprint &self, BlueprintVector children, std::vector<size_t> order) { +void check_sort_order_and_strictness(std::unique_ptr<IntermediateBlueprint> self, bool self_strict, BlueprintVector children, std::vector<size_t> order, std::vector<bool> strict) { ASSERT_EQUAL(children.size(), order.size()); + ASSERT_EQUAL(children.size(), strict.size()); std::vector<const Blueprint *> unordered; - for (const auto & child: children) { + for (auto &&child: children) { unordered.push_back(child.get()); + self->addChild(std::move(child)); } - // TODO: sort by cost (requires both setDocIdLimit and optimize to be called) - self.sort(children, true, false); - for (size_t i = 0; i < children.size(); ++i) { - EXPECT_EQUAL(children[i].get(), unordered[order[i]]); + self->basic_plan(self_strict, 1000); + for (size_t i = 0; i < self->childCnt(); ++i) { + const auto &child = self->getChild(i); + EXPECT_EQUAL(&child, unordered[order[i]]); + EXPECT_EQUAL(child.strict(), strict[i]); } } @@ -126,18 +127,18 @@ TEST("test AndNot Blueprint") { EXPECT_EQUAL(false, got_global_filter(a.getChild(0))); EXPECT_EQUAL(true, got_global_filter(a.getChild(1))); } - check_sort_order(b, createLeafs({10, 20, 40, 30}), {0, 2, 3, 1}); - EXPECT_EQUAL(true, b.inheritStrict(0)); - EXPECT_EQUAL(false, b.inheritStrict(1)); - EXPECT_EQUAL(false, b.inheritStrict(2)); - EXPECT_EQUAL(false, b.inheritStrict(-1)); + check_sort_order_and_strictness(std::make_unique<AndNotBlueprint>(), false, + createLeafs({10, 20, 40, 30}), {0, 2, 3, 1}, + {false, false, false, false}); + check_sort_order_and_strictness(std::make_unique<AndNotBlueprint>(), true, + createLeafs({10, 20, 40, 30}), {0, 2, 3, 1}, + {true, false, false, false}); // createSearch tested by iterator unit test } template <typename BP> void optimize(std::unique_ptr<BP> &ref, bool strict) { - auto opts = Blueprint::Options::all(); - auto optimized = Blueprint::optimize_and_sort(std::move(ref), strict, opts); + auto optimized = Blueprint::optimize_and_sort(std::move(ref), strict); ref.reset(dynamic_cast<BP*>(optimized.get())); ASSERT_TRUE(ref); optimized.release(); @@ -151,11 +152,11 @@ TEST("test And propagates updated histestimate") { bp->addChild(ap(MyLeafSpec(2000).create<RememberExecuteInfo>()->setSourceId(2))); bp->setDocIdLimit(5000); optimize(bp, true); - bp->fetchPostings(ExecuteInfo::TRUE); + bp->fetchPostings(ExecuteInfo::FULL); EXPECT_EQUAL(3u, bp->childCnt()); for (uint32_t i = 0; i < bp->childCnt(); i++) { const auto & child = dynamic_cast<const RememberExecuteInfo &>(bp->getChild(i)); - EXPECT_EQUAL((i == 0), child.is_strict); + EXPECT_EQUAL((i == 0), child.strict()); } EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).hit_rate); EXPECT_EQUAL(1.0/250, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).hit_rate); @@ -170,25 +171,25 @@ TEST("test Or propagates updated histestimate") { bp->addChild(ap(MyLeafSpec(800).create<RememberExecuteInfo>()->setSourceId(2))); bp->addChild(ap(MyLeafSpec(20).create<RememberExecuteInfo>()->setSourceId(2))); bp->setDocIdLimit(5000); - // NOTE: use non-strict OR ordering since strict OR ordering is non-deterministic - optimize(bp, false); //--- execute info when non-strict: - bp->fetchPostings(ExecuteInfo::FALSE); + optimize(bp, false); + bp->fetchPostings(ExecuteInfo::FULL); 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_FALSE(child.is_strict); + EXPECT_FALSE(child.strict()); } EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).hit_rate); EXPECT_APPROX(0.5, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).hit_rate, 1e-6); EXPECT_APPROX(0.5*3.0/5.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(2)).hit_rate, 1e-6); EXPECT_APPROX(0.5*3.0*42.0/(5.0*50.0), dynamic_cast<const RememberExecuteInfo &>(bp->getChild(3)).hit_rate, 1e-6); //--- execute info when strict: - bp->fetchPostings(ExecuteInfo::TRUE); + optimize(bp, true); + bp->fetchPostings(ExecuteInfo::FULL); 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.is_strict); + EXPECT_TRUE(child.strict()); } EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(0)).hit_rate); EXPECT_EQUAL(1.0, dynamic_cast<const RememberExecuteInfo &>(bp->getChild(1)).hit_rate); @@ -227,12 +228,12 @@ TEST("test And Blueprint") { EXPECT_EQUAL(false, got_global_filter(a.getChild(0))); EXPECT_EQUAL(true, got_global_filter(a.getChild(1))); } - check_sort_order(b, createLeafs({20, 40, 10, 30}), {2, 0, 3, 1}); - EXPECT_EQUAL(true, b.inheritStrict(0)); - EXPECT_EQUAL(false, b.inheritStrict(1)); - EXPECT_EQUAL(false, b.inheritStrict(2)); - EXPECT_EQUAL(false, b.inheritStrict(-1)); - + check_sort_order_and_strictness(std::make_unique<AndBlueprint>(), false, + createLeafs({20, 40, 10, 30}), {2, 0, 3, 1}, + {false, false, false, false}); + check_sort_order_and_strictness(std::make_unique<AndBlueprint>(), true, + createLeafs({20, 40, 10, 30}), {2, 0, 3, 1}, + {true, false, false, false}); // createSearch tested by iterator unit test } @@ -291,11 +292,12 @@ TEST("test Or Blueprint") { EXPECT_EQUAL(false, got_global_filter(o.getChild(0))); EXPECT_EQUAL(true, got_global_filter(o.getChild(o.childCnt() - 1))); } - check_sort_order(b, createLeafs({10, 20, 40, 30}), {2, 3, 1, 0}); - EXPECT_EQUAL(true, b.inheritStrict(0)); - EXPECT_EQUAL(true, b.inheritStrict(1)); - EXPECT_EQUAL(true, b.inheritStrict(2)); - EXPECT_EQUAL(true, b.inheritStrict(-1)); + check_sort_order_and_strictness(std::make_unique<OrBlueprint>(), false, + createLeafs({10, 20, 40, 30}), {2, 3, 1, 0}, + {false, false, false, false}); + check_sort_order_and_strictness(std::make_unique<OrBlueprint>(), true, + createLeafs({10, 20, 40, 30}), {0, 1, 2, 3}, + {true, true, true, true}); // createSearch tested by iterator unit test } @@ -323,11 +325,12 @@ TEST("test Near Blueprint") { a.addChild(ap(MyLeafSpec(10).addField(1, 1).create())); EXPECT_EQUAL(0u, a.exposeFields().size()); } - check_sort_order(b, createLeafs({40, 10, 30, 20}), {1, 3, 2, 0}); - EXPECT_EQUAL(true, b.inheritStrict(0)); - EXPECT_EQUAL(false, b.inheritStrict(1)); - EXPECT_EQUAL(false, b.inheritStrict(2)); - EXPECT_EQUAL(false, b.inheritStrict(-1)); + check_sort_order_and_strictness(std::make_unique<NearBlueprint>(7), false, + createLeafs({40, 10, 30, 20}), {1, 3, 2, 0}, + {false, false, false, false}); + check_sort_order_and_strictness(std::make_unique<NearBlueprint>(7), true, + createLeafs({40, 10, 30, 20}), {1, 3, 2, 0}, + {true, false, false, false}); // createSearch tested by iterator unit test } @@ -355,11 +358,12 @@ TEST("test ONear Blueprint") { a.addChild(ap(MyLeafSpec(10).addField(1, 1).create())); EXPECT_EQUAL(0u, a.exposeFields().size()); } - check_sort_order(b, createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}); - EXPECT_EQUAL(true, b.inheritStrict(0)); - EXPECT_EQUAL(false, b.inheritStrict(1)); - EXPECT_EQUAL(false, b.inheritStrict(2)); - EXPECT_EQUAL(false, b.inheritStrict(-1)); + check_sort_order_and_strictness(std::make_unique<ONearBlueprint>(7), false, + createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}, + {false, false, false, false}); + check_sort_order_and_strictness(std::make_unique<ONearBlueprint>(7), true, + createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}, + {true, false, false, false}); // createSearch tested by iterator unit test } @@ -395,11 +399,12 @@ TEST("test Rank Blueprint") { EXPECT_EQUAL(false, got_global_filter(a.getChild(0))); EXPECT_EQUAL(true, got_global_filter(a.getChild(1))); } - check_sort_order(b, createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}); - EXPECT_EQUAL(true, b.inheritStrict(0)); - EXPECT_EQUAL(false, b.inheritStrict(1)); - EXPECT_EQUAL(false, b.inheritStrict(2)); - EXPECT_EQUAL(false, b.inheritStrict(-1)); + check_sort_order_and_strictness(std::make_unique<RankBlueprint>(), false, + createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}, + {false, false, false, false}); + check_sort_order_and_strictness(std::make_unique<RankBlueprint>(), true, + createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}, + {true, false, false, false}); // createSearch tested by iterator unit test } @@ -451,11 +456,12 @@ TEST("test SourceBlender Blueprint") { o.addChild(ap(MyLeafSpec(0, true).create())); EXPECT_EQUAL(0u, a->getState().numFields()); } - check_sort_order(b, createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}); - EXPECT_EQUAL(true, b.inheritStrict(0)); - EXPECT_EQUAL(true, b.inheritStrict(1)); - EXPECT_EQUAL(true, b.inheritStrict(2)); - EXPECT_EQUAL(true, b.inheritStrict(-1)); + check_sort_order_and_strictness(std::make_unique<SourceBlenderBlueprint>(*selector), false, + createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}, + {false, false, false, false}); + check_sort_order_and_strictness(std::make_unique<SourceBlenderBlueprint>(*selector), true, + createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}, + {true, true, true, true}); // createSearch tested by iterator unit test } @@ -573,7 +579,7 @@ optimize_and_compare(Blueprint::UP top, Blueprint::UP expect, bool strict = true top->setDocIdLimit(1000); expect->setDocIdLimit(1000); TEST_DO(compare(*top, *expect, false)); - auto opts = Blueprint::Options::all().sort_by_cost(sort_by_cost); + auto opts = Blueprint::Options::default_options().sort_by_cost(sort_by_cost); top = Blueprint::optimize_and_sort(std::move(top), strict, opts); TEST_DO(compare(*top, *expect, true)); expect = Blueprint::optimize_and_sort(std::move(expect), strict, opts); @@ -705,12 +711,11 @@ TEST("test empty root node optimization and safeness") { //------------------------------------------------------------------------- auto expect_up = std::make_unique<EmptyBlueprint>(); - auto opts = Blueprint::Options::all(); - compare(*expect_up, *Blueprint::optimize_and_sort(std::move(top1), true, opts), true); - compare(*expect_up, *Blueprint::optimize_and_sort(std::move(top2), true, opts), true); - compare(*expect_up, *Blueprint::optimize_and_sort(std::move(top3), true, opts), true); - compare(*expect_up, *Blueprint::optimize_and_sort(std::move(top4), true, opts), true); - compare(*expect_up, *Blueprint::optimize_and_sort(std::move(top5), true, opts), true); + compare(*expect_up, *Blueprint::optimize_and_sort(std::move(top1)), true); + compare(*expect_up, *Blueprint::optimize_and_sort(std::move(top2)), true); + compare(*expect_up, *Blueprint::optimize_and_sort(std::move(top3)), true); + compare(*expect_up, *Blueprint::optimize_and_sort(std::move(top4)), true); + compare(*expect_up, *Blueprint::optimize_and_sort(std::move(top5)), true); } TEST("and with one empty child is optimized away") { @@ -718,8 +723,7 @@ TEST("and with one empty child is optimized away") { Blueprint::UP top = ap((new SourceBlenderBlueprint(*selector))-> addChild(ap(MyLeafSpec(10).create())). addChild(addLeafs(std::make_unique<AndBlueprint>(), {{0, true}, 10, 20}))); - auto opts = Blueprint::Options::all(); - top = Blueprint::optimize_and_sort(std::move(top), true, opts); + top = Blueprint::optimize_and_sort(std::move(top)); Blueprint::UP expect_up(ap((new SourceBlenderBlueprint(*selector))-> addChild(ap(MyLeafSpec(10).create())). addChild(std::make_unique<EmptyBlueprint>()))); @@ -896,9 +900,8 @@ TEST("require that replaced blueprints retain source id") { addChild(ap(MyLeafSpec(30).create()->setSourceId(55))))); Blueprint::UP expect2_up(ap(MyLeafSpec(30).create()->setSourceId(42))); //------------------------------------------------------------------------- - auto opts = Blueprint::Options::all(); - top1_up = Blueprint::optimize_and_sort(std::move(top1_up), true, opts); - top2_up = Blueprint::optimize_and_sort(std::move(top2_up), true, opts); + top1_up = Blueprint::optimize_and_sort(std::move(top1_up)); + top2_up = Blueprint::optimize_and_sort(std::move(top2_up)); compare(*expect1_up, *top1_up, true); compare(*expect2_up, *top2_up, true); EXPECT_EQUAL(13u, top1_up->getSourceId()); @@ -960,11 +963,12 @@ TEST("test WeakAnd Blueprint") { a.addChild(ap(MyLeafSpec(10).addField(1, 1).create())); EXPECT_EQUAL(0u, a.exposeFields().size()); } - check_sort_order(b, createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}); - EXPECT_EQUAL(true, b.inheritStrict(0)); - EXPECT_EQUAL(true, b.inheritStrict(1)); - EXPECT_EQUAL(true, b.inheritStrict(2)); - EXPECT_EQUAL(true, b.inheritStrict(-1)); + check_sort_order_and_strictness(std::make_unique<WeakAndBlueprint>(1000), false, + createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}, + {false, false, false, false}); + check_sort_order_and_strictness(std::make_unique<WeakAndBlueprint>(1000), true, + createLeafs({20, 10, 40, 30}), {0, 1, 2, 3}, + {true, true, true, true}); { FieldSpec field("foo", 1, 1); FakeResult x = FakeResult().doc(1).doc(2).doc(5); @@ -977,8 +981,9 @@ TEST("test WeakAnd Blueprint") { 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); + wa.basic_plan(true, 1000); + wa.fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = wa.createSearch(*md); EXPECT_TRUE(dynamic_cast<WeakAndSearch*>(search.get()) != nullptr); auto &s = dynamic_cast<WeakAndSearch&>(*search); EXPECT_EQUAL(456u, s.getN()); @@ -999,8 +1004,9 @@ TEST("test WeakAnd Blueprint") { EXPECT_EQUAL(0u, terms[2].maxScore); // NB: not set } { - wa.fetchPostings(ExecuteInfo::FALSE); - SearchIterator::UP search = wa.createSearch(*md, false); + wa.basic_plan(false, 1000); + wa.fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = wa.createSearch(*md); EXPECT_TRUE(dynamic_cast<WeakAndSearch*>(search.get()) != nullptr); EXPECT_TRUE(search->seek(1)); EXPECT_TRUE(search->seek(2)); @@ -1029,23 +1035,24 @@ TEST("require_that_unpack_of_or_over_multisearch_is_optimized") { addChild(std::move(child1)). addChild(std::move(child2)))); MatchData::UP md = MatchData::makeTestInstance(100, 10); - top_up->fetchPostings(ExecuteInfo::FALSE); + top_up->basic_plan(false, 1000); + top_up->fetchPostings(ExecuteInfo::FULL); EXPECT_EQUAL("search::queryeval::OrLikeSearch<false, search::queryeval::(anonymous namespace)::FullUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); md->resolveTermField(2)->tagAsNotNeeded(); EXPECT_EQUAL("search::queryeval::OrLikeSearch<false, search::queryeval::(anonymous namespace)::FullUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); md->resolveTermField(1)->tagAsNotNeeded(); md->resolveTermField(3)->tagAsNotNeeded(); EXPECT_EQUAL("search::queryeval::OrLikeSearch<false, search::queryeval::(anonymous namespace)::SelectiveUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); md->resolveTermField(4)->tagAsNotNeeded(); md->resolveTermField(6)->tagAsNotNeeded(); EXPECT_EQUAL("search::queryeval::OrLikeSearch<false, search::queryeval::(anonymous namespace)::SelectiveUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); md->resolveTermField(5)->tagAsNotNeeded(); EXPECT_EQUAL("search::queryeval::OrLikeSearch<false, search::queryeval::NoUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); } TEST("require_that_unpack_of_or_is_optimized") { @@ -1055,16 +1062,17 @@ TEST("require_that_unpack_of_or_is_optimized") { addChild(ap(MyLeafSpec(20).addField(2,2).create())). addChild(ap(MyLeafSpec(10).addField(3,3).create())))); MatchData::UP md = MatchData::makeTestInstance(100, 10); - top_up->fetchPostings(ExecuteInfo::FALSE); + top_up->basic_plan(false, 1000); + top_up->fetchPostings(ExecuteInfo::FULL); EXPECT_EQUAL("search::queryeval::OrLikeSearch<false, search::queryeval::(anonymous namespace)::FullUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); md->resolveTermField(2)->tagAsNotNeeded(); EXPECT_EQUAL("search::queryeval::OrLikeSearch<false, search::queryeval::(anonymous namespace)::SelectiveUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); md->resolveTermField(1)->tagAsNotNeeded(); md->resolveTermField(3)->tagAsNotNeeded(); EXPECT_EQUAL("search::queryeval::OrLikeSearch<false, search::queryeval::NoUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); } TEST("require_that_unpack_of_and_is_optimized") { @@ -1074,16 +1082,17 @@ TEST("require_that_unpack_of_and_is_optimized") { addChild(ap(MyLeafSpec(20).addField(2,2).create())). addChild(ap(MyLeafSpec(10).addField(3,3).create())))); MatchData::UP md = MatchData::makeTestInstance(100, 10); - top_up->fetchPostings(ExecuteInfo::FALSE); + top_up->basic_plan(false, 1000); + top_up->fetchPostings(ExecuteInfo::FULL); EXPECT_EQUAL("search::queryeval::AndSearchNoStrict<search::queryeval::(anonymous namespace)::FullUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); md->resolveTermField(2)->tagAsNotNeeded(); EXPECT_EQUAL("search::queryeval::AndSearchNoStrict<search::queryeval::(anonymous namespace)::SelectiveUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); md->resolveTermField(1)->tagAsNotNeeded(); md->resolveTermField(3)->tagAsNotNeeded(); EXPECT_EQUAL("search::queryeval::AndSearchNoStrict<search::queryeval::NoUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); } TEST("require_that_unpack_optimization_is_honoured_by_parents") { @@ -1094,16 +1103,17 @@ TEST("require_that_unpack_optimization_is_honoured_by_parents") { addChild(ap(MyLeafSpec(20).addField(2,2).create())). addChild(ap(MyLeafSpec(10).addField(3,3).create())))))); MatchData::UP md = MatchData::makeTestInstance(100, 10); - top_up->fetchPostings(ExecuteInfo::FALSE); + top_up->basic_plan(false, 1000); + top_up->fetchPostings(ExecuteInfo::FULL); EXPECT_EQUAL("search::queryeval::AndSearchNoStrict<search::queryeval::(anonymous namespace)::FullUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); md->resolveTermField(2)->tagAsNotNeeded(); EXPECT_EQUAL("search::queryeval::AndSearchNoStrict<search::queryeval::(anonymous namespace)::FullUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); md->resolveTermField(1)->tagAsNotNeeded(); md->resolveTermField(3)->tagAsNotNeeded(); EXPECT_EQUAL("search::queryeval::AndSearchNoStrict<search::queryeval::NoUnpack>", - top_up->createSearch(*md, false)->getClassName()); + top_up->createSearch(*md)->getClassName()); } namespace { @@ -1143,8 +1153,9 @@ TEST("require that children does not optimize when parents refuse them to") { FieldSpec("f2", 2, idxth21), makeTerm("w2")), 1.0))); MatchData::UP md = MatchData::makeTestInstance(100, 10); - top_up->fetchPostings(ExecuteInfo::FALSE); - SearchIterator::UP search = top_up->createSearch(*md, true); + top_up->basic_plan(true, 1000); + top_up->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = top_up->createSearch(*md); EXPECT_EQUAL(strict_equiv_name, normalize_class_name(search->getClassName())); { const auto & e = dynamic_cast<const MultiSearch &>(*search); @@ -1154,7 +1165,7 @@ TEST("require that children does not optimize when parents refuse them to") { } md->resolveTermField(12)->tagAsNotNeeded(); - search = top_up->createSearch(*md, true); + search = top_up->createSearch(*md); EXPECT_EQUAL(strict_equiv_name, normalize_class_name(search->getClassName())); { const auto & e = dynamic_cast<const MultiSearch &>(*search); @@ -1181,8 +1192,9 @@ TEST("require_that_unpack_optimization_is_not_overruled_by_equiv") { addChild(ap(MyLeafSpec(10).addField(3,idxth3).create()))), 1.0))); MatchData::UP md = MatchData::makeTestInstance(100, 10); - top_up->fetchPostings(ExecuteInfo::FALSE); - SearchIterator::UP search = top_up->createSearch(*md, true); + top_up->basic_plan(true, 1000); + top_up->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = top_up->createSearch(*md); EXPECT_EQUAL(strict_equiv_name, normalize_class_name(search->getClassName())); { const auto & e = dynamic_cast<const MultiSearch &>(*search); @@ -1191,7 +1203,7 @@ TEST("require_that_unpack_optimization_is_not_overruled_by_equiv") { } md->resolveTermField(2)->tagAsNotNeeded(); - search = top_up->createSearch(*md, true); + search = top_up->createSearch(*md); EXPECT_EQUAL(strict_equiv_name, normalize_class_name(search->getClassName())); { const auto & e = dynamic_cast<const MultiSearch &>(*search); @@ -1201,7 +1213,7 @@ TEST("require_that_unpack_optimization_is_not_overruled_by_equiv") { md->resolveTermField(1)->tagAsNotNeeded(); md->resolveTermField(3)->tagAsNotNeeded(); - search = top_up->createSearch(*md, true); + search = top_up->createSearch(*md); EXPECT_EQUAL(strict_equiv_name, normalize_class_name(search->getClassName())); { const auto & e = dynamic_cast<const MultiSearch &>(*search); @@ -1213,8 +1225,7 @@ TEST("require_that_unpack_optimization_is_not_overruled_by_equiv") { TEST("require that ANDNOT without children is optimized to empty search") { Blueprint::UP top_up = std::make_unique<AndNotBlueprint>(); auto expect_up = std::make_unique<EmptyBlueprint>(); - auto opts = Blueprint::Options::all(); - top_up = Blueprint::optimize_and_sort(std::move(top_up), true, opts); + top_up = Blueprint::optimize_and_sort(std::move(top_up)); compare(*expect_up, *top_up, true); } diff --git a/searchlib/src/tests/queryeval/blueprint/leaf_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/leaf_blueprints_test.cpp index 44be9fb0fca..cb5473babbd 100644 --- a/searchlib/src/tests/queryeval/blueprint/leaf_blueprints_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/leaf_blueprints_test.cpp @@ -29,8 +29,9 @@ Test::testEmptyBlueprint() EXPECT_EQUAL(1u, empty.getState().field(0).getFieldId()); EXPECT_EQUAL(11u, empty.getState().field(0).getHandle()); - empty.fetchPostings(ExecuteInfo::TRUE); - SearchIterator::UP search = empty.createSearch(*md, true); + empty.basic_plan(true, 100); + empty.fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = empty.createSearch(*md); SimpleResult res; res.search(*search); @@ -47,8 +48,9 @@ Test::testSimpleBlueprint() SimpleBlueprint simple(a); simple.tag("tag"); EXPECT_EQUAL("tag", simple.tag()); - simple.fetchPostings(ExecuteInfo::TRUE); - SearchIterator::UP search = simple.createSearch(*md, true); + simple.basic_plan(true, 100); + simple.fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = simple.createSearch(*md); SimpleResult res; res.search(*search); @@ -69,8 +71,9 @@ Test::testFakeBlueprint() TermFieldHandle handle = 0; FakeBlueprint orig(FieldSpec("<field>", fieldId, handle), fake); - orig.fetchPostings(ExecuteInfo::TRUE); - SearchIterator::UP search = orig.createSearch(*md, true); + orig.basic_plan(true, 100); + orig.fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = orig.createSearch(*md); search->initFullRange(); EXPECT_TRUE(!search->seek(1u)); EXPECT_EQUAL(10u, search->getDocId()); diff --git a/searchlib/src/tests/queryeval/blueprint/mysearch.h b/searchlib/src/tests/queryeval/blueprint/mysearch.h index 79c9885bb7d..e3b86a0eb84 100644 --- a/searchlib/src/tests/queryeval/blueprint/mysearch.h +++ b/searchlib/src/tests/queryeval/blueprint/mysearch.h @@ -109,9 +109,9 @@ class MyLeaf : public SimpleLeafBlueprint public: SearchIterator::UP - createLeafSearch(const TFMDA &tfmda, bool strict) const override + createLeafSearch(const TFMDA &tfmda) const override { - return std::make_unique<MySearch>("leaf", tfmda, strict); + return std::make_unique<MySearch>("leaf", tfmda, strict()); } MyLeaf() : SimpleLeafBlueprint() {} @@ -141,8 +141,8 @@ public: // make public using LeafBlueprint::set_want_global_filter; - SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { - return create_default_filter(strict, constraint); + SearchIteratorUP createFilterSearch(FilterConstraint constraint) const override { + return create_default_filter(constraint); } }; diff --git a/searchlib/src/tests/queryeval/dot_product/dot_product_test.cpp b/searchlib/src/tests/queryeval/dot_product/dot_product_test.cpp index d160b513534..542eb1bb4f8 100644 --- a/searchlib/src/tests/queryeval/dot_product/dot_product_test.cpp +++ b/searchlib/src/tests/queryeval/dot_product/dot_product_test.cpp @@ -74,8 +74,9 @@ struct DP { FieldSpecList fields; fields.add(FieldSpec(field, fieldId, handle, field_is_filter)); queryeval::Blueprint::UP bp = searchable.createBlueprint(requestContext, fields, *node); - bp->fetchPostings(ExecuteInfo::createForTest(strict)); - SearchIterator::UP sb = bp->createSearch(*md, strict); + bp->basic_plan(strict, 10); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP sb = bp->createSearch(*md); EXPECT_TRUE(dynamic_cast<DotProductSearch*>(sb.get()) != 0); sb->initFullRange(); FakeResult result; diff --git a/searchlib/src/tests/queryeval/equiv/equiv_test.cpp b/searchlib/src/tests/queryeval/equiv/equiv_test.cpp index c570c06a60b..99045af7245 100644 --- a/searchlib/src/tests/queryeval/equiv/equiv_test.cpp +++ b/searchlib/src/tests/queryeval/equiv/equiv_test.cpp @@ -59,8 +59,9 @@ EquivTest::test_equiv(bool strict, bool unpack_normal_features, bool unpack_inte data.setNeedNormalFeatures(unpack_normal_features); data.setNeedInterleavedFeatures(unpack_interleaved_features); } - bp->fetchPostings(ExecuteInfo::createForTest(strict)); - SearchIterator::UP search = bp->createSearch(*md, strict); + bp->basic_plan(strict, 100); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = bp->createSearch(*md); search->initFullRange(); EXPECT_TRUE(!search->seek(3)); diff --git a/searchlib/src/tests/queryeval/fake_searchable/fake_searchable_test.cpp b/searchlib/src/tests/queryeval/fake_searchable/fake_searchable_test.cpp index 8ddac327643..638ce30eb28 100644 --- a/searchlib/src/tests/queryeval/fake_searchable/fake_searchable_test.cpp +++ b/searchlib/src/tests/queryeval/fake_searchable/fake_searchable_test.cpp @@ -62,8 +62,9 @@ TEST_F(FakeSearchableTest, require_that_term_search_works) { bool strict = (i == 0); SCOPED_TRACE(strict ? "strict" : "non-strict"); MatchData::UP md = MatchData::makeTestInstance(100, 10); - bp->fetchPostings(ExecuteInfo::createForTest(strict)); - SearchIterator::UP search = bp->createSearch(*md, strict); + bp->basic_plan(strict, 100); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = bp->createSearch(*md); search->initFullRange(); EXPECT_TRUE(!search->seek(3)); @@ -116,8 +117,9 @@ TEST_F(FakeSearchableTest, require_that_phrase_search_works) { bool strict = (i == 0); SCOPED_TRACE(strict ? "strict" : "non-strict"); MatchData::UP md = MatchData::makeTestInstance(100, 10); - bp->fetchPostings(ExecuteInfo::createForTest(strict)); - SearchIterator::UP search = bp->createSearch(*md, strict); + bp->basic_plan(strict, 100); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = bp->createSearch(*md); search->initFullRange(); EXPECT_TRUE(!search->seek(3)); @@ -167,8 +169,9 @@ TEST_F(FakeSearchableTest, require_that_weigheted_set_search_works) { bool strict = (i == 0); SCOPED_TRACE(strict ? "strict" : "non-strict"); MatchData::UP md = MatchData::makeTestInstance(100, 10); - bp->fetchPostings(ExecuteInfo::createForTest(strict)); - SearchIterator::UP search = bp->createSearch(*md, strict); + bp->basic_plan(strict, 100); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = bp->createSearch(*md); search->initFullRange(); EXPECT_TRUE(!search->seek(2)); @@ -238,8 +241,9 @@ TEST_F(FakeSearchableTest, require_that_multi_field_search_works) { bool strict = (i == 0); SCOPED_TRACE(strict ? "strict" : "non-strict"); MatchData::UP md = MatchData::makeTestInstance(100, 10); - bp->fetchPostings(ExecuteInfo::createForTest(strict)); - SearchIterator::UP search = bp->createSearch(*md, strict); + bp->basic_plan(strict, 100); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = bp->createSearch(*md); search->initFullRange(); EXPECT_TRUE(!search->seek(3)); @@ -322,8 +326,9 @@ TEST_F(FakeSearchableTest, require_that_phrase_with_empty_child_works) { bool strict = (i == 0); SCOPED_TRACE(strict ? "strict" : "non-strict"); MatchData::UP md = MatchData::makeTestInstance(100, 10); - bp->fetchPostings(ExecuteInfo::createForTest(strict)); - SearchIterator::UP search = bp->createSearch(*md, strict); + bp->basic_plan(strict, 100); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = bp->createSearch(*md); search->initFullRange(); EXPECT_TRUE(!search->seek(3)); @@ -342,8 +347,9 @@ TEST_F(FakeSearchableTest, require_that_match_data_is_compressed_for_attributes) fields.add(FieldSpec("attrfoo", 1, 1)); Blueprint::UP bp = source.createBlueprint(req_ctx, fields, termNode); MatchData::UP md = MatchData::makeTestInstance(100, 10); - bp->fetchPostings(ExecuteInfo::FALSE); - SearchIterator::UP search = bp->createSearch(*md, false); + bp->basic_plan(false, 100); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = bp->createSearch(*md); search->initFullRange(); EXPECT_TRUE(search->seek(5)); search->unpack(5u); @@ -369,8 +375,9 @@ TEST_F(FakeSearchableTest, require_that_relevant_data_can_be_obtained_from_fake_ fields.add(FieldSpec("attrfoo", 1, 1)); Blueprint::UP bp = source.createBlueprint(req_ctx, fields, termNode); MatchData::UP md = MatchData::makeTestInstance(100, 10); - bp->fetchPostings(ExecuteInfo::FALSE); - SearchIterator::UP search = bp->createSearch(*md, false); + bp->basic_plan(false, 100); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = bp->createSearch(*md); EXPECT_TRUE(bp->get_attribute_search_context() != nullptr); const auto *attr_ctx = bp->get_attribute_search_context(); ASSERT_TRUE(attr_ctx); 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 c4d34ab3565..5c29c293d82 100644 --- a/searchlib/src/tests/queryeval/filter_search/filter_search_test.cpp +++ b/searchlib/src/tests/queryeval/filter_search/filter_search_test.cpp @@ -36,8 +36,9 @@ constexpr auto upper_bound = Constraint::UPPER_BOUND; const uint32_t docid_limit = 100; template <typename T> -concept FilterFactory = requires(const T &a, bool strict, Constraint constraint) { - { a.createFilterSearch(strict, constraint) } -> std::same_as<std::unique_ptr<SearchIterator>>; +concept FilterFactory = requires(const T &a, T &ma, InFlow in_flow, uint32_t my_docid_limit, bool strict, Constraint constraint) { + ma.basic_plan(in_flow, my_docid_limit); + { a.createFilterSearch(constraint) } -> std::same_as<std::unique_ptr<SearchIterator>>; }; template <typename T> @@ -45,20 +46,6 @@ concept ChildCollector = requires(T a, std::unique_ptr<Blueprint> bp) { a.addChild(std::move(bp)); }; -// inherit Blueprint to capture the default filter factory -struct DefaultBlueprint : Blueprint { - FlowStats calculate_flow_stats(uint32_t) const override { abort(); } - void optimize(Blueprint* &, OptimizePass) override { abort(); } - double sort(InFlow, const Options &) override { abort(); } - const State &getState() const override { abort(); } - void fetchPostings(const ExecuteInfo &) override { abort(); } - void freeze() override { abort(); } - SearchIteratorUP createSearch(MatchData &, bool) const override { abort(); } - SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { - return create_default_filter(strict, constraint); - } -}; - // proxy class used to make various decorators for leaf blueprints // may be used directly to add the use of a field to a leaf blueprint struct LeafProxy : SimpleLeafBlueprint { @@ -71,10 +58,20 @@ struct LeafProxy : SimpleLeafBlueprint { : SimpleLeafBlueprint(), child(std::move(child_in)) { init(); } LeafProxy(FieldSpecBase field, std::unique_ptr<Blueprint> child_in) : SimpleLeafBlueprint(field), child(std::move(child_in)) { init(); } - FlowStats calculate_flow_stats(uint32_t) const override { abort(); } - SearchIteratorUP createLeafSearch(const TermFieldMatchDataArray &, bool) const override { abort(); } - SearchIteratorUP createFilterSearch(bool strict, Constraint constraint) const override { - return child->createFilterSearch(strict, constraint); + void each_node_post_order(const std::function<void(Blueprint&)> &f) override { + child->each_node_post_order(f); + f(*this); + } + FlowStats calculate_flow_stats(uint32_t my_docid_limit) const override { + return child->calculate_flow_stats(my_docid_limit); + } + void sort(InFlow in_flow, const Options &opts) override { + strict(in_flow.strict()); + child->sort(in_flow, opts); + } + SearchIteratorUP createLeafSearch(const TermFieldMatchDataArray &) const override { abort(); } + SearchIteratorUP createFilterSearch(Constraint constraint) const override { + return child->createFilterSearch(constraint); } }; @@ -82,15 +79,22 @@ struct LeafProxy : SimpleLeafBlueprint { struct CheckParamsProxy : LeafProxy { static bool current_strict; // <- changed by test static Constraint current_constraint; // <- changed by test + bool expect_forced_strict = false; bool expect_inherit_strict; bool expect_same_constraint; CheckParamsProxy(std::unique_ptr<Blueprint> child_in, bool expect_inherit_strict_in, bool expect_same_constraint_in) : LeafProxy(std::move(child_in)), expect_inherit_strict(expect_inherit_strict_in), expect_same_constraint(expect_same_constraint_in) {} - SearchIteratorUP createFilterSearch(bool strict, Constraint constraint) const override { - EXPECT_EQ(strict, (current_strict && expect_inherit_strict)); + CheckParamsProxy(std::unique_ptr<Blueprint> child_in) + : LeafProxy(std::move(child_in)), expect_forced_strict(true), expect_inherit_strict(false), expect_same_constraint(true) {} + SearchIteratorUP createFilterSearch(Constraint constraint) const override { + if (expect_forced_strict) { + EXPECT_EQ(strict(), true); + } else { + EXPECT_EQ(strict(), (current_strict && expect_inherit_strict)); + } EXPECT_EQ((constraint == current_constraint), expect_same_constraint); - return child->createFilterSearch(strict, constraint); + return child->createFilterSearch(constraint); } }; bool CheckParamsProxy::current_strict = false; @@ -101,9 +105,9 @@ struct CheckDroppedProxy : LeafProxy { mutable bool used; CheckDroppedProxy(std::unique_ptr<Blueprint> child_in) : LeafProxy(std::move(child_in)), used(false) {} - SearchIteratorUP createFilterSearch(bool strict, Constraint constraint) const override { + SearchIteratorUP createFilterSearch(Constraint constraint) const override { used = true; - return child->createFilterSearch(strict, constraint); + return child->createFilterSearch(constraint); } ~CheckDroppedProxy() override { EXPECT_EQ(used, false); @@ -162,6 +166,10 @@ std::unique_ptr<Blueprint> check(std::unique_ptr<Blueprint> child, bool expect_i return std::make_unique<CheckParamsProxy>(std::move(child), expect_inherit_strict, expect_same_constraint); } +std::unique_ptr<Blueprint> check_forced(std::unique_ptr<Blueprint> child) { + return std::make_unique<CheckParamsProxy>(std::move(child)); +} + // check that create filter is not called std::unique_ptr<Blueprint> dropped(std::unique_ptr<Blueprint> child) { return std::make_unique<CheckDroppedProxy>(std::move(child)); @@ -191,6 +199,11 @@ struct Children { list.back() = [=](){ return ::check(old_factory(), expect_inherit_strict, expect_same_constraint); }; return *this; } + Children &check_forced() { + Factory old_factory = list.back(); + list.back() = [=](){ return ::check_forced(old_factory()); }; + return *this; + } Children &dropped() { Factory old_factory = list.back(); list.back() = [=](){ return ::dropped(old_factory()); }; @@ -204,29 +217,44 @@ struct Children { } }; +struct NoFlow { + NoFlow(InFlow) noexcept {} + void add(double) noexcept {}; + bool strict() noexcept { return false; } + double flow() noexcept { return 0.0; } +}; + // Combine children blueprints using a shared filter creation // algorithm. Satisfies the FilterFactory concept. +template <typename Flow> struct Combine { using factory_fun = std::function<std::unique_ptr<SearchIterator>(const Blueprint::Children &, bool, Constraint)>; factory_fun fun; + bool strict; Blueprint::Children list; - Combine(factory_fun fun_in, const Children &child_list); + Combine(factory_fun fun_in, const Children &child_list) + : fun(fun_in), strict(false), list() + { + child_list.apply(*this); + } ~Combine(); void addChild(std::unique_ptr<Blueprint> child) { list.push_back(std::move(child)); } - auto createFilterSearch(bool strict, Constraint constraint) const { + void basic_plan(InFlow in_flow, uint32_t my_docid_limit) { + strict = in_flow.strict(); + Flow flow(in_flow); + for (auto &child: list) { + child->basic_plan(InFlow(flow.strict(), flow.flow()), my_docid_limit); + flow.add(child->estimate()); + } + } + auto createFilterSearch(Constraint constraint) const { return fun(list, strict, constraint); } }; - -Combine::Combine(factory_fun fun_in, const Children &child_list) - : fun(fun_in), list() -{ - child_list.apply(*this); -} - -Combine::~Combine() = default; +template <typename Flow> +Combine<Flow>::~Combine() = default; // enable Make-ing source blender struct SourceBlenderAdapter { @@ -236,8 +264,11 @@ struct SourceBlenderAdapter { void addChild(std::unique_ptr<Blueprint> child) { blueprint.addChild(std::move(child)); } - auto createFilterSearch(bool strict, Constraint constraint) const { - return blueprint.createFilterSearch(strict, constraint); + void basic_plan(InFlow in_flow, uint32_t my_docid_limit) { + blueprint.basic_plan(in_flow, my_docid_limit); + } + auto createFilterSearch(Constraint constraint) const { + return blueprint.createFilterSearch(constraint); } }; @@ -251,8 +282,11 @@ struct SimplePhraseAdapter { auto term = std::make_unique<LeafProxy>(child_field, std::move(child)); blueprint.addTerm(std::move(term)); } - auto createFilterSearch(bool strict, Constraint constraint) const { - return blueprint.createFilterSearch(strict, constraint); + void basic_plan(InFlow in_flow, uint32_t my_docid_limit) { + blueprint.basic_plan(in_flow, my_docid_limit); + } + auto createFilterSearch(Constraint constraint) const { + return blueprint.createFilterSearch(constraint); } }; @@ -264,8 +298,11 @@ struct EquivAdapter { void addChild(std::unique_ptr<Blueprint> child) { blueprint.addTerm(std::move(child), 1.0); } - auto createFilterSearch(bool strict, Constraint constraint) const { - return blueprint.createFilterSearch(strict, constraint); + void basic_plan(InFlow in_flow, uint32_t my_docid_limit) { + blueprint.basic_plan(in_flow, my_docid_limit); + } + auto createFilterSearch(Constraint constraint) const { + return blueprint.createFilterSearch(constraint); } }; @@ -280,8 +317,11 @@ struct WeightedSetTermAdapter { blueprint.addTerm(std::move(child), 100, estimate); blueprint.complete(estimate); } - auto createFilterSearch(bool strict, Constraint constraint) const { - return blueprint.createFilterSearch(strict, constraint); + void basic_plan(InFlow in_flow, uint32_t my_docid_limit) { + blueprint.basic_plan(in_flow, my_docid_limit); + } + auto createFilterSearch(Constraint constraint) const { + return blueprint.createFilterSearch(constraint); } }; @@ -301,8 +341,11 @@ struct DotProductAdapter { blueprint.addTerm(std::move(term), 100, estimate); blueprint.complete(estimate); } - auto createFilterSearch(bool strict, Constraint constraint) const { - return blueprint.createFilterSearch(strict, constraint); + void basic_plan(InFlow in_flow, uint32_t my_docid_limit) { + blueprint.basic_plan(in_flow, my_docid_limit); + } + auto createFilterSearch(Constraint constraint) const { + return blueprint.createFilterSearch(constraint); } }; @@ -321,8 +364,11 @@ struct ParallelWeakAndAdapter { blueprint.addTerm(std::move(term), 100, estimate); blueprint.complete(estimate); } - auto createFilterSearch(bool strict, Constraint constraint) const { - return blueprint.createFilterSearch(strict, constraint); + void basic_plan(InFlow in_flow, uint32_t my_docid_limit) { + blueprint.basic_plan(in_flow, my_docid_limit); + } + auto createFilterSearch(Constraint constraint) const { + return blueprint.createFilterSearch(constraint); } }; @@ -337,8 +383,11 @@ struct SameElementAdapter { auto term = std::make_unique<LeafProxy>(child_field, std::move(child)); blueprint.addTerm(std::move(term)); } - auto createFilterSearch(bool strict, Constraint constraint) const { - return blueprint.createFilterSearch(strict, constraint); + void basic_plan(InFlow in_flow, uint32_t my_docid_limit) { + blueprint.basic_plan(in_flow, my_docid_limit); + } + auto createFilterSearch(Constraint constraint) const { + return blueprint.createFilterSearch(constraint); } }; @@ -355,8 +404,11 @@ struct Make { Make(const Children &child_list, Args && ... args) : blueprint(std::forward<Args>(args)...) { child_list.apply(blueprint); } - auto createFilterSearch(bool strict, Constraint constraint) const { - return blueprint.createFilterSearch(strict, constraint); + void basic_plan(InFlow in_flow, uint32_t my_docid_limit) { + blueprint.basic_plan(in_flow, my_docid_limit); + } + auto createFilterSearch(Constraint constraint) const { + return blueprint.createFilterSearch(constraint); } }; @@ -381,10 +433,11 @@ struct Expect { }; template <FilterFactory Blueprint> -void verify(const Blueprint &blueprint, bool strict, Constraint constraint, const Expect &expect) { +void verify(Blueprint &&blueprint, bool strict, Constraint constraint, const Expect &expect) { CheckParamsProxy::current_strict = strict; CheckParamsProxy::current_constraint = constraint; - auto filter = blueprint.createFilterSearch(strict, constraint); + blueprint.basic_plan(strict, docid_limit); + auto filter = blueprint.createFilterSearch(constraint); if (expect.children > 0) { ASSERT_EQ(filter->isMultiSearch(), true); EXPECT_EQ(static_cast<MultiSearch*>(filter.get())->getChildren().size(), expect.children); @@ -409,14 +462,14 @@ void verify(const Blueprint &blueprint, bool strict, Constraint constraint, cons } template <FilterFactory Blueprint> -void verify(const Blueprint &blueprint, bool strict, const Expect &expect) { +void verify(Blueprint &&blueprint, bool strict, const Expect &expect) { for (auto constraint: {lower_bound, upper_bound}) { verify(blueprint, strict, constraint, expect); } } template <FilterFactory Blueprint> -void verify(const Blueprint &blueprint, const Expect &upper, const Expect &lower) { +void verify(Blueprint &&blueprint, const Expect &upper, const Expect &lower) { for (auto constraint: {lower_bound, upper_bound}) { const Expect &expect = (constraint == upper_bound) ? upper : lower; for (bool strict: {false, true}) { @@ -426,7 +479,7 @@ void verify(const Blueprint &blueprint, const Expect &upper, const Expect &lower } template <FilterFactory Blueprint> -void verify(const Blueprint &blueprint, const Expect &upper_and_lower) { +void verify(Blueprint &&blueprint, const Expect &upper_and_lower) { verify(blueprint, upper_and_lower, upper_and_lower); } @@ -443,12 +496,12 @@ TEST(FilterSearchTest, custom_leaf) { } TEST(FilterSearchTest, default_filter) { - verify(DefaultBlueprint(), Expect::full(), Expect::empty()); - auto adapter = [](const auto &ignore_children, bool strict, Constraint constraint) { + auto adapter = [](const auto &ignore_children, bool ignore_strict, Constraint constraint) { (void) ignore_children; - return Blueprint::create_default_filter(strict, constraint); + (void) ignore_strict; + return Blueprint::create_default_filter(constraint); }; - verify(Combine(adapter, Children()), Expect::full(), Expect::empty()); + verify(Combine<NoFlow>(adapter, Children()), Expect::full(), Expect::empty()); } TEST(FilterSearchTest, simple_or) { @@ -457,39 +510,55 @@ TEST(FilterSearchTest, simple_or) { .hits({7}).check(true, true) .hits({3, 11}).check(true, true); auto expected = Expect::hits({3, 5, 7, 10, 11}); - verify(Combine(Blueprint::create_or_filter, child_list), expected); + verify(Combine<OrFlow>(Blueprint::create_or_filter, child_list), expected); verify(Make<OrBlueprint>(child_list), expected); verify(Make<EquivAdapter>(child_list), expected); - verify(Make<WeightedSetTermAdapter>(child_list), expected); - verify(Make<DotProductAdapter>(child_list), expected); - verify(Combine(Blueprint::create_atmost_or_filter, child_list), expected, Expect::empty()); + verify(Combine<OrFlow>(Blueprint::create_atmost_or_filter, child_list), expected, Expect::empty()); verify(Make<WeakAndBlueprint>(child_list, 100), expected, Expect::empty()); verify(Make<SourceBlenderAdapter>(child_list), expected, Expect::empty()); verify(Make<ParallelWeakAndAdapter>(child_list), expected, Expect::empty()); } +TEST(FilterSearchTest, forced_or) { + auto child_list = Children() + .hits({5, 10}).check_forced() + .hits({7}).check_forced() + .hits({3, 11}).check_forced(); + auto expected = Expect::hits({3, 5, 7, 10, 11}); + verify(Make<WeightedSetTermAdapter>(child_list), expected); + verify(Make<DotProductAdapter>(child_list), expected); +} + TEST(FilterSearchTest, simple_and) { auto child_list = Children() - .hits({1, 2, 3, 4, 5, 6}).check(true, true) - .hits({2, 4, 6, 7}).check(false, true) - .hits({1, 4, 6, 7, 10}).check(false, true); + .hits({2, 4, 6, 7}).check(true, true) + .hits({1, 4, 6, 7, 10}).check(false, true) + .hits({1, 2, 3, 4, 5, 6}).check(false, true); auto expected = Expect::hits({4, 6}); - verify(Combine(Blueprint::create_and_filter, child_list), expected); + verify(Combine<AndFlow>(Blueprint::create_and_filter, child_list), expected); verify(Make<AndBlueprint>(child_list), expected); - verify(Combine(Blueprint::create_atmost_and_filter, child_list), expected, Expect::empty()); + verify(Combine<AndFlow>(Blueprint::create_atmost_and_filter, child_list), expected, Expect::empty()); verify(Make<NearBlueprint>(child_list, 3), expected, Expect::empty()); verify(Make<ONearBlueprint>(child_list, 3), expected, Expect::empty()); - verify(Make<SimplePhraseAdapter>(child_list), expected, Expect::empty()); verify(Make<SameElementAdapter>(child_list), expected, Expect::empty()); } +TEST(FilterSearchTest, eager_and) { + auto child_list = Children() + .hits({2, 4, 6, 7}).check(true, true) + .hits({1, 4, 6, 7, 10}).check(true, true) + .hits({1, 2, 3, 4, 5, 6}).check(true, true); + auto expected = Expect::hits({4, 6}); + verify(Make<SimplePhraseAdapter>(child_list), expected, Expect::empty()); +} + TEST(FilterSearchTest, simple_andnot) { auto child_list = Children() .hits({1, 2, 3, 4, 5, 6}).check(true, true) .hits({2, 4, 6}).check(false, false) .hits({4, 6, 7}).check(false, false); auto expected = Expect::hits({1, 3, 5}); - verify(Combine(Blueprint::create_andnot_filter, child_list), expected); + verify(Combine<AndNotFlow>(Blueprint::create_andnot_filter, child_list), expected); verify(Make<AndNotBlueprint>(child_list), expected); } @@ -497,9 +566,13 @@ TEST(FilterSearchTest, rank_filter) { auto child_list1 = Children().hits({1,2,3}).empty().full(); auto child_list2 = Children().empty().hits({1,2,3}).full(); auto child_list3 = Children().full().hits({1,2,3}).empty(); - verify(Combine(Blueprint::create_first_child_filter, child_list1), Expect::hits({1,2,3})); - verify(Combine(Blueprint::create_first_child_filter, child_list2), Expect::empty()); - verify(Combine(Blueprint::create_first_child_filter, child_list3), Expect::full()); + auto adapter = [](const auto &children, bool ignore_strict, Constraint constraint) { + (void) ignore_strict; + return Blueprint::create_first_child_filter(children, constraint); + }; + verify(Combine<RankFlow>(adapter, child_list1), Expect::hits({1,2,3})); + verify(Combine<RankFlow>(adapter, child_list2), Expect::empty()); + verify(Combine<RankFlow>(adapter, child_list3), Expect::full()); verify(Make<RankBlueprint>(child_list1), Expect::hits({1,2,3})); verify(Make<RankBlueprint>(child_list2), Expect::empty()); verify(Make<RankBlueprint>(child_list3), Expect::full()); @@ -510,7 +583,7 @@ TEST(FilterSearchTest, or_short_circuit) { .hits({5, 10}).check(true, true) .full().check(true, true) .hits({3, 11}).check(true, true).dropped(); - verify(Combine(Blueprint::create_or_filter, child_list), + verify(Combine<OrFlow>(Blueprint::create_or_filter, child_list), Expect::full()); } @@ -519,7 +592,7 @@ TEST(FilterSearchTest, or_pruning) { .empty().check(true, true) .empty().check(true, true) .empty().check(true, true); - verify(Combine(Blueprint::create_or_filter, child_list), + verify(Combine<OrFlow>(Blueprint::create_or_filter, child_list), Expect::empty()); } @@ -528,7 +601,7 @@ TEST(FilterSearchTest, or_partial_pruning) { .hits({5, 10}).check(true, true) .empty().check(true, true) .hits({3, 11}).check(true, true); - verify(Combine(Blueprint::create_or_filter, child_list), + verify(Combine<OrFlow>(Blueprint::create_or_filter, child_list), Expect::hits({3, 5, 10, 11}).child_count(2)); } @@ -537,7 +610,7 @@ TEST(FilterSearchTest, and_short_circuit) { .hits({1, 2, 3}).check(true, true) .empty().check(false, true) .hits({2, 3, 4}).check(false, true).dropped(); - verify(Combine(Blueprint::create_and_filter, child_list), + verify(Combine<AndFlow>(Blueprint::create_and_filter, child_list), Expect::empty()); } @@ -546,7 +619,7 @@ TEST(FilterSearchTest, and_pruning) { .full().check(true, true) .full().check(false, true) .full().check(false, true); - verify(Combine(Blueprint::create_and_filter, child_list), + verify(Combine<AndFlow>(Blueprint::create_and_filter, child_list), Expect::full()); } @@ -555,7 +628,7 @@ TEST(FilterSearchTest, and_partial_pruning) { .hits({1, 2, 3}).check(true, true) .full().check(false, true) .hits({2, 3, 4}).check(false, true); - verify(Combine(Blueprint::create_and_filter, child_list), + verify(Combine<AndFlow>(Blueprint::create_and_filter, child_list), Expect::hits({2, 3}).child_count(2)); } @@ -563,7 +636,7 @@ TEST(FilterSearchTest, andnot_positive_short_circuit) { auto child_list = Children() .empty().check(true, true) .hits({1, 2, 3}).check(false, false).dropped(); - verify(Combine(Blueprint::create_andnot_filter, child_list), + verify(Combine<AndNotFlow>(Blueprint::create_andnot_filter, child_list), Expect::empty()); } @@ -573,7 +646,7 @@ TEST(FilterSearchTest, andnot_negative_short_circuit) { .hits({1}).check(false, false) .full().check(false, false) .hits({3}).check(false, false).dropped(); - verify(Combine(Blueprint::create_andnot_filter, child_list), + verify(Combine<AndNotFlow>(Blueprint::create_andnot_filter, child_list), Expect::empty()); } @@ -583,7 +656,7 @@ TEST(FilterSearchTest, andnot_negative_pruning) { .empty().check(false, false) .empty().check(false, false) .empty().check(false, false); - verify(Combine(Blueprint::create_andnot_filter, child_list), + verify(Combine<AndNotFlow>(Blueprint::create_andnot_filter, child_list), Expect::full()); } @@ -593,7 +666,7 @@ TEST(FilterSearchTest, andnot_partial_negative_pruning) { .hits({1}).check(false, false) .empty().check(false, false) .hits({3}).check(false, false); - verify(Combine(Blueprint::create_andnot_filter, child_list), + verify(Combine<AndNotFlow>(Blueprint::create_andnot_filter, child_list), Expect::hits({2}).child_count(3)); } @@ -602,7 +675,7 @@ TEST(FilterSearchTest, first_or_child_can_be_partially_pruned) { .empty().check(true, true) .hits({5, 10}).check(true, true) .hits({3, 11}).check(true, true); - verify(Combine(Blueprint::create_or_filter, child_list), + verify(Combine<OrFlow>(Blueprint::create_or_filter, child_list), Expect::hits({3, 5, 10, 11}).child_count(2)); } @@ -611,9 +684,9 @@ TEST(FilterSearchTest, first_and_child_can_only_be_partially_pruned_when_nonstri .full().check(true, true) .hits({1, 2, 3}).check(false, true) .hits({2, 3, 4}).check(false, true); - verify(Combine(Blueprint::create_and_filter, child_list), true, + verify(Combine<AndFlow>(Blueprint::create_and_filter, child_list), true, Expect::hits({2, 3}).child_count(3)); - verify(Combine(Blueprint::create_and_filter, child_list), false, + verify(Combine<AndFlow>(Blueprint::create_and_filter, child_list), false, Expect::hits({2, 3}).child_count(2)); } @@ -623,19 +696,19 @@ TEST(FilterSearchTest, first_negative_andnot_child_can_be_partially_pruned) { .empty().check(false, false) .hits({1}).check(false, false) .hits({3}).check(false, false); - verify(Combine(Blueprint::create_andnot_filter, child_list), + verify(Combine<AndNotFlow>(Blueprint::create_andnot_filter, child_list), Expect::hits({2}).child_count(3)); } TEST(FilterSearchTest, need_atleast_one_child) { - verify(Combine(Blueprint::create_and_filter, Children().full()), Expect::full()); - verify(Combine(Blueprint::create_or_filter, Children().empty()), Expect::empty()); - verify(Combine(Blueprint::create_andnot_filter, Children().full()), Expect::full()); - EXPECT_THROW(verify(Combine(Blueprint::create_and_filter, Children()), Expect::empty()), + verify(Combine<AndFlow>(Blueprint::create_and_filter, Children().full()), Expect::full()); + verify(Combine<OrFlow>(Blueprint::create_or_filter, Children().empty()), Expect::empty()); + verify(Combine<AndNotFlow>(Blueprint::create_andnot_filter, Children().full()), Expect::full()); + EXPECT_THROW(verify(Combine<AndFlow>(Blueprint::create_and_filter, Children()), Expect::empty()), vespalib::RequireFailedException); - EXPECT_THROW(verify(Combine(Blueprint::create_or_filter, Children()), Expect::empty()), + EXPECT_THROW(verify(Combine<OrFlow>(Blueprint::create_or_filter, Children()), Expect::empty()), vespalib::RequireFailedException); - EXPECT_THROW(verify(Combine(Blueprint::create_andnot_filter, Children()), Expect::empty()), + EXPECT_THROW(verify(Combine<AndNotFlow>(Blueprint::create_andnot_filter, Children()), Expect::empty()), vespalib::RequireFailedException); } diff --git a/searchlib/src/tests/queryeval/iterator_benchmark/iterator_benchmark_test.cpp b/searchlib/src/tests/queryeval/iterator_benchmark/iterator_benchmark_test.cpp index 202ba8c180e..33c2e067255 100644 --- a/searchlib/src/tests/queryeval/iterator_benchmark/iterator_benchmark_test.cpp +++ b/searchlib/src/tests/queryeval/iterator_benchmark/iterator_benchmark_test.cpp @@ -156,7 +156,7 @@ get_class_name(const auto& obj) BenchmarkResult strict_search(Blueprint& blueprint, MatchData& md, uint32_t docid_limit) { - auto itr = blueprint.createSearch(md, true); + auto itr = blueprint.createSearch(md); assert(itr.get()); BenchmarkTimer timer(budget_sec); uint32_t hits = 0; @@ -176,9 +176,9 @@ strict_search(Blueprint& blueprint, MatchData& md, uint32_t docid_limit) } BenchmarkResult -non_strict_search(Blueprint& blueprint, MatchData& md, uint32_t docid_limit, double filter_hit_ratio, bool force_strict) +non_strict_search(Blueprint& blueprint, MatchData& md, uint32_t docid_limit, double filter_hit_ratio) { - auto itr = blueprint.createSearch(md, force_strict); + auto itr = blueprint.createSearch(md); assert(itr.get()); BenchmarkTimer timer(budget_sec); uint32_t seeks = 0; @@ -209,16 +209,15 @@ non_strict_search(Blueprint& blueprint, MatchData& md, uint32_t docid_limit, dou BenchmarkResult benchmark_search(Blueprint::UP blueprint, uint32_t docid_limit, bool strict_context, bool force_strict, double filter_hit_ratio) { - auto opts = Blueprint::Options::all(); - blueprint->sort(strict_context || force_strict, opts); - blueprint->fetchPostings(ExecuteInfo::createForTest(strict_context || force_strict)); + blueprint->basic_plan(strict_context || force_strict, docid_limit); + blueprint->fetchPostings(ExecuteInfo::FULL); // Note: All blueprints get the same TermFieldMatchData instance. // This is OK as long as we don't do unpacking and only use 1 thread. auto md = MatchData::makeTestInstance(1, 1); if (strict_context) { return strict_search(*blueprint, *md, docid_limit); } else { - return non_strict_search(*blueprint, *md, docid_limit, filter_hit_ratio, force_strict); + return non_strict_search(*blueprint, *md, docid_limit, filter_hit_ratio); } } 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 7a7abb20cdf..992ac320385 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 @@ -179,9 +179,9 @@ struct WandBlueprintSpec Node::UP term = createNode(); Blueprint::UP bp = blueprint(searchable, field, *term); MatchData::UP md(MatchData::makeTestInstance(1, 1)); - bp->fetchPostings(ExecuteInfo::TRUE); - bp->setDocIdLimit(docIdLimit); - SearchIterator::UP sb = bp->createSearch(*md, true); + bp->basic_plan(true, docIdLimit); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP sb = bp->createSearch(*md); EXPECT_TRUE(dynamic_cast<ParallelWeakAndSearch*>(sb.get()) != 0); return sb; } @@ -194,9 +194,9 @@ struct WandBlueprintSpec FakeResult search(Searchable &searchable, const std::string &field, const search::query::Node &term) const { Blueprint::UP bp = blueprint(searchable, field, term); MatchData::UP md(MatchData::makeTestInstance(1, 1)); - bp->fetchPostings(ExecuteInfo::TRUE); - bp->setDocIdLimit(docIdLimit); - SearchIterator::UP sb = bp->createSearch(*md, true); + bp->basic_plan(true, docIdLimit); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP sb = bp->createSearch(*md); EXPECT_TRUE(dynamic_cast<ParallelWeakAndSearch*>(sb.get()) != 0); return doSearch(*sb, *md->resolveTermField(handle)); } diff --git a/searchlib/src/tests/queryeval/predicate/predicate_blueprint_test.cpp b/searchlib/src/tests/queryeval/predicate/predicate_blueprint_test.cpp index ed349480ff4..ffa2905ce0e 100644 --- a/searchlib/src/tests/queryeval/predicate/predicate_blueprint_test.cpp +++ b/searchlib/src/tests/queryeval/predicate/predicate_blueprint_test.cpp @@ -128,13 +128,14 @@ TEST_F("require that blueprint with zstar-compressed estimates non-empty.", Fixt void runQuery(Fixture & f, std::vector<uint32_t> expected, bool expectCachedSize, uint32_t expectedKV) { PredicateBlueprint blueprint(f.field, f.guard(), f.query); - blueprint.fetchPostings(ExecuteInfo::TRUE); + blueprint.basic_plan(true, 100); + blueprint.fetchPostings(ExecuteInfo::FULL); EXPECT_EQUAL(expectCachedSize, blueprint.getCachedFeatures().size()); for (uint32_t docId : expected) { EXPECT_EQUAL(expectedKV, uint32_t(blueprint.getKV()[docId])); } TermFieldMatchDataArray tfmda; - SearchIterator::UP it = blueprint.createLeafSearch(tfmda, true); + SearchIterator::UP it = blueprint.createLeafSearch(tfmda); ASSERT_TRUE(it.get()); it->initFullRange(); EXPECT_EQUAL(SearchIterator::beginId(), it->getDocId()); @@ -172,9 +173,10 @@ TEST_F("require that blueprint can create more advanced search", Fixture) { f.indexEmptyDocument(doc_id + 2); PredicateBlueprint blueprint(f.field, f.guard(), f.query); - blueprint.fetchPostings(ExecuteInfo::TRUE); + blueprint.basic_plan(true, 100); + blueprint.fetchPostings(ExecuteInfo::FULL); TermFieldMatchDataArray tfmda; - SearchIterator::UP it = blueprint.createLeafSearch(tfmda, true); + SearchIterator::UP it = blueprint.createLeafSearch(tfmda); ASSERT_TRUE(it.get()); it->initFullRange(); EXPECT_EQUAL(SearchIterator::beginId(), it->getDocId()); @@ -195,9 +197,10 @@ TEST_F("require that blueprint can create NOT search", Fixture) { f.indexDocument(doc_id, annotations); PredicateBlueprint blueprint(f.field, f.guard(), f.query); - blueprint.fetchPostings(ExecuteInfo::TRUE); + blueprint.basic_plan(true, 100); + blueprint.fetchPostings(ExecuteInfo::FULL); TermFieldMatchDataArray tfmda; - SearchIterator::UP it = blueprint.createLeafSearch(tfmda, true); + SearchIterator::UP it = blueprint.createLeafSearch(tfmda); ASSERT_TRUE(it.get()); it->initFullRange(); EXPECT_TRUE(it->seek(doc_id)); @@ -211,9 +214,10 @@ TEST_F("require that blueprint can create compressed NOT search", Fixture) { f.indexDocument(doc_id, annotations); PredicateBlueprint blueprint(f.field, f.guard(), f.query); - blueprint.fetchPostings(ExecuteInfo::TRUE); + blueprint.basic_plan(true, 100); + blueprint.fetchPostings(ExecuteInfo::FULL); TermFieldMatchDataArray tfmda; - SearchIterator::UP it = blueprint.createLeafSearch(tfmda, true); + SearchIterator::UP it = blueprint.createLeafSearch(tfmda); ASSERT_TRUE(it.get()); it->initFullRange(); EXPECT_TRUE(it->seek(doc_id)); @@ -235,9 +239,10 @@ TEST_F("require that blueprint can set up search with subqueries", Fixture) { query.getTerm()->addFeature("key2", "value", 2); PredicateBlueprint blueprint(f.field, f.guard(), query); - blueprint.fetchPostings(ExecuteInfo::TRUE); + blueprint.basic_plan(true, 100); + blueprint.fetchPostings(ExecuteInfo::FULL); TermFieldMatchDataArray tfmda; - SearchIterator::UP it = blueprint.createLeafSearch(tfmda, true); + SearchIterator::UP it = blueprint.createLeafSearch(tfmda); ASSERT_TRUE(it.get()); it->initFullRange(); EXPECT_FALSE(it->seek(doc_id)); diff --git a/searchlib/src/tests/queryeval/queryeval_test.cpp b/searchlib/src/tests/queryeval/queryeval_test.cpp index e8f30ba84ff..b72481d24cf 100644 --- a/searchlib/src/tests/queryeval/queryeval_test.cpp +++ b/searchlib/src/tests/queryeval/queryeval_test.cpp @@ -220,8 +220,9 @@ TEST(QueryEvalTest, test_and) { auto and_b = std::make_unique<AndBlueprint>(); and_b->addChild(std::make_unique<SimpleBlueprint>(a)); and_b->addChild(std::make_unique<SimpleBlueprint>(b)); - and_b->fetchPostings(ExecuteInfo::TRUE); - SearchIterator::UP and_ab = and_b->createSearch(*md, true); + and_b->basic_plan(true, 1000); + and_b->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP and_ab = and_b->createSearch(*md); EXPECT_TRUE(dynamic_cast<const AndSearch *>(and_ab.get()) != nullptr); EXPECT_EQ(4u, dynamic_cast<AndSearch &>(*and_ab).estimate()); @@ -231,14 +232,16 @@ TEST(QueryEvalTest, test_and) { expect.addHit(5).addHit(30); EXPECT_EQ(res, expect); - SearchIterator::UP filter_ab = and_b->createFilterSearch(true, upper_bound); + SearchIterator::UP filter_ab = and_b->createFilterSearch(upper_bound); SimpleResult filter_res; filter_res.search(*filter_ab); EXPECT_EQ(res, expect); std::string dump = filter_ab->asString(); expect_match(dump, "upper"); expect_match(dump, "AndSearchStrict.*NoUnpack.*SimpleSearch.*upper.*SimpleSearch.*upper"); - filter_ab = and_b->createFilterSearch(false, lower_bound); + and_b->basic_plan(false, 1000); + and_b->fetchPostings(ExecuteInfo::FULL); + filter_ab = and_b->createFilterSearch(lower_bound); dump = filter_ab->asString(); expect_match(dump, "lower"); expect_match(dump, "AndSearchNoStrict.*NoUnpack.*SimpleSearch.*lower.*SimpleSearch.*lower"); @@ -256,8 +259,9 @@ TEST(QueryEvalTest, test_or) auto or_b = std::make_unique<OrBlueprint>(); or_b->addChild(std::make_unique<SimpleBlueprint>(a)); or_b->addChild(std::make_unique<SimpleBlueprint>(b)); - or_b->fetchPostings(ExecuteInfo::TRUE); - SearchIterator::UP or_ab = or_b->createSearch(*md, true); + or_b->basic_plan(true, 1000); + or_b->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP or_ab = or_b->createSearch(*md); SimpleResult res; res.search(*or_ab); @@ -265,14 +269,16 @@ TEST(QueryEvalTest, test_or) expect.addHit(5).addHit(10).addHit(17).addHit(30); EXPECT_EQ(res, expect); - SearchIterator::UP filter_ab = or_b->createFilterSearch(true, upper_bound); + SearchIterator::UP filter_ab = or_b->createFilterSearch(upper_bound); SimpleResult filter_res; filter_res.search(*filter_ab); EXPECT_EQ(res, expect); std::string dump = filter_ab->asString(); expect_match(dump, "upper"); expect_match(dump, "StrictHeapOrSearch.*NoUnpack.*SimpleSearch.*upper.*SimpleSearch.*upper"); - filter_ab = or_b->createFilterSearch(false, lower_bound); + or_b->basic_plan(false, 1000); + or_b->fetchPostings(ExecuteInfo::FULL); + filter_ab = or_b->createFilterSearch(lower_bound); dump = filter_ab->asString(); expect_match(dump, "lower"); expect_match(dump, "OrLikeSearch.false.*NoUnpack.*SimpleSearch.*lower.*SimpleSearch.*lower"); @@ -365,13 +371,13 @@ public: : default_flow_stats(docid_limit, est.est_hits(), 0); } SearchIterator::UP - createLeafSearch(const TermFieldMatchDataArray &tfmda, bool strict) const override + createLeafSearch(const TermFieldMatchDataArray &tfmda) const override { (void) tfmda; - return _sc->createIterator(&_tfmd, strict); + return _sc->createIterator(&_tfmd, strict()); } - SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { - return create_default_filter(strict, constraint); + SearchIteratorUP createFilterSearch(FilterConstraint constraint) const override { + return create_default_filter(constraint); } private: search::SingleBoolAttribute _a; @@ -392,8 +398,9 @@ TEST(QueryEvalTest, test_andnot) auto andnot_b = std::make_unique<AndNotBlueprint>(); andnot_b->addChild(std::make_unique<SimpleBlueprint>(a)); andnot_b->addChild(std::make_unique<SimpleBlueprint>(b)); - andnot_b->fetchPostings(ExecuteInfo::TRUE); - SearchIterator::UP andnot_ab = andnot_b->createSearch(*md, true); + andnot_b->basic_plan(true, 1000); + andnot_b->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP andnot_ab = andnot_b->createSearch(*md); SimpleResult res; res.search(*andnot_ab); @@ -401,14 +408,16 @@ TEST(QueryEvalTest, test_andnot) expect.addHit(10); EXPECT_EQ(res, expect); - SearchIterator::UP filter_ab = andnot_b->createFilterSearch(true, upper_bound); + SearchIterator::UP filter_ab = andnot_b->createFilterSearch(upper_bound); SimpleResult filter_res; filter_res.search(*filter_ab); EXPECT_EQ(res, expect); std::string dump = filter_ab->asString(); expect_match(dump, "upper"); expect_match(dump, "AndNotSearch.*SimpleSearch.*<strict,upper>.*SimpleSearch.*<nostrict,lower>"); - filter_ab = andnot_b->createFilterSearch(false, lower_bound); + andnot_b->basic_plan(false, 1000); + andnot_b->fetchPostings(ExecuteInfo::FULL); + filter_ab = andnot_b->createFilterSearch(lower_bound); dump = filter_ab->asString(); expect_match(dump, "lower"); expect_match(dump, "AndNotSearch.*SimpleSearch.*<nostrict,lower>.*SimpleSearch.*<nostrict,upper>"); @@ -423,8 +432,9 @@ TEST(QueryEvalTest, test_andnot) auto andnot_b = std::make_unique<AndNotBlueprint>(); andnot_b->addChild(std::make_unique<SimpleBlueprint>(a)); andnot_b->addChild(std::make_unique<DummySingleValueBitNumericAttributeBlueprint>(b)); - andnot_b->fetchPostings(ExecuteInfo::TRUE); - SearchIterator::UP andnot_ab = andnot_b->createSearch(*md, true); + andnot_b->basic_plan(true, 1000); + andnot_b->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP andnot_ab = andnot_b->createSearch(*md); SimpleResult res; res.search(*andnot_ab); @@ -449,8 +459,9 @@ TEST(QueryEvalTest, test_andnot) auto and_b = std::make_unique<AndBlueprint>(); and_b->addChild(std::make_unique<SimpleBlueprint>(c)); and_b->addChild(std::move(andnot_b)); - and_b->fetchPostings(ExecuteInfo::TRUE); - SearchIterator::UP and_cab = and_b->createSearch(*md, true); + and_b->basic_plan(true, 1000); + and_b->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP and_cab = and_b->createSearch(*md); SimpleResult res; res.search(*and_cab); @@ -475,8 +486,9 @@ TEST(QueryEvalTest, test_rank) auto rank_b = std::make_unique<RankBlueprint>(); rank_b->addChild(std::make_unique<SimpleBlueprint>(a)); rank_b->addChild(std::make_unique<SimpleBlueprint>(b)); - rank_b->fetchPostings(ExecuteInfo::TRUE); - SearchIterator::UP rank_ab = rank_b->createSearch(*md, true); + rank_b->basic_plan(true, 1000); + rank_b->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP rank_ab = rank_b->createSearch(*md); SimpleResult res; res.search(*rank_ab); diff --git a/searchlib/src/tests/queryeval/same_element/same_element_test.cpp b/searchlib/src/tests/queryeval/same_element/same_element_test.cpp index 64f4fafd2d1..9d93ade71d9 100644 --- a/searchlib/src/tests/queryeval/same_element/same_element_test.cpp +++ b/searchlib/src/tests/queryeval/same_element/same_element_test.cpp @@ -46,9 +46,8 @@ std::unique_ptr<SameElementBlueprint> make_blueprint(const std::vector<FakeResul } Blueprint::UP finalize(Blueprint::UP bp, bool strict) { - auto opts = Blueprint::Options::all(); - Blueprint::UP result = Blueprint::optimize_and_sort(std::move(bp), true, opts); - result->fetchPostings(ExecuteInfo::createForTest(strict)); + Blueprint::UP result = Blueprint::optimize_and_sort(std::move(bp), strict); + result->fetchPostings(ExecuteInfo::FULL); result->freeze(); return result; } @@ -56,7 +55,7 @@ Blueprint::UP finalize(Blueprint::UP bp, bool strict) { SimpleResult find_matches(const std::vector<FakeResult> &children) { auto md = make_match_data(); auto bp = finalize(make_blueprint(children), false); - auto search = bp->createSearch(*md, false); + auto search = bp->createSearch(*md); return SimpleResult().search(*search, 1000); } @@ -85,7 +84,7 @@ TEST("require that matching elements can be identified") { auto b = make_result({{5, {3,5,7,10}}, {10, {4,5,6}}}); auto bp = finalize(make_blueprint({a,b}), false); auto md = make_match_data(); - auto search = bp->createSearch(*md, false); + auto search = bp->createSearch(*md); search->initRange(1, 1000); auto *se = dynamic_cast<SameElementSearch*>(search.get()); ASSERT_TRUE(se != nullptr); @@ -107,7 +106,7 @@ TEST("require that strict iterator seeks to next hit and can unpack matching doc auto a = make_result({{5, {1,2}}, {7, {1,2}}, {8, {1,2}}, {9, {1,2}}}); auto b = make_result({{5, {3}}, {6, {1,2}}, {7, {2,4}}, {9, {1}}}); auto bp = finalize(make_blueprint({a,b}), true); - auto search = bp->createSearch(*md, true); + auto search = bp->createSearch(*md); auto* tfmd = md->resolveTermField(0); search->initRange(1, 1000); EXPECT_LESS(search->getDocId(), 1u); @@ -145,9 +144,9 @@ TEST("require that children are sorted") { TEST("require that attribute iterators are wrapped for element unpacking") { auto a = make_result({{5, {1,3,7}}}); auto b = make_result({{5, {3,5,10}}}); - auto bp = finalize(make_blueprint({a,b}, true), true); + auto bp = finalize(make_blueprint({a,b}, true), false); auto md = make_match_data(); - auto search = bp->createSearch(*md, false); + auto search = bp->createSearch(*md); auto *se = dynamic_cast<SameElementSearch*>(search.get()); ASSERT_TRUE(se != nullptr); ASSERT_EQUAL(se->children().size(), 2u); diff --git a/searchlib/src/tests/queryeval/simple_phrase/simple_phrase_test.cpp b/searchlib/src/tests/queryeval/simple_phrase/simple_phrase_test.cpp index 99812900d40..3e779bdca14 100644 --- a/searchlib/src/tests/queryeval/simple_phrase/simple_phrase_test.cpp +++ b/searchlib/src/tests/queryeval/simple_phrase/simple_phrase_test.cpp @@ -38,11 +38,11 @@ struct MyTerm : public search::queryeval::SimpleLeafBlueprint { FlowStats calculate_flow_stats(uint32_t docid_limit) const override { return default_flow_stats(docid_limit, getState().estimate().estHits, 0); } - SearchIterator::UP createLeafSearch(const search::fef::TermFieldMatchDataArray &, bool) const override { + SearchIterator::UP createLeafSearch(const search::fef::TermFieldMatchDataArray &) const override { return {}; } - SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { - return create_default_filter(strict, constraint); + SearchIteratorUP createFilterSearch(FilterConstraint constraint) const override { + return create_default_filter(constraint); } }; @@ -146,12 +146,14 @@ public: void fetchPostings(bool useBlueprint) { - ExecuteInfo execInfo = ExecuteInfo::createForTest(_strict); + ExecuteInfo execInfo = ExecuteInfo::FULL; if (useBlueprint) { + _phrase.basic_plan(_strict, 100); _phrase.fetchPostings(execInfo); return; } for (const auto & i : _children) { + i->basic_plan(_strict, 100); i->fetchPostings(execInfo); } } @@ -160,7 +162,7 @@ public: SearchIterator *createSearch(bool useBlueprint) { SearchIterator::UP search; if (useBlueprint) { - search = _phrase.createSearch(*_md, _strict); + search = _phrase.createSearch(*_md); } else { search::fef::TermFieldMatchDataArray childMatch; for (size_t i = 0; i < _children.size(); ++i) { @@ -171,7 +173,7 @@ public: } SimplePhraseSearch::Children children; for (const auto & i : _children) { - children.push_back(i->createSearch(*_md, _strict)); + children.push_back(i->createSearch(*_md)); } search = std::make_unique<SimplePhraseSearch>(std::move(children), MatchData::UP(), childMatch, _order, diff --git a/searchlib/src/tests/queryeval/sourceblender/sourceblender_test.cpp b/searchlib/src/tests/queryeval/sourceblender/sourceblender_test.cpp index a266902445b..b84cb02a357 100644 --- a/searchlib/src/tests/queryeval/sourceblender/sourceblender_test.cpp +++ b/searchlib/src/tests/queryeval/sourceblender/sourceblender_test.cpp @@ -76,8 +76,9 @@ TEST(SourceBlenderTest, test_strictness) blend_b->addChild(std::move(a_b)); blend_b->addChild(std::move(b_b)); Blueprint::UP bp(blend_b); - bp->fetchPostings(ExecuteInfo::createForTest(strict)); - SearchIterator::UP search = bp->createSearch(*md, strict); + bp->basic_plan(strict, 100); + bp->fetchPostings(ExecuteInfo::FULL); + SearchIterator::UP search = bp->createSearch(*md); search->initFullRange(); SearchIterator &blend = *search; diff --git a/searchlib/src/tests/queryeval/termwise_eval/termwise_eval_test.cpp b/searchlib/src/tests/queryeval/termwise_eval/termwise_eval_test.cpp index 2a3ce66dba6..310c6d628e3 100644 --- a/searchlib/src/tests/queryeval/termwise_eval/termwise_eval_test.cpp +++ b/searchlib/src/tests/queryeval/termwise_eval/termwise_eval_test.cpp @@ -86,13 +86,11 @@ struct MyBlueprint : SimpleLeafBlueprint { FlowStats calculate_flow_stats(uint32_t docid_limit) const override { return default_flow_stats(docid_limit, getState().estimate().estHits, 0); } - SearchIterator::UP createLeafSearch(const fef::TermFieldMatchDataArray &, - bool strict) const override - { - return std::make_unique<MyTerm>(hits, strict); + SearchIterator::UP createLeafSearch(const fef::TermFieldMatchDataArray &) const override { + return std::make_unique<MyTerm>(hits, strict()); } - SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { - return create_default_filter(strict, constraint); + SearchIteratorUP createFilterSearch(FilterConstraint constraint) const override { + return create_default_filter(constraint); } }; @@ -416,7 +414,8 @@ TEST(TermwiseEvalTest, require_that_basic_termwise_evaluation_works) my_or.addChild(UP(new MyBlueprint({1}, true, 1))); my_or.addChild(UP(new MyBlueprint({2}, true, 2))); for (bool strict: {true, false}) { - EXPECT_EQ(my_or.createSearch(*md, strict)->asString(), + my_or.basic_plan(strict, 100); + EXPECT_EQ(my_or.createSearch(*md)->asString(), make_termwise(OR({ TERM({1}, strict), TERM({2}, strict) }, strict), strict)->asString()); } } @@ -431,7 +430,8 @@ TEST(TermwiseEvalTest, require_that_the_hit_rate_must_be_high_enough_for_termwis my_or.addChild(UP(new MyBlueprint({1}, true, 1))); my_or.addChild(UP(new MyBlueprint({2}, true, 2))); for (bool strict: {true, false}) { - EXPECT_TRUE(my_or.createSearch(*md, strict)->asString().find("TermwiseSearch") == vespalib::string::npos); + my_or.basic_plan(strict, 100); + EXPECT_TRUE(my_or.createSearch(*md)->asString().find("TermwiseSearch") == vespalib::string::npos); } } @@ -446,7 +446,8 @@ TEST(TermwiseEvalTest, require_that_enough_unranked_termwise_terms_are_present_f my_or.addChild(UP(new MyBlueprint({2}, false, 2))); // <- not termwise my_or.addChild(UP(new MyBlueprint({3}, true, 3))); // <- ranked for (bool strict: {true, false}) { - EXPECT_TRUE(my_or.createSearch(*md, strict)->asString().find("TermwiseSearch") == vespalib::string::npos); + my_or.basic_plan(strict, 100); + EXPECT_TRUE(my_or.createSearch(*md)->asString().find("TermwiseSearch") == vespalib::string::npos); } } @@ -464,7 +465,8 @@ TEST(TermwiseEvalTest, require_that_termwise_evaluation_can_be_multi_level_but_n child->addChild(UP(new MyBlueprint({3}, true, 3))); my_or.addChild(std::move(child)); for (bool strict: {true, false}) { - EXPECT_EQ(my_or.createSearch(*md, strict)->asString(), + my_or.basic_plan(strict, 100); + EXPECT_EQ(my_or.createSearch(*md)->asString(), make_termwise(OR({ TERM({1}, strict), ORz({ TERM({2}, strict), TERM({3}, strict) }, strict) }, strict), strict)->asString()); @@ -483,7 +485,8 @@ TEST(TermwiseEvalTest, require_that_or_can_be_completely_termwise) my_or.addChild(UP(new MyBlueprint({1}, true, 1))); my_or.addChild(UP(new MyBlueprint({2}, true, 2))); for (bool strict: {true, false}) { - EXPECT_EQ(my_or.createSearch(*md, strict)->asString(), + my_or.basic_plan(strict, 100); + EXPECT_EQ(my_or.createSearch(*md)->asString(), make_termwise(OR({ TERM({1}, strict), TERM({2}, strict) }, strict), strict)->asString()); } } @@ -499,7 +502,8 @@ TEST(TermwiseEvalTest, require_that_or_can_be_partially_termwise) my_or.addChild(UP(new MyBlueprint({2}, true, 2))); my_or.addChild(UP(new MyBlueprint({3}, true, 3))); for (bool strict: {true, false}) { - EXPECT_EQ(my_or.createSearch(*md, strict)->asString(), + my_or.basic_plan(strict, 100); + EXPECT_EQ(my_or.createSearch(*md)->asString(), ORs({ make_termwise(OR({ TERM({1}, strict), TERM({3}, strict) }, strict), strict), TERM({2}, strict) }, strict)->asString()); } @@ -516,7 +520,8 @@ TEST(TermwiseEvalTest, require_that_or_puts_termwise_subquery_at_the_right_place my_or.addChild(UP(new MyBlueprint({2}, true, 2))); my_or.addChild(UP(new MyBlueprint({3}, true, 3))); for (bool strict: {true, false}) { - EXPECT_EQ(my_or.createSearch(*md, strict)->asString(), + my_or.basic_plan(strict, 100); + EXPECT_EQ(my_or.createSearch(*md)->asString(), ORs({ TERM({1}, strict), make_termwise(OR({ TERM({2}, strict), TERM({3}, strict) }, strict), strict) }, strict)->asString()); @@ -535,7 +540,8 @@ TEST(TermwiseEvalTest, require_that_or_can_use_termwise_eval_also_when_having_no my_or.addChild(UP(new MyBlueprint({2}, true, 2))); my_or.addChild(UP(new MyBlueprint({3}, true, 3))); for (bool strict: {true, false}) { - EXPECT_EQ(my_or.createSearch(*md, strict)->asString(), + my_or.basic_plan(strict, 100); + EXPECT_EQ(my_or.createSearch(*md)->asString(), ORz({ TERM({1}, strict), make_termwise(OR({ TERM({2}, strict), TERM({3}, strict) }, strict), strict)}, @@ -555,7 +561,8 @@ TEST(TermwiseEvalTest, require_that_and_can_be_completely_termwise) my_and.addChild(UP(new MyBlueprint({1}, true, 1))); my_and.addChild(UP(new MyBlueprint({2}, true, 2))); for (bool strict: {true, false}) { - EXPECT_EQ(my_and.createSearch(*md, strict)->asString(), + my_and.basic_plan(strict, 100); + EXPECT_EQ(my_and.createSearch(*md)->asString(), make_termwise(AND({ TERM({1}, strict), TERM({2}, false) }, strict), strict)->asString()); } } @@ -571,7 +578,8 @@ TEST(TermwiseEvalTest, require_that_and_can_be_partially_termwise) my_and.addChild(UP(new MyBlueprint({2}, true, 2))); my_and.addChild(UP(new MyBlueprint({3}, true, 3))); for (bool strict: {true, false}) { - EXPECT_EQ(my_and.createSearch(*md, strict)->asString(), + my_and.basic_plan(strict, 100); + EXPECT_EQ(my_and.createSearch(*md)->asString(), ANDs({ make_termwise(AND({ TERM({1}, strict), TERM({3}, false) }, strict), strict), @@ -590,7 +598,8 @@ TEST(TermwiseEvalTest, require_that_and_puts_termwise_subquery_at_the_right_plac my_and.addChild(UP(new MyBlueprint({2}, true, 2))); my_and.addChild(UP(new MyBlueprint({3}, true, 3))); for (bool strict: {true, false}) { - EXPECT_EQ(my_and.createSearch(*md, strict)->asString(), + my_and.basic_plan(strict, 100); + EXPECT_EQ(my_and.createSearch(*md)->asString(), ANDs({ TERM({1}, strict), make_termwise(AND({ TERM({2}, false), TERM({3}, false) }, false), false) }, strict)->asString()); @@ -609,7 +618,8 @@ TEST(TermwiseEvalTest, require_that_and_can_use_termwise_eval_also_when_having_n my_and.addChild(UP(new MyBlueprint({2}, true, 2))); my_and.addChild(UP(new MyBlueprint({3}, true, 3))); for (bool strict: {true, false}) { - EXPECT_EQ(my_and.createSearch(*md, strict)->asString(), + my_and.basic_plan(strict, 100); + EXPECT_EQ(my_and.createSearch(*md)->asString(), ANDz({ TERM({1}, strict), make_termwise(AND({ TERM({2}, false), TERM({3}, false) }, false), false) }, strict)->asString()); @@ -627,7 +637,8 @@ TEST(TermwiseEvalTest, require_that_andnot_can_be_completely_termwise) my_andnot.addChild(UP(new MyBlueprint({1}, true, 1))); my_andnot.addChild(UP(new MyBlueprint({2}, true, 2))); for (bool strict: {true, false}) { - EXPECT_EQ(my_andnot.createSearch(*md, strict)->asString(), + my_andnot.basic_plan(strict, 100); + EXPECT_EQ(my_andnot.createSearch(*md)->asString(), make_termwise(ANDNOT({ TERM({1}, strict), TERM({2}, false) }, strict), strict)->asString()); } @@ -642,7 +653,8 @@ TEST(TermwiseEvalTest, require_that_andnot_can_be_partially_termwise) my_andnot.addChild(UP(new MyBlueprint({2}, true, 2))); my_andnot.addChild(UP(new MyBlueprint({3}, true, 3))); for (bool strict: {true, false}) { - EXPECT_EQ(my_andnot.createSearch(*md, strict)->asString(), + my_andnot.basic_plan(strict, 100); + EXPECT_EQ(my_andnot.createSearch(*md)->asString(), ANDNOT({ TERM({1}, strict), make_termwise(OR({ TERM({2}, false), TERM({3}, false) }, false), false) }, strict)->asString()); @@ -659,7 +671,8 @@ TEST(TermwiseEvalTest, require_that_andnot_can_be_partially_termwise_with_first_ my_andnot.addChild(UP(new MyBlueprint({2}, false, 2))); my_andnot.addChild(UP(new MyBlueprint({3}, true, 3))); for (bool strict: {true, false}) { - EXPECT_EQ(my_andnot.createSearch(*md, strict)->asString(), + my_andnot.basic_plan(strict, 100); + EXPECT_EQ(my_andnot.createSearch(*md)->asString(), ANDNOT({ make_termwise(ANDNOT({ TERM({1}, strict), TERM({3}, false) }, strict), strict), TERM({2}, false) }, strict)->asString()); diff --git a/searchlib/src/tests/queryeval/weighted_set_term/weighted_set_term_test.cpp b/searchlib/src/tests/queryeval/weighted_set_term/weighted_set_term_test.cpp index 54663e48060..57e41fef13b 100644 --- a/searchlib/src/tests/queryeval/weighted_set_term/weighted_set_term_test.cpp +++ b/searchlib/src/tests/queryeval/weighted_set_term/weighted_set_term_test.cpp @@ -69,8 +69,9 @@ struct WS { FieldSpecList fields; fields.add(FieldSpec(field, fieldId, handle)); auto bp = searchable.createBlueprint(requestContext, fields, *node); - bp->fetchPostings(ExecuteInfo::createForTest(strict)); - auto sb = bp->createSearch(*md, strict); + bp->basic_plan(strict, 1000); + bp->fetchPostings(ExecuteInfo::FULL); + auto sb = bp->createSearch(*md); return (dynamic_cast<WeightedSetTermSearch*>(sb.get()) != nullptr); } @@ -84,8 +85,9 @@ struct WS { FieldSpecList fields; fields.add(FieldSpec(field, fieldId, handle, field_is_filter)); auto bp = searchable.createBlueprint(requestContext, fields, *node); - bp->fetchPostings(ExecuteInfo::createForTest(strict)); - auto sb = bp->createSearch(*md, strict); + bp->basic_plan(strict, 1000); + bp->fetchPostings(ExecuteInfo::FULL); + auto sb = bp->createSearch(*md); sb->initFullRange(); FakeResult result; for (uint32_t docId = 1; docId < 10; ++docId) { @@ -333,7 +335,7 @@ struct VerifyMatchData { VerifyMatchData &vmd; MyBlueprint(VerifyMatchData &vmd_in, FieldSpecBase spec_in) : SimpleLeafBlueprint(spec_in), vmd(vmd_in) {} - [[nodiscard]] SearchIterator::UP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool) const override { + [[nodiscard]] SearchIterator::UP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda) const override { EXPECT_EQ(tfmda.size(), 1u); EXPECT_TRUE(tfmda[0] != nullptr); if (vmd.child_tfmd == nullptr) { @@ -347,8 +349,8 @@ struct VerifyMatchData { FlowStats calculate_flow_stats(uint32_t docid_limit) const override { return default_flow_stats(docid_limit, 0, 0); } - [[nodiscard]] SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { - return create_default_filter(strict, constraint); + [[nodiscard]] SearchIteratorUP createFilterSearch(FilterConstraint constraint) const override { + return create_default_filter(constraint); } }; size_t child_cnt = 0; @@ -371,7 +373,12 @@ TEST(WeightedSetTermTest, require_that_children_get_a_common_yet_separate_term_f } blueprint.complete(estimate); auto match_data = layout.createMatchData(); - auto search = blueprint.createSearch(*match_data, true); + blueprint.basic_plan(true, 1000); + { + Blueprint &bp = blueprint; + bp.fetchPostings(ExecuteInfo::FULL); + } + auto search = blueprint.createSearch(*match_data); auto top_tfmd = match_data->resolveTermField(top_handle); EXPECT_EQ(vmd.child_cnt, 5u); EXPECT_TRUE(vmd.child_tfmd != nullptr); |