diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-07-20 12:21:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-20 12:21:58 +0200 |
commit | 67893969909e31df00b319460102ffed503c7d7b (patch) | |
tree | bcc1574baa312379d15bb00233a8e21cef28fbe8 /searchcore | |
parent | c0295935ea3e251982dee93e0dd39e0f0d2ad030 (diff) | |
parent | 4becd1651e549393dd555095d99abe6f4452afd1 (diff) |
Merge pull request #6439 from vespa-engine/balder/lift-rankitem
Balder/lift rankitem
Diffstat (limited to 'searchcore')
3 files changed, 53 insertions, 4 deletions
diff --git a/searchcore/src/tests/proton/matching/query_test.cpp b/searchcore/src/tests/proton/matching/query_test.cpp index 61823a17f09..ed436e30cdc 100644 --- a/searchcore/src/tests/proton/matching/query_test.cpp +++ b/searchcore/src/tests/proton/matching/query_test.cpp @@ -63,6 +63,10 @@ using search::queryeval::SearchIterator; using search::queryeval::SimpleBlueprint; using search::queryeval::SimpleResult; using search::queryeval::ParallelWeakAndBlueprint; +using search::queryeval::RankBlueprint; +using search::queryeval::AndBlueprint; +using search::queryeval::SourceBlenderBlueprint; + using std::string; using std::vector; namespace fef_test = search::fef::test; @@ -106,6 +110,7 @@ class Test : public vespalib::TestApp { void requireThatWeakAndBlueprintsAreCreatedCorrectly(); void requireThatParallelWandBlueprintsAreCreatedCorrectly(); void requireThatWhiteListBlueprintCanBeUsed(); + void requireThatRankBlueprintStaysOnTopAfterWhiteListing(); void requireThatSameElementTermsAreProperlyPrefixed(); void requireThatSameElementDoesNotAllocateMatchData(); void requireThatSameElementIteratorsCanBeBuilt(); @@ -879,6 +884,38 @@ Test::requireThatWhiteListBlueprintCanBeUsed() EXPECT_EQUAL(exp, act); } +void Test::requireThatRankBlueprintStaysOnTopAfterWhiteListing() { + QueryBuilder<ProtonNodeTypes> builder; + builder.addRank(2); + builder.addStringTerm("foo", field, field_id, string_weight); + builder.addStringTerm("bar", field, field_id, string_weight); + std::string stackDump = StackDumpCreator::create(*builder.build()); + Query query; + query.buildTree(stackDump, "", ViewResolver(), plain_index_env); + FakeSearchContext context(42); + context.addIdx(0).idx(0).getFake() + .addResult(field, "foo", FakeResult().doc(1)); + context.setLimit(42); + + query.setWhiteListBlueprint(std::make_unique<SimpleBlueprint>(SimpleResult())); + + FakeRequestContext requestContext; + MatchDataLayout mdl; + query.reserveHandles(requestContext, context, mdl); + const RankBlueprint * root = dynamic_cast<const RankBlueprint *>(query.peekRoot()); + ASSERT_TRUE(root != nullptr); + EXPECT_EQUAL(2u, root->childCnt()); + const AndBlueprint * first = dynamic_cast<const AndBlueprint *>(&root->getChild(0)); + ASSERT_TRUE(first != nullptr); + EXPECT_EQUAL(2u, first->childCnt()); + EXPECT_TRUE(dynamic_cast<const SourceBlenderBlueprint *>(&first->getChild(0))); + EXPECT_TRUE(dynamic_cast<const SimpleBlueprint *>(&first->getChild(1))); + EXPECT_TRUE(dynamic_cast<const SourceBlenderBlueprint *>(&root->getChild(1))); + +} + + + search::query::Node::UP make_same_element_stack_dump(const vespalib::string &prefix, const vespalib::string &term_prefix) { @@ -984,6 +1021,7 @@ Test::Main() TEST_CALL(requireThatWeakAndBlueprintsAreCreatedCorrectly); TEST_CALL(requireThatParallelWandBlueprintsAreCreatedCorrectly); TEST_CALL(requireThatWhiteListBlueprintCanBeUsed); + TEST_CALL(requireThatRankBlueprintStaysOnTopAfterWhiteListing); TEST_CALL(requireThatSameElementTermsAreProperlyPrefixed); TEST_CALL(requireThatSameElementDoesNotAllocateMatchData); TEST_CALL(requireThatSameElementIteratorsCanBeBuilt); diff --git a/searchcore/src/vespa/searchcore/proton/matching/query.cpp b/searchcore/src/vespa/searchcore/proton/matching/query.cpp index 38affde6075..263f2b65eba 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/query.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/query.cpp @@ -28,6 +28,7 @@ using search::query::Node; using search::query::QueryTreeCreator; using search::query::Weight; using search::queryeval::AndBlueprint; +using search::queryeval::RankBlueprint; using search::queryeval::Blueprint; using search::queryeval::IRequestContext; using search::queryeval::SearchIterator; @@ -126,10 +127,18 @@ Query::reserveHandles(const IRequestContext & requestContext, ISearchContext &co LOG(debug, "original blueprint:\n%s\n", _blueprint->asString().c_str()); if (_whiteListBlueprint) { auto andBlueprint = std::make_unique<AndBlueprint>(); - (*andBlueprint) - .addChild(std::move(_blueprint)) - .addChild(std::move(_whiteListBlueprint)); - _blueprint = std::move(andBlueprint); + RankBlueprint * rank = dynamic_cast<RankBlueprint*>(_blueprint.get()); + if (rank != nullptr) { + (*andBlueprint) + .addChild(rank->removeChild(0)) + .addChild(std::move(_whiteListBlueprint)); + rank->insertChild(0, std::move(andBlueprint)); + } else { + (*andBlueprint) + .addChild(std::move(_blueprint)) + .addChild(std::move(_whiteListBlueprint)); + _blueprint = std::move(andBlueprint); + } _blueprint->setDocIdLimit(context.getDocIdLimit()); LOG(debug, "blueprint after white listing:\n%s\n", _blueprint->asString().c_str()); } diff --git a/searchcore/src/vespa/searchcore/proton/matching/query.h b/searchcore/src/vespa/searchcore/proton/matching/query.h index a3b512fc2b7..21365f75133 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/query.h +++ b/searchcore/src/vespa/searchcore/proton/matching/query.h @@ -100,6 +100,8 @@ public: * @return estimate of hits produced. */ Blueprint::HitEstimate estimate() const; + + const Blueprint * peekRoot() const { return _blueprint.get(); } }; } |