diff options
author | Henning Baldersheim <balder@oath.com> | 2018-07-24 09:09:20 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-07-24 09:09:20 +0200 |
commit | 9933dd135928b850267f78c2250be35a7969f0d6 (patch) | |
tree | 471702f44787cd66cd7c69bc217bd9559697a977 /searchcore | |
parent | 611d541bb06a168848371ab36959201cd5e766c5 (diff) |
Move the whitelist down through AndNot and Rank to the last one and 'AND' it with the first child there.
Diffstat (limited to 'searchcore')
-rw-r--r-- | searchcore/src/tests/proton/matching/query_test.cpp | 17 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/matching/query.cpp | 13 |
2 files changed, 24 insertions, 6 deletions
diff --git a/searchcore/src/tests/proton/matching/query_test.cpp b/searchcore/src/tests/proton/matching/query_test.cpp index b80fba86796..82aab72068d 100644 --- a/searchcore/src/tests/proton/matching/query_test.cpp +++ b/searchcore/src/tests/proton/matching/query_test.cpp @@ -887,10 +887,11 @@ Test::requireThatWhiteListBlueprintCanBeUsed() EXPECT_EQUAL(exp, act); } -template<typename T> +template<typename T1, typename T2> void verifyThatRankBlueprintAndAndNotStaysOnTopAfterWhiteListing(QueryBuilder<ProtonNodeTypes> & builder) { builder.addStringTerm("foo", field, field_id, string_weight); builder.addStringTerm("bar", field, field_id, string_weight); + builder.addStringTerm("baz", field, field_id, string_weight); std::string stackDump = StackDumpCreator::create(*builder.build()); Query query; query.buildTree(stackDump, "", ViewResolver(), plain_index_env); @@ -904,27 +905,33 @@ void verifyThatRankBlueprintAndAndNotStaysOnTopAfterWhiteListing(QueryBuilder<Pr FakeRequestContext requestContext; MatchDataLayout mdl; query.reserveHandles(requestContext, context, mdl); - const IntermediateBlueprint * root = dynamic_cast<const T *>(query.peekRoot()); + const IntermediateBlueprint * root = dynamic_cast<const T1 *>(query.peekRoot()); ASSERT_TRUE(root != nullptr); EXPECT_EQUAL(2u, root->childCnt()); - const AndBlueprint * first = dynamic_cast<const AndBlueprint *>(&root->getChild(0)); + const IntermediateBlueprint * second = dynamic_cast<const T2 *>(&root->getChild(0)); + ASSERT_TRUE(second != nullptr); + EXPECT_EQUAL(2u, second->childCnt()); + const AndBlueprint * first = dynamic_cast<const AndBlueprint *>(&second->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 *>(&second->getChild(1))); EXPECT_TRUE(dynamic_cast<const SourceBlenderBlueprint *>(&root->getChild(1))); } void Test::requireThatRankBlueprintStaysOnTopAfterWhiteListing() { QueryBuilder<ProtonNodeTypes> builder; builder.addRank(2); - verifyThatRankBlueprintAndAndNotStaysOnTopAfterWhiteListing<RankBlueprint>(builder); + builder.addAndNot(2); + verifyThatRankBlueprintAndAndNotStaysOnTopAfterWhiteListing<RankBlueprint, AndNotBlueprint>(builder); } void Test::requireThatAndNotBlueprintStaysOnTopAfterWhiteListing() { QueryBuilder<ProtonNodeTypes> builder; builder.addAndNot(2); - verifyThatRankBlueprintAndAndNotStaysOnTopAfterWhiteListing<AndNotBlueprint>(builder); + builder.addRank(2); + verifyThatRankBlueprintAndAndNotStaysOnTopAfterWhiteListing<AndNotBlueprint, RankBlueprint>(builder); } diff --git a/searchcore/src/vespa/searchcore/proton/matching/query.cpp b/searchcore/src/vespa/searchcore/proton/matching/query.cpp index 1de664fe6ab..e550ad8cad7 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/query.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/query.cpp @@ -86,6 +86,17 @@ asRankOrAndNot(Blueprint * blueprint) { return rankOrAndNot; } +IntermediateBlueprint * +lastConsequtiveRankOrAndNot(Blueprint * blueprint) { + IntermediateBlueprint * prev = nullptr; + IntermediateBlueprint * curr = asRankOrAndNot(blueprint); + while (curr != nullptr) { + prev = curr; + curr = asRankOrAndNot(&curr->getChild(0)); + } + return prev; +} + } // namespace Query::Query() = default; @@ -139,7 +150,7 @@ 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>(); - IntermediateBlueprint * rankOrAndNot = asRankOrAndNot(_blueprint.get()); + IntermediateBlueprint * rankOrAndNot = lastConsequtiveRankOrAndNot(_blueprint.get()); if (rankOrAndNot != nullptr) { (*andBlueprint) .addChild(rankOrAndNot->removeChild(0)) |