diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-06-05 11:41:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-05 11:41:48 +0200 |
commit | c6e0e0ee297f401ce6c51a6f21ea574bda9c3898 (patch) | |
tree | e236ade6f9506e8c3b134b9213ac3e8c2449cc59 /searchcore | |
parent | ae7bf57611e733d0b489d66e3e60b2e6724b7667 (diff) | |
parent | 9755590957e73eed2ac6d9cc684a81a8b9bb14b5 (diff) |
Merge pull request #6075 from vespa-engine/balder/introduce-common-termnode-parent
Balder/introduce common termnode parent
Diffstat (limited to 'searchcore')
4 files changed, 30 insertions, 15 deletions
diff --git a/searchcore/src/tests/proton/matching/query_test.cpp b/searchcore/src/tests/proton/matching/query_test.cpp index 461d2300843..9adb86147b6 100644 --- a/searchcore/src/tests/proton/matching/query_test.cpp +++ b/searchcore/src/tests/proton/matching/query_test.cpp @@ -911,8 +911,8 @@ Test::requireThatSameElementTermsAreProperlyPrefixed() root = dynamic_cast<search::query::SameElement *>(query.get()); EXPECT_EQUAL(root->getView(), "abc"); EXPECT_EQUAL(root->getChildren().size(), 2u); - EXPECT_EQUAL(dynamic_cast<ProtonStringTerm *>(root->getChildren()[0])->getView(), "abc.f1"); - EXPECT_EQUAL(dynamic_cast<ProtonStringTerm *>(root->getChildren()[1])->getView(), "abc.f2"); + EXPECT_EQUAL(dynamic_cast<ProtonStringTerm *>(root->getChildren()[0])->getView(), "abc.abc.f1"); + EXPECT_EQUAL(dynamic_cast<ProtonStringTerm *>(root->getChildren()[1])->getView(), "abc.abc.f2"); } Test::~Test() = default; diff --git a/searchcore/src/vespa/searchcore/proton/matching/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/matching/CMakeLists.txt index 0dee7adfa49..d700aeba6b6 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/CMakeLists.txt +++ b/searchcore/src/vespa/searchcore/proton/matching/CMakeLists.txt @@ -27,6 +27,7 @@ vespa_add_library(searchcore_matching STATIC ranking_constants.cpp requestcontext.cpp result_processor.cpp + sameelementmodifier.cpp same_element_builder.cpp search_session.cpp session_manager_explorer.cpp diff --git a/searchcore/src/vespa/searchcore/proton/matching/sameelementmodifier.cpp b/searchcore/src/vespa/searchcore/proton/matching/sameelementmodifier.cpp new file mode 100644 index 00000000000..da33d444d99 --- /dev/null +++ b/searchcore/src/vespa/searchcore/proton/matching/sameelementmodifier.cpp @@ -0,0 +1,26 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "sameelementmodifier.h" +#include <vespa/vespalib/util/classname.h> +#include <vespa/log/log.h> +LOG_SETUP(".matching.sameelementmodifier"); + +namespace proton::matching { + +void +SameElementModifier::visit(ProtonNodeTypes::SameElement &n) { + if (n.getView().empty()) return; + + vespalib::string prefix = n.getView() + "."; + for (search::query::Node * child : n.getChildren()) { + search::query::TermNode * term = dynamic_cast<search::query::TermNode *>(child); + if (term != nullptr) { + term->setView(prefix + term->getView()); + } else { + LOG(error, "Required a search::query::TermNode. Got %s", vespalib::getClassName(*child).c_str()); + } + } +} + +} + diff --git a/searchcore/src/vespa/searchcore/proton/matching/sameelementmodifier.h b/searchcore/src/vespa/searchcore/proton/matching/sameelementmodifier.h index 6109f5096c3..a42e5b83a0b 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/sameelementmodifier.h +++ b/searchcore/src/vespa/searchcore/proton/matching/sameelementmodifier.h @@ -16,19 +16,7 @@ class SameElementModifier : public search::query::TemplateTermVisitor<SameElemen public: template <class TermNode> void visitTerm(TermNode &) { } - - void visit(ProtonNodeTypes::SameElement &n) override { - if (n.getView().empty()) return; - - vespalib::string prefix = n.getView() + "."; - for (auto & child : n.getChildren()) { - search::query::StringBase * term = dynamic_cast<search::query::StringBase *>(child); - const vespalib::string & index = term->getView(); - if (index.find(prefix) != 0) { // This can be removed when qrs does not prefix the sameelemnt children - term->setView(prefix + index); - } - } - } + void visit(ProtonNodeTypes::SameElement &n) override; }; } |