diff options
author | Geir Storli <geirst@yahooinc.com> | 2022-10-31 12:40:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-31 12:40:23 +0100 |
commit | b89b4c8bf2b892199baa18b7a78a24bef747df9c (patch) | |
tree | 4a10a73537999b09f1ae97e806e4189184401658 | |
parent | ffd568166c37540d7b5f31e77522f2c35075414c (diff) | |
parent | 852967e6ee61e8930e37f4df2c47b7375a29553c (diff) |
Merge pull request #24655 from vespa-engine/havarde/explicit-default-filter
explicit default filter
14 files changed, 63 insertions, 14 deletions
diff --git a/searchcore/src/tests/proton/matching/match_phase_limiter/match_phase_limiter_test.cpp b/searchcore/src/tests/proton/matching/match_phase_limiter/match_phase_limiter_test.cpp index b1275681dc1..dd2396e5f34 100644 --- a/searchcore/src/tests/proton/matching/match_phase_limiter/match_phase_limiter_test.cpp +++ b/searchcore/src/tests/proton/matching/match_phase_limiter/match_phase_limiter_test.cpp @@ -82,6 +82,9 @@ struct MockBlueprint : SimpleLeafBlueprint { } return std::make_unique<MockSearch>(spec, term, strict, tfmda, postings_fetched); } + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } void fetchPostings(const search::queryeval::ExecuteInfo &execInfo) override { postings_strict = execInfo; postings_fetched = true; diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp index 3c0b49da762..4b9c23ea5d3 100644 --- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp @@ -45,7 +45,9 @@ public: { return std::make_unique<MySearch>("or", std::move(subSearches), &md, strict); } - + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } static MyOr& create() { return *(new MyOr()); } MyOr& add(Blueprint *n) { addChild(UP(n)); return *this; } MyOr& add(Blueprint &n) { addChild(UP(&n)); return *this; } @@ -140,6 +142,9 @@ struct MyTerm : SimpleLeafBlueprint { virtual SearchIterator::UP createLeafSearch(const search::fef::TermFieldMatchDataArray &, bool) const override { return SearchIterator::UP(); } + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } }; //----------------------------------------------------------------------------- diff --git a/searchlib/src/tests/queryeval/blueprint/mysearch.h b/searchlib/src/tests/queryeval/blueprint/mysearch.h index 346a1fb12be..23cfc8583cd 100644 --- a/searchlib/src/tests/queryeval/blueprint/mysearch.h +++ b/searchlib/src/tests/queryeval/blueprint/mysearch.h @@ -132,6 +132,10 @@ public: bool got_global_filter() const { return _got_global_filter; } // make public using LeafBlueprint::set_want_global_filter; + + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } }; //----------------------------------------------------------------------------- diff --git a/searchlib/src/tests/queryeval/filter_search/filter_search_test.cpp b/searchlib/src/tests/queryeval/filter_search/filter_search_test.cpp index 8748124d6f0..83dc574c16c 100644 --- a/searchlib/src/tests/queryeval/filter_search/filter_search_test.cpp +++ b/searchlib/src/tests/queryeval/filter_search/filter_search_test.cpp @@ -54,6 +54,9 @@ struct DefaultBlueprint : Blueprint { void fetchPostings(const ExecuteInfo &) override { abort(); } void freeze() override { abort(); } SearchIteratorUP createSearch(MatchData &, bool) const override { abort(); } + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } }; // proxy class used to make various decorators for leaf blueprints @@ -412,8 +415,13 @@ TEST(FilterSearchTest, custom_leaf) { verify(*hits({5,10,20}), Expect::hits({5,10,20})); } -TEST(FilterSearchTest, default_blueprint) { +TEST(FilterSearchTest, default_filter) { verify(DefaultBlueprint(), Expect::full(), Expect::empty()); + auto adapter = [](const auto &ignore_children, bool strict, Constraint constraint) { + (void) ignore_children; + return Blueprint::create_default_filter(strict, constraint); + }; + verify(Combine(adapter, Children()), Expect::full(), Expect::empty()); } TEST(FilterSearchTest, simple_or) { diff --git a/searchlib/src/tests/queryeval/queryeval.cpp b/searchlib/src/tests/queryeval/queryeval.cpp index 2f03525644a..5d34e491708 100644 --- a/searchlib/src/tests/queryeval/queryeval.cpp +++ b/searchlib/src/tests/queryeval/queryeval.cpp @@ -360,6 +360,9 @@ public: (void) tfmda; return _sc->createIterator(&_tfmd, strict); } + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } private: search::SingleBoolAttribute _a; std::unique_ptr<search::attribute::SearchContext> _sc; diff --git a/searchlib/src/tests/queryeval/simple_phrase/simple_phrase_test.cpp b/searchlib/src/tests/queryeval/simple_phrase/simple_phrase_test.cpp index 13202a062c7..0e238a1b878 100644 --- a/searchlib/src/tests/queryeval/simple_phrase/simple_phrase_test.cpp +++ b/searchlib/src/tests/queryeval/simple_phrase/simple_phrase_test.cpp @@ -38,6 +38,9 @@ struct MyTerm : public search::queryeval::SimpleLeafBlueprint { SearchIterator::UP createLeafSearch(const search::fef::TermFieldMatchDataArray &, bool) const override { return SearchIterator::UP(); } + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } }; class Test : public vespalib::TestApp { diff --git a/searchlib/src/tests/queryeval/termwise_eval/termwise_eval_test.cpp b/searchlib/src/tests/queryeval/termwise_eval/termwise_eval_test.cpp index 322a36eb90a..bad7146479c 100644 --- a/searchlib/src/tests/queryeval/termwise_eval/termwise_eval_test.cpp +++ b/searchlib/src/tests/queryeval/termwise_eval/termwise_eval_test.cpp @@ -88,6 +88,9 @@ struct MyBlueprint : SimpleLeafBlueprint { { return std::make_unique<MyTerm>(hits, strict); } + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } }; MyBlueprint::~MyBlueprint() = default; diff --git a/searchlib/src/tests/queryeval/weighted_set_term/weighted_set_term_test.cpp b/searchlib/src/tests/queryeval/weighted_set_term/weighted_set_term_test.cpp index ba75d7b0da0..8f4381c48f9 100644 --- a/searchlib/src/tests/queryeval/weighted_set_term/weighted_set_term_test.cpp +++ b/searchlib/src/tests/queryeval/weighted_set_term/weighted_set_term_test.cpp @@ -287,6 +287,9 @@ struct VerifyMatchData { ++vmd.child_cnt; return std::make_unique<EmptySearch>(); } + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } }; size_t child_cnt = 0; TermFieldMatchData *child_tfmd = nullptr; diff --git a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp index 3ef675c6b98..179296ff0f9 100644 --- a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp @@ -266,6 +266,9 @@ public: return std::make_unique<LocationPreFilterIterator<false>>(std::move(children)); } } + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } void fetchPostings(const queryeval::ExecuteInfo &execInfo) override { for (auto & search : _rangeSearches) { @@ -319,6 +322,9 @@ public: } return FastS_AllocLocationIterator(_attribute.getNumDocs(), strict, _location); } + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } }; //----------------------------------------------------------------------------- diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp index 8adfcd95c2f..9c9df6b82fe 100644 --- a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp @@ -144,17 +144,6 @@ Blueprint::root() const return *bp; } -SearchIterator::UP -Blueprint::createFilterSearch(bool /*strict*/, FilterConstraint constraint) const -{ - if (constraint == FilterConstraint::UPPER_BOUND) { - return std::make_unique<FullSearch>(); - } else { - LOG_ASSERT(constraint == FilterConstraint::LOWER_BOUND); - return std::make_unique<EmptySearch>(); - } -} - std::unique_ptr<MatchingElementsSearch> Blueprint::create_matching_elements_search(const MatchingElementsFields &fields) const { @@ -291,6 +280,17 @@ Blueprint::create_first_child_filter(const Children &children, bool strict, Blue return children[0]->createFilterSearch(strict, constraint); } +std::unique_ptr<SearchIterator> +Blueprint::create_default_filter(bool, FilterConstraint constraint) +{ + if (constraint == FilterConstraint::UPPER_BOUND) { + return std::make_unique<FullSearch>(); + } else { + REQUIRE_EQ(constraint, FilterConstraint::LOWER_BOUND); + return std::make_unique<EmptySearch>(); + } +} + vespalib::string Blueprint::asString() const { diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.h b/searchlib/src/vespa/searchlib/queryeval/blueprint.h index 199cf45792d..e7e4741fa3e 100644 --- a/searchlib/src/vespa/searchlib/queryeval/blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.h @@ -225,13 +225,14 @@ public: bool frozen() const { return _frozen; } virtual SearchIteratorUP createSearch(fef::MatchData &md, bool strict) const = 0; - virtual SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const; + virtual SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const = 0; static SearchIteratorUP create_and_filter(const Children &children, bool strict, FilterConstraint constraint); static SearchIteratorUP create_or_filter(const Children &children, bool strict, FilterConstraint constraint); static SearchIteratorUP create_atmost_and_filter(const Children &children, bool strict, FilterConstraint constraint); static SearchIteratorUP create_atmost_or_filter(const Children &children, bool strict, FilterConstraint constraint); static SearchIteratorUP create_andnot_filter(const Children &children, bool strict, FilterConstraint constraint); static SearchIteratorUP create_first_child_filter(const Children &children, bool strict, FilterConstraint constraint); + static SearchIteratorUP create_default_filter(bool strict, FilterConstraint constraint); // for debug dumping vespalib::string asString() const; diff --git a/searchlib/src/vespa/searchlib/queryeval/leaf_blueprints.h b/searchlib/src/vespa/searchlib/queryeval/leaf_blueprints.h index 2f97d89e322..7b28df84ad1 100644 --- a/searchlib/src/vespa/searchlib/queryeval/leaf_blueprints.h +++ b/searchlib/src/vespa/searchlib/queryeval/leaf_blueprints.h @@ -86,6 +86,10 @@ public: const attribute::ISearchContext *get_attribute_search_context() const override { return _ctx.get(); } + + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } }; //----------------------------------------------------------------------------- diff --git a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.h index 3dd03291b97..3defb34cffd 100644 --- a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.h @@ -67,6 +67,9 @@ public: std::unique_ptr<SearchIterator> createLeafSearch(const search::fef::TermFieldMatchDataArray& tfmda, bool strict) const override; + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } void visitMembers(vespalib::ObjectVisitor& visitor) const override; bool always_needs_unpack() const override; }; diff --git a/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h index fc466806e9c..e5daee87fc6 100644 --- a/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h @@ -51,6 +51,9 @@ public: SearchIterator::UP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool strict) const override; + SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override { + return create_default_filter(strict, constraint); + } // Exposed for testing const BitVectorCache::CountVector & getKV() const { return _kV; } |