diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-04-01 21:22:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-01 21:22:14 +0200 |
commit | cf56cbe6f8671a532fca938c9f2fead443a803c9 (patch) | |
tree | 8b547c271e495d162b7c9f430989a34dbb1e1a37 | |
parent | eb58fd37f2f351efa8d8d53e21e3ca3d8e66f4fd (diff) | |
parent | cb7cfb894eed31098869a43c734317af378e5f18 (diff) |
Merge pull request #21947 from vespa-engine/toregge/add-numeric-search-context
Add NumericSearchContext.
16 files changed, 125 insertions, 101 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt index af8df69f5e8..ba4ec2b3f12 100644 --- a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt @@ -83,6 +83,7 @@ vespa_add_library(searchlib_attribute OBJECT numericbase.cpp numeric_matcher.cpp numeric_range_matcher.cpp + numeric_search_context.cpp posting_list_merger.cpp postingchange.cpp postinglistattribute.cpp diff --git a/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.h b/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.h index 683621eb726..44e7fe9491f 100644 --- a/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.h +++ b/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.h @@ -2,7 +2,7 @@ #pragma once -#include "search_context.h" +#include "numeric_search_context.h" #include "enumstore.h" #include "multi_value_mapping.h" @@ -13,10 +13,11 @@ namespace search::attribute { * a query term on a multi value enumerated attribute vector. * This class should be considered to be an abstract class. */ -template <typename T, typename Matcher, typename M> -class MultiEnumSearchContext : public Matcher, public SearchContext +template <typename T, typename BaseSC, typename M> +class MultiEnumSearchContext : public BaseSC { protected: + using DocId = ISearchContext::DocId; const MultiValueMapping<M>& _mv_mapping; const EnumStoreT<T>& _enum_store; @@ -28,9 +29,7 @@ protected: return find(docId, elemId); } - bool valid() const override { return this->isValid(); } - - MultiEnumSearchContext(Matcher&& matcher, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping, const EnumStoreT<T>& enum_store); + MultiEnumSearchContext(typename BaseSC::MatcherType&& matcher, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping, const EnumStoreT<T>& enum_store); public: int32_t find(DocId doc, int32_t elemId, int32_t & weight) const { diff --git a/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.hpp b/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.hpp index b0069af3c89..cc1640a08b9 100644 --- a/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multi_enum_search_context.hpp @@ -8,18 +8,17 @@ namespace search::attribute { -template <typename T, typename Matcher, typename M> -MultiEnumSearchContext<T, Matcher, M>::MultiEnumSearchContext(Matcher&& matcher, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping, const EnumStoreT<T>& enum_store) - : Matcher(std::move(matcher)), - SearchContext(toBeSearched), +template <typename T, typename BaseSC, typename M> +MultiEnumSearchContext<T, BaseSC, M>::MultiEnumSearchContext(typename BaseSC::MatcherType&& matcher, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping, const EnumStoreT<T>& enum_store) + : BaseSC(toBeSearched, std::move(matcher)), _mv_mapping(mv_mapping), _enum_store(enum_store) { } -template <typename T, typename Matcher, typename M> +template <typename T, typename BaseSC, typename M> std::unique_ptr<queryeval::SearchIterator> -MultiEnumSearchContext<T, Matcher, M>::createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) +MultiEnumSearchContext<T, BaseSC, M>::createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) { if (!this->valid()) { return std::make_unique<queryeval::EmptySearch>(); diff --git a/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.h b/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.h index d0153a05f15..b70ce2459ee 100644 --- a/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.h +++ b/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.h @@ -4,6 +4,7 @@ #include "multi_enum_search_context.h" #include "numeric_range_matcher.h" +#include "numeric_search_context.h" namespace search::attribute { @@ -12,12 +13,10 @@ namespace search::attribute { * a query term on a multi value numeric enumerated attribute vector. */ template <typename T, typename M> -class MultiNumericEnumSearchContext : public MultiEnumSearchContext<T, NumericRangeMatcher<T>, M> +class MultiNumericEnumSearchContext : public MultiEnumSearchContext<T, NumericSearchContext<NumericRangeMatcher<T>>, M> { public: MultiNumericEnumSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping, const EnumStoreT<T>& enum_store); - - Int64Range getAsIntegerTerm() const override; }; } diff --git a/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.hpp b/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.hpp index 7b8e193379c..9780aa7a507 100644 --- a/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multi_numeric_enum_search_context.hpp @@ -9,15 +9,8 @@ namespace search::attribute { template <typename T, typename M> MultiNumericEnumSearchContext<T, M>::MultiNumericEnumSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping, const EnumStoreT<T>& enum_store) - : MultiEnumSearchContext<T, NumericRangeMatcher<T>, M>(NumericRangeMatcher<T>(*qTerm), toBeSearched, mv_mapping, enum_store) + : MultiEnumSearchContext<T, NumericSearchContext<NumericRangeMatcher<T>>, M>(NumericRangeMatcher<T>(*qTerm), toBeSearched, mv_mapping, enum_store) { } -template <typename T, typename M> -Int64Range -MultiNumericEnumSearchContext<T, M>::getAsIntegerTerm() const -{ - return this->getRange(); -} - } diff --git a/searchlib/src/vespa/searchlib/attribute/multi_numeric_search_context.h b/searchlib/src/vespa/searchlib/attribute/multi_numeric_search_context.h index 2a95c4df5a8..7d43e195d00 100644 --- a/searchlib/src/vespa/searchlib/attribute/multi_numeric_search_context.h +++ b/searchlib/src/vespa/searchlib/attribute/multi_numeric_search_context.h @@ -2,7 +2,7 @@ #pragma once -#include "search_context.h" +#include "numeric_search_context.h" #include "multi_value_mapping.h" #include "numeric_range_matcher.h" @@ -13,9 +13,10 @@ namespace search::attribute { * a query term on a multi value numeric attribute vector. */ template <typename T, typename M> -class MultiNumericSearchContext : public NumericRangeMatcher<T>, public SearchContext +class MultiNumericSearchContext : public NumericSearchContext<NumericRangeMatcher<T>> { private: + using DocId = ISearchContext::DocId; const MultiValueMapping<M>& _mv_mapping; int32_t onFind(DocId docId, int32_t elemId, int32_t& weight) const override final { @@ -26,9 +27,6 @@ private: return find(docId, elemId); } -protected: - bool valid() const override; - public: MultiNumericSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping); int32_t find(DocId doc, int32_t elemId, int32_t & weight) const { @@ -53,8 +51,6 @@ public: return -1; } - Int64Range getAsIntegerTerm() const override; - std::unique_ptr<queryeval::SearchIterator> createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) override; }; diff --git a/searchlib/src/vespa/searchlib/attribute/multi_numeric_search_context.hpp b/searchlib/src/vespa/searchlib/attribute/multi_numeric_search_context.hpp index 01e7f359255..8398c921ec6 100644 --- a/searchlib/src/vespa/searchlib/attribute/multi_numeric_search_context.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multi_numeric_search_context.hpp @@ -10,35 +10,20 @@ namespace search::attribute { template <typename T, typename M> -bool -MultiNumericSearchContext<T, M>::valid() const -{ - return this->isValid(); -} - -template <typename T, typename M> MultiNumericSearchContext<T, M>::MultiNumericSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const MultiValueMapping<M>& mv_mapping) - : attribute::NumericRangeMatcher<T>(*qTerm), - attribute::SearchContext(toBeSearched), + : NumericSearchContext<NumericRangeMatcher<T>>(toBeSearched, *qTerm, false), _mv_mapping(mv_mapping) { } template <typename T, typename M> -Int64Range -MultiNumericSearchContext<T, M>::getAsIntegerTerm() const -{ - return this->getRange(); -} - -template <typename T, typename M> std::unique_ptr<queryeval::SearchIterator> MultiNumericSearchContext<T, M>::createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) { - if (!valid()) { + if (!this->valid()) { return std::make_unique<queryeval::EmptySearch>(); } - if (getIsFilter()) { + if (this->getIsFilter()) { return strict ? std::make_unique<FilterAttributeIteratorStrict<MultiNumericSearchContext<T, M>>>(*this, matchData) : std::make_unique<FilterAttributeIteratorT<MultiNumericSearchContext<T, M>>>(*this, matchData); diff --git a/searchlib/src/vespa/searchlib/attribute/numeric_search_context.cpp b/searchlib/src/vespa/searchlib/attribute/numeric_search_context.cpp new file mode 100644 index 00000000000..1ab7e0e2701 --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/numeric_search_context.cpp @@ -0,0 +1,23 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "numeric_search_context.hpp" +#include "numeric_matcher.h" +#include "numeric_range_matcher.h" + +namespace search::attribute { + +template class NumericSearchContext<NumericMatcher<int8_t>>; +template class NumericSearchContext<NumericMatcher<int16_t>>; +template class NumericSearchContext<NumericMatcher<int32_t>>; +template class NumericSearchContext<NumericMatcher<int64_t>>; +template class NumericSearchContext<NumericMatcher<float>>; +template class NumericSearchContext<NumericMatcher<double>>; + +template class NumericSearchContext<NumericRangeMatcher<int8_t>>; +template class NumericSearchContext<NumericRangeMatcher<int16_t>>; +template class NumericSearchContext<NumericRangeMatcher<int32_t>>; +template class NumericSearchContext<NumericRangeMatcher<int64_t>>; +template class NumericSearchContext<NumericRangeMatcher<float>>; +template class NumericSearchContext<NumericRangeMatcher<double>>; + +} diff --git a/searchlib/src/vespa/searchlib/attribute/numeric_search_context.h b/searchlib/src/vespa/searchlib/attribute/numeric_search_context.h new file mode 100644 index 00000000000..9c17af3677b --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/numeric_search_context.h @@ -0,0 +1,25 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "search_context.h" + +namespace search::attribute { + +/* + * NumericSearchContext is an abstract base class for search contexts + * handling a query term on a numeric attribute vector. + */ +template <typename Matcher> +class NumericSearchContext : public SearchContext, public Matcher +{ +protected: + using MatcherType = Matcher; +public: + NumericSearchContext(const AttributeVector& to_be_searched, const QueryTermSimple& query_term, bool avoid_undefined_range); + NumericSearchContext(const AttributeVector& to_be_searched, Matcher&& matcher); + Int64Range getAsIntegerTerm() const override; + bool valid() const override; +}; + +} diff --git a/searchlib/src/vespa/searchlib/attribute/numeric_search_context.hpp b/searchlib/src/vespa/searchlib/attribute/numeric_search_context.hpp new file mode 100644 index 00000000000..f9435578303 --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/numeric_search_context.hpp @@ -0,0 +1,37 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "numeric_search_context.h" + +namespace search::attribute { + +template <typename Matcher> +NumericSearchContext<Matcher>::NumericSearchContext(const AttributeVector& to_be_searched, const QueryTermSimple& query_term, bool avoid_undefined_range) + : SearchContext(to_be_searched), + Matcher(query_term, avoid_undefined_range) +{ +} + +template <typename Matcher> +NumericSearchContext<Matcher>::NumericSearchContext(const AttributeVector& to_be_searched, Matcher &&matcher) + : SearchContext(to_be_searched), + Matcher(std::move(matcher)) +{ +} + +template <typename Matcher> +Int64Range +NumericSearchContext<Matcher>::getAsIntegerTerm() const +{ + return Matcher::getRange(); +} + +template <typename Matcher> +bool +NumericSearchContext<Matcher>::valid() const +{ + return Matcher::isValid(); +} + +} diff --git a/searchlib/src/vespa/searchlib/attribute/single_enum_search_context.h b/searchlib/src/vespa/searchlib/attribute/single_enum_search_context.h index 69a19666fa1..f0e6908fc14 100644 --- a/searchlib/src/vespa/searchlib/attribute/single_enum_search_context.h +++ b/searchlib/src/vespa/searchlib/attribute/single_enum_search_context.h @@ -13,10 +13,11 @@ namespace search::attribute { * a query term on a single value enumerated attribute vector. * This class should be considered to be an abstract class. */ -template <typename T, typename Matcher> -class SingleEnumSearchContext : public Matcher, public SearchContext +template <typename T, typename BaseSC> +class SingleEnumSearchContext : public BaseSC { protected: + using DocId = ISearchContext::DocId; const vespalib::datastore::AtomicEntryRef* _enum_indices; const EnumStoreT<T>& _enum_store; @@ -27,10 +28,9 @@ protected: int32_t onFind(DocId docId, int32_t elemId) const override final { return find(docId, elemId); } - bool valid() const override; public: - SingleEnumSearchContext(Matcher&& matcher, const AttributeVector& toBeSearched, const vespalib::datastore::AtomicEntryRef* enum_indices, const EnumStoreT<T>& enum_store); + SingleEnumSearchContext(typename BaseSC::MatcherType&& matcher, const AttributeVector& toBeSearched, const vespalib::datastore::AtomicEntryRef* enum_indices, const EnumStoreT<T>& enum_store); int32_t find(DocId docId, int32_t elemId, int32_t & weight) const { if ( elemId != 0) return -1; diff --git a/searchlib/src/vespa/searchlib/attribute/single_enum_search_context.hpp b/searchlib/src/vespa/searchlib/attribute/single_enum_search_context.hpp index a79572e1fff..a415c301f9c 100644 --- a/searchlib/src/vespa/searchlib/attribute/single_enum_search_context.hpp +++ b/searchlib/src/vespa/searchlib/attribute/single_enum_search_context.hpp @@ -8,30 +8,22 @@ namespace search::attribute { -template <typename T, typename Matcher> -SingleEnumSearchContext<T, Matcher>::SingleEnumSearchContext(Matcher&& matcher, const AttributeVector& toBeSearched, const vespalib::datastore::AtomicEntryRef* enum_indices, const EnumStoreT<T>& enum_store) - : Matcher(std::move(matcher)), - SearchContext(toBeSearched), +template <typename T, typename BaseSC> +SingleEnumSearchContext<T, BaseSC>::SingleEnumSearchContext(typename BaseSC::MatcherType&& matcher, const AttributeVector& toBeSearched, const vespalib::datastore::AtomicEntryRef* enum_indices, const EnumStoreT<T>& enum_store) + : BaseSC(toBeSearched, std::move(matcher)), _enum_indices(enum_indices), _enum_store(enum_store) { } -template <typename T, typename Matcher> -bool -SingleEnumSearchContext<T, Matcher>::valid() const -{ - return this->isValid(); -} - -template <typename T, typename Matcher> +template <typename T, typename BaseSC> std::unique_ptr<queryeval::SearchIterator> -SingleEnumSearchContext<T, Matcher>::createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) +SingleEnumSearchContext<T, BaseSC>::createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) { - if (!valid()) { + if (!this->valid()) { return std::make_unique<queryeval::EmptySearch>(); } - if (getIsFilter()) { + if (this->getIsFilter()) { return strict ? std::make_unique<FilterAttributeIteratorStrict<SingleEnumSearchContext>>(*this, matchData) : std::make_unique<FilterAttributeIteratorT<SingleEnumSearchContext>>(*this, matchData); diff --git a/searchlib/src/vespa/searchlib/attribute/single_numeric_enum_search_context.h b/searchlib/src/vespa/searchlib/attribute/single_numeric_enum_search_context.h index deabb0917f9..86283f59283 100644 --- a/searchlib/src/vespa/searchlib/attribute/single_numeric_enum_search_context.h +++ b/searchlib/src/vespa/searchlib/attribute/single_numeric_enum_search_context.h @@ -4,6 +4,7 @@ #include "single_enum_search_context.h" #include "numeric_range_matcher.h" +#include "numeric_search_context.h" namespace search::attribute { @@ -12,12 +13,10 @@ namespace search::attribute { * a query term on a single value numeric enumerated attribute vector. */ template <typename T> -class SingleNumericEnumSearchContext : public SingleEnumSearchContext<T, NumericRangeMatcher<T>> +class SingleNumericEnumSearchContext : public SingleEnumSearchContext<T, NumericSearchContext<NumericRangeMatcher<T>>> { public: SingleNumericEnumSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const vespalib::datastore::AtomicEntryRef* enum_indices, const EnumStoreT<T>& enum_store); - - Int64Range getAsIntegerTerm() const override; }; } diff --git a/searchlib/src/vespa/searchlib/attribute/single_numeric_enum_search_context.hpp b/searchlib/src/vespa/searchlib/attribute/single_numeric_enum_search_context.hpp index 6997b094f1e..f4e049cb6f1 100644 --- a/searchlib/src/vespa/searchlib/attribute/single_numeric_enum_search_context.hpp +++ b/searchlib/src/vespa/searchlib/attribute/single_numeric_enum_search_context.hpp @@ -9,15 +9,8 @@ namespace search::attribute { template <typename T> SingleNumericEnumSearchContext<T>::SingleNumericEnumSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const vespalib::datastore::AtomicEntryRef* enum_indices, const EnumStoreT<T>& enum_store) - : SingleEnumSearchContext<T, NumericRangeMatcher<T>>(NumericRangeMatcher<T>(*qTerm, true), toBeSearched, enum_indices, enum_store) + : SingleEnumSearchContext<T, NumericSearchContext<NumericRangeMatcher<T>>>(NumericRangeMatcher<T>(*qTerm, true), toBeSearched, enum_indices, enum_store) { } -template <typename T> -Int64Range -SingleNumericEnumSearchContext<T>::getAsIntegerTerm() const -{ - return this->getRange(); -} - } diff --git a/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.h b/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.h index b68be69530f..5f6925f7f4d 100644 --- a/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.h +++ b/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.h @@ -2,7 +2,7 @@ #pragma once -#include "search_context.h" +#include "numeric_search_context.h" #include <vespa/vespalib/util/atomic.h> namespace search::attribute { @@ -12,9 +12,10 @@ namespace search::attribute { * a query term on a single value numeric attribute vector. */ template <typename T, typename M> -class SingleNumericSearchContext final : public M, public SearchContext +class SingleNumericSearchContext final : public NumericSearchContext<M> { private: + using DocId = ISearchContext::DocId; const T* _data; int32_t onFind(DocId docId, int32_t elemId, int32_t& weight) const override { @@ -25,8 +26,6 @@ private: return find(docId, elemId); } - bool valid() const override; - public: SingleNumericSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const T* data); int32_t find(DocId docId, int32_t elemId, int32_t& weight) const { @@ -42,8 +41,6 @@ public: return this->match(v) ? 0 : -1; } - Int64Range getAsIntegerTerm() const override; - std::unique_ptr<queryeval::SearchIterator> createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) override; }; diff --git a/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.hpp b/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.hpp index 7459ce53f6b..75d3da9de7f 100644 --- a/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.hpp +++ b/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.hpp @@ -9,34 +9,20 @@ namespace search::attribute { template <typename T, typename M> -bool -SingleNumericSearchContext<T, M>::valid() const -{ - return M::isValid(); -} - -template <typename T, typename M> SingleNumericSearchContext<T, M>::SingleNumericSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, const T* data) - : M(*qTerm, true), - attribute::SearchContext(toBeSearched), + : NumericSearchContext<M>(toBeSearched, *qTerm, true), _data(data) { } template <typename T, typename M> -Int64Range -SingleNumericSearchContext<T, M>::getAsIntegerTerm() const { - return M::getRange(); -} - -template <typename T, typename M> std::unique_ptr<queryeval::SearchIterator> SingleNumericSearchContext<T, M>::createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) { - if (!valid()) { + if (!this->valid()) { return std::make_unique<queryeval::EmptySearch>(); } - if (getIsFilter()) { + if (this->getIsFilter()) { return strict ? std::make_unique<FilterAttributeIteratorStrict<SingleNumericSearchContext<T, M>>>(*this, matchData) : std::make_unique<FilterAttributeIteratorT<SingleNumericSearchContext<T, M>>>(*this, matchData); |