diff options
author | Arne H Juul <arnej27959@users.noreply.github.com> | 2020-06-02 11:31:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-02 11:31:02 +0200 |
commit | 8a3850679c830c2b56e1b0d6f8c387dfa9b2aa62 (patch) | |
tree | 690a874a51be9338f93e55a3bc476f5337f47af6 /searchlib | |
parent | aa7d2d50ae977f1e3bac4f12a09d64106d0b2742 (diff) | |
parent | cceb654d43601f670c9b9a47fa93f6b23079e57b (diff) |
Merge pull request #13421 from vespa-engine/arnej/more-intermediate-filters
Arnej/more intermediate filters
Diffstat (limited to 'searchlib')
6 files changed, 102 insertions, 14 deletions
diff --git a/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp index cf378c95487..8a798e6cce3 100644 --- a/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp @@ -75,6 +75,17 @@ EquivBlueprint::createLeafSearch(const fef::TermFieldMatchDataArray &outputs, bo return SearchIterator::UP(EquivSearch::create(children, std::move(md), childMatch, outputs, strict)); } +SearchIterator::UP +EquivBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const +{ + MultiSearch::Children children(_terms.size()); + for (size_t i = 0; i < _terms.size(); ++i) { + children[i] = _terms[i]->createFilterSearch(strict, constraint).release(); + } + UnpackInfo unpack_info; + return SearchIterator::UP(OrSearch::create(children, strict, unpack_info)); +} + void EquivBlueprint::visitMembers(vespalib::ObjectVisitor &visitor) const { diff --git a/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.h index 59ed5ad5d3d..d1df1e0aada 100644 --- a/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.h @@ -25,6 +25,7 @@ public: EquivBlueprint& addTerm(Blueprint::UP term, double exactness); SearchIteratorUP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool strict) const override; + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override; void visitMembers(vespalib::ObjectVisitor &visitor) const override; void fetchPostings(const ExecuteInfo &execInfo) override; diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp index 624b9a1a368..14e53d6d868 100644 --- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp @@ -82,6 +82,23 @@ need_normal_features_for_children(const IntermediateBlueprint &blueprint, fef::M } } +/** utility for operators that degrade to AND when creating filter */ +SearchIterator::UP createAndFilter(const IntermediateBlueprint &self, + bool strict, Blueprint::FilterConstraint constraint) +{ + MultiSearch::Children sub_searches; + sub_searches.reserve(self.childCnt()); + for (size_t i = 0; i < self.childCnt(); ++i) { + bool child_strict = strict && (i == 0); + auto search = self.getChild(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(self.getState().estimate().estHits); + return SearchIterator::UP(search); +} + } // namespace search::queryeval::<unnamed> //----------------------------------------------------------------------------- @@ -273,17 +290,7 @@ AndBlueprint::createIntermediateSearch(const MultiSearch::Children &sub_searches SearchIterator::UP AndBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const { - 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.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); + return createAndFilter(*this, strict, constraint); } double @@ -477,6 +484,16 @@ 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 +{ + if (constraint == Blueprint::FilterConstraint::UPPER_BOUND) { + return createAndFilter(*this, strict, constraint); + } else { + return std::make_unique<EmptySearch>(); + } +} + //----------------------------------------------------------------------------- Blueprint::HitEstimate @@ -527,6 +544,16 @@ ONearBlueprint::createIntermediateSearch(const MultiSearch::Children &sub_search return SearchIterator::UP(new ONearSearch(sub_searches, tfmda, _window, strict)); } +SearchIterator::UP +ONearBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const +{ + if (constraint == Blueprint::FilterConstraint::UPPER_BOUND) { + return createAndFilter(*this, strict, constraint); + } else { + return std::make_unique<EmptySearch>(); + } +} + //----------------------------------------------------------------------------- Blueprint::HitEstimate @@ -602,6 +629,13 @@ RankBlueprint::createIntermediateSearch(const MultiSearch::Children &sub_searche } } +SearchIterator::UP +RankBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const +{ + assert(childCnt() > 0); + return getChild(0).createFilterSearch(strict, constraint); +} + //----------------------------------------------------------------------------- SourceBlenderBlueprint::SourceBlenderBlueprint(const ISourceSelector &selector) @@ -668,6 +702,24 @@ SourceBlenderBlueprint::createIntermediateSearch(const MultiSearch::Children &su children, strict)); } +SearchIterator::UP +SourceBlenderBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const +{ + if (constraint == 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.push_back(search.release()); + } + UnpackInfo unpack_info; + return SearchIterator::UP(OrSearch::create(sub_searches, strict, unpack_info)); + } else { + return std::make_unique<EmptySearch>(); + } +} + bool SourceBlenderBlueprint::isCompatibleWith(const SourceBlenderBlueprint &other) const { diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h index ecad9431a81..65dced2ea6b 100644 --- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h +++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h @@ -32,6 +32,7 @@ private: //----------------------------------------------------------------------------- +/** normal AND operator */ class AndBlueprint : public IntermediateBlueprint { public: @@ -56,6 +57,7 @@ public: //----------------------------------------------------------------------------- +/** normal OR operator */ class OrBlueprint : public IntermediateBlueprint { public: @@ -118,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 IntermediateBlueprint +class ONearBlueprint : public IntermediateBlueprint { private: uint32_t _window; @@ -139,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) {} }; @@ -157,6 +161,8 @@ public: SearchIterator::UP createIntermediateSearch(const MultiSearch::Children &subSearches, bool strict, fef::MatchData &md) const override; + SearchIterator::UP + createFilterSearch(bool strict, FilterConstraint constraint) const override; }; //----------------------------------------------------------------------------- @@ -181,6 +187,8 @@ public: SearchIterator::UP createIntermediateSearch(const MultiSearch::Children &subSearches, bool strict, fef::MatchData &md) const override; + SearchIterator::UP + createFilterSearch(bool strict, FilterConstraint constraint) const override; /** check if this blueprint has the same source selector as the other */ bool isCompatibleWith(const SourceBlenderBlueprint &other) const; diff --git a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp index c52cf6ddae1..fc29c7ef45d 100644 --- a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp @@ -2,6 +2,7 @@ #include "simple_phrase_blueprint.h" #include "simple_phrase_search.h" +#include "emptysearch.h" #include "field_spec.hpp" #include <vespa/searchlib/fef/termfieldmatchdata.h> #include <vespa/vespalib/objects/visit.hpp> @@ -83,6 +84,21 @@ SimplePhraseBlueprint::createLeafSearch(const fef::TermFieldMatchDataArray &tfmd return phrase; } +SearchIterator::UP +SimplePhraseBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const +{ + if (constraint == FilterConstraint::UPPER_BOUND) { + MultiSearch::Children children(_terms.size()); + for (size_t i = 0; i < _terms.size(); ++i) { + bool child_strict = strict && (i == 0); + children[i] = _terms[i]->createFilterSearch(child_strict, constraint).release(); + } + UnpackInfo unpack_info; + return SearchIterator::UP(AndSearch::create(children, strict, unpack_info)); + } else { + return std::make_unique<EmptySearch>(); + } +} void SimplePhraseBlueprint::fetchPostings(const ExecuteInfo &execInfo) diff --git a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.h index 0fb1599d68f..b20866fdd1f 100644 --- a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.h @@ -33,8 +33,8 @@ public: // used by create visitor void addTerm(Blueprint::UP term); - SearchIteratorUP - createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool strict) const override; + SearchIteratorUP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool strict) const override; + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override; void visitMembers(vespalib::ObjectVisitor &visitor) const override; void fetchPostings(const ExecuteInfo &execInfo) override; }; |