diff options
4 files changed, 42 insertions, 10 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/matching/query.cpp b/searchcore/src/vespa/searchcore/proton/matching/query.cpp index a8f75928a6d..ae9832eaa56 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/query.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/query.cpp @@ -40,7 +40,25 @@ using std::vector; namespace proton::matching { namespace { -void AddLocationNode(const string &location_str, Node::UP &query_tree, Location &fef_location) { + +Node::UP +inject(Node::UP query, Node::UP to_inject) { + if (dynamic_cast<search::query::And *>(query.get())) { + dynamic_cast<search::query::And &>(*query).append(std::move(to_inject)); + } else if (dynamic_cast<search::query::Rank *>(query.get())) { + search::query::Rank & rank = dynamic_cast<search::query::Rank &>(*query); + rank.prepend(inject(rank.stealFirst(), std::move(to_inject))); + } else { + auto new_root = std::make_unique<ProtonAnd>(); + new_root->append(std::move(query)); + new_root->append(std::move(to_inject)); + query = std::move(new_root); + } + return query; +} + +void +addLocationNode(const string &location_str, Node::UP &query_tree, Location &fef_location) { if (location_str.empty()) { return; } @@ -61,20 +79,16 @@ void AddLocationNode(const string &location_str, Node::UP &query_tree, Location int32_t id = -1; Weight weight(100); - auto new_base = std::make_unique<ProtonAnd>(); - new_base->append(std::move(query_tree)); - if (locationSpec.getRankOnDistance()) { - new_base->append(std::make_unique<ProtonLocationTerm>(loc, view, id, weight)); + query_tree = inject(std::move(query_tree), std::make_unique<ProtonLocationTerm>(loc, view, id, weight)); fef_location.setAttribute(view); fef_location.setXPosition(locationSpec.getX()); fef_location.setYPosition(locationSpec.getY()); fef_location.setXAspect(locationSpec.getXAspect()); fef_location.setValid(true); } else if (locationSpec.getPruneOnDistance()) { - new_base->append(std::make_unique<ProtonLocationTerm>(loc, view, id, weight)); + query_tree = inject(std::move(query_tree), std::make_unique<ProtonLocationTerm>(loc, view, id, weight)); } - query_tree = std::move(new_base); } IntermediateBlueprint * @@ -111,7 +125,7 @@ Query::buildTree(vespalib::stringref stack, const string &location, if (_query_tree) { SameElementModifier prefixSameElementSubIndexes; _query_tree->accept(prefixSameElementSubIndexes); - AddLocationNode(location, _query_tree, _location); + addLocationNode(location, _query_tree, _location); ResolveViewVisitor resolve_visitor(resolver, indexEnv); _query_tree->accept(resolve_visitor); return true; diff --git a/searchlib/src/vespa/searchlib/query/tree/intermediate.cpp b/searchlib/src/vespa/searchlib/query/tree/intermediate.cpp index f56da9c2cf9..3949b975f5f 100644 --- a/searchlib/src/vespa/searchlib/query/tree/intermediate.cpp +++ b/searchlib/src/vespa/searchlib/query/tree/intermediate.cpp @@ -9,10 +9,26 @@ Intermediate::~Intermediate() { } } -Intermediate &Intermediate::append(Node::UP child) +Intermediate & +Intermediate::append(Node::UP child) { _children.push_back(child.release()); return *this; } +Intermediate & +Intermediate::prepend(Node::UP child) +{ + _children.insert(_children.begin(), child.release()); + return *this; +} + +Node::UP +Intermediate::stealFirst() +{ + Node::UP first(_children.front()); + _children.erase(_children.begin()); + return first; +} + } diff --git a/searchlib/src/vespa/searchlib/query/tree/intermediate.h b/searchlib/src/vespa/searchlib/query/tree/intermediate.h index 052dc1db269..2f4323f8e87 100644 --- a/searchlib/src/vespa/searchlib/query/tree/intermediate.h +++ b/searchlib/src/vespa/searchlib/query/tree/intermediate.h @@ -20,7 +20,9 @@ class Intermediate : public Node const std::vector<Node *> &getChildren() const { return _children; } Intermediate &reserve(size_t sz) { _children.reserve(sz); return *this; } + Intermediate &prepend(Node::UP child); Intermediate &append(Node::UP child); + Node::UP stealFirst(); }; } diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp index 5cb51aa4fd0..0a11203c390 100644 --- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp @@ -208,7 +208,7 @@ AndBlueprint::inheritStrict(size_t i) const SearchIterator::UP AndBlueprint::createIntermediateSearch(const MultiSearch::Children &subSearches, - bool strict, search::fef::MatchData & md) const + bool strict, search::fef::MatchData & md) const { UnpackInfo unpackInfo(calculateUnpackInfo(md)); AndSearch * search = 0; |