diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-05-29 05:30:40 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-05-29 05:30:40 +0000 |
commit | d6a4cac8a10f1090f9de6e689bd1342e3bf1abfc (patch) | |
tree | 222c494b90c9511a582df0c49712a20961b48810 /searchlib/src | |
parent | 6366e23e0f46b4ddb0488e4541c46cfcc126a2e4 (diff) |
use helper method instead of inheritance
Diffstat (limited to 'searchlib/src')
-rw-r--r-- | searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp | 37 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h | 13 |
2 files changed, 33 insertions, 17 deletions
diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp index 31ee19d238c..6ec35b39f1b 100644 --- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp @@ -432,26 +432,35 @@ WeakAndBlueprint::createIntermediateSearch(const MultiSearch::Children &sub_sear //----------------------------------------------------------------------------- -SearchIterator::UP -FilterUpperAndBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const +namespace { + +/** shared implementation for operators that degrade to AND when creating filter for upper-bound case */ +SearchIterator::UP createAndFilterAsUpperBound(const IntermediateBlueprint &self, + bool strict, Blueprint::FilterConstraint constraint) { - if (constraint == FilterConstraint::UPPER_BOUND) { + std::vector<const Blueprint *> children; + children.reserve(self.childCnt()); + for (size_t i = 0; i < self.childCnt(); ++i) { + children.push_back(&self.getChild(i)); + } + if (constraint == Blueprint::FilterConstraint::UPPER_BOUND) { MultiSearch::Children sub_searches; - sub_searches.reserve(childCnt()); - for (size_t i = 0; i < childCnt(); ++i) { - bool child_strict = strict && inheritStrict(i); - auto search = getChild(i).createFilterSearch(child_strict, constraint); + sub_searches.reserve(children.size()); + for (size_t i = 0; i < children.size(); ++i) { + bool child_strict = strict && (i == 0); + auto search = children[i]->createFilterSearch(child_strict, constraint); sub_searches.push_back(search.release()); } UnpackInfo unpack_info; AndSearch * search = AndSearch::create(sub_searches, strict, unpack_info); - search->estimate(getState().estimate().estHits); return SearchIterator::UP(search); } else { return std::make_unique<EmptySearch>(); } } +} // namespace <unnamed> + //----------------------------------------------------------------------------- Blueprint::HitEstimate @@ -499,6 +508,12 @@ NearBlueprint::createIntermediateSearch(const MultiSearch::Children &sub_searche return SearchIterator::UP(new NearSearch(sub_searches, tfmda, _window, strict)); } +SearchIterator::UP +NearBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const +{ + return createAndFilterAsUpperBound(*this, strict, constraint); +} + //----------------------------------------------------------------------------- Blueprint::HitEstimate @@ -534,6 +549,12 @@ ONearBlueprint::createSearch(fef::MatchData &md, bool strict) const } SearchIterator::UP +ONearBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const +{ + return createAndFilterAsUpperBound(*this, strict, constraint); +} + +SearchIterator::UP ONearBlueprint::createIntermediateSearch(const MultiSearch::Children &sub_searches, bool strict, search::fef::MatchData &md) const { diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h index b404ca9c6c1..65dced2ea6b 100644 --- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h +++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h @@ -105,14 +105,7 @@ public: //----------------------------------------------------------------------------- -/** shared implementation for operators that degrade to AND when creating filter for upper-bound case */ -class FilterUpperAndBlueprint : public IntermediateBlueprint -{ -public: - SearchIterator::UP createFilterSearch(bool strict, FilterConstraint constraint) const override; -}; - -class NearBlueprint : public FilterUpperAndBlueprint +class NearBlueprint : public IntermediateBlueprint { private: uint32_t _window; @@ -127,13 +120,14 @@ public: SearchIterator::UP createIntermediateSearch(const MultiSearch::Children &subSearches, bool strict, fef::MatchData &md) const override; + SearchIterator::UP createFilterSearch(bool strict, FilterConstraint constraint) const override; NearBlueprint(uint32_t window) : _window(window) {} }; //----------------------------------------------------------------------------- -class ONearBlueprint : public FilterUpperAndBlueprint +class ONearBlueprint : public IntermediateBlueprint { private: uint32_t _window; @@ -148,6 +142,7 @@ public: SearchIterator::UP createIntermediateSearch(const MultiSearch::Children &subSearches, bool strict, fef::MatchData &md) const override; + SearchIterator::UP createFilterSearch(bool strict, FilterConstraint constraint) const override; ONearBlueprint(uint32_t window) : _window(window) {} }; |