diff options
author | Geir Storli <geirst@yahooinc.com> | 2022-03-30 16:15:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-30 16:15:28 +0200 |
commit | 46b37a52ab97cac956bf2608d21ca99549f44834 (patch) | |
tree | 606666cbaee1b2babbdd940e1d38b35847a1cd8d /searchlib | |
parent | 58200e0e03baf5fc712fd28313622bc8b4515dca (diff) | |
parent | 1a0507f12b26efc93e8939506f946029db34f0aa (diff) |
Merge pull request #21900 from vespa-engine/toregge/factor-out-single-numeric-search-context
Factor out SingleNumericSearchContext from SingleNumericAttribute.
Diffstat (limited to 'searchlib')
7 files changed, 130 insertions, 84 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt index 9c58954a399..4f4d892d887 100644 --- a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt @@ -103,6 +103,7 @@ vespa_add_library(searchlib_attribute OBJECT singlesmallnumericattribute.cpp singlestringattribute.cpp singlestringpostattribute.cpp + single_numeric_search_context.cpp sourceselector.cpp stringattribute.cpp stringbase.cpp diff --git a/searchlib/src/vespa/searchlib/attribute/attributeiterators.hpp b/searchlib/src/vespa/searchlib/attribute/attributeiterators.hpp index ebd028b0ee4..8cde2862645 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributeiterators.hpp +++ b/searchlib/src/vespa/searchlib/attribute/attributeiterators.hpp @@ -275,7 +275,7 @@ void AttributeIteratorT<SC>::visitMembers(vespalib::ObjectVisitor &visitor) const { AttributeIterator::visitMembers(visitor); - visit(visitor, "searchcontext.attribute", _concreteSearchCtx.attribute().getName()); + visit(visitor, "searchcontext.attribute", _concreteSearchCtx.attributeName()); visit(visitor, "searchcontext.queryterm", _concreteSearchCtx.queryTerm()); } @@ -284,7 +284,7 @@ void FilterAttributeIteratorT<SC>::visitMembers(vespalib::ObjectVisitor &visitor) const { FilterAttributeIterator::visitMembers(visitor); - visit(visitor, "searchcontext.attribute", _concreteSearchCtx.attribute().getName()); + visit(visitor, "searchcontext.attribute", _concreteSearchCtx.attributeName()); visit(visitor, "searchcontext.queryterm", _concreteSearchCtx.queryTerm()); } diff --git a/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.cpp b/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.cpp new file mode 100644 index 00000000000..01342557fea --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/single_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 "single_numeric_search_context.hpp" +#include "numeric_matcher.h" +#include "numeric_range_matcher.h" + +namespace search::attribute { + +template class SingleNumericSearchContext<int8_t, NumericMatcher<int8_t>>; +template class SingleNumericSearchContext<int16_t, NumericMatcher<int16_t>>; +template class SingleNumericSearchContext<int32_t, NumericMatcher<int32_t>>; +template class SingleNumericSearchContext<int64_t, NumericMatcher<int64_t>>; +template class SingleNumericSearchContext<float, NumericMatcher<float>>; +template class SingleNumericSearchContext<double, NumericMatcher<double>>; + +template class SingleNumericSearchContext<int8_t, NumericRangeMatcher<int8_t>>; +template class SingleNumericSearchContext<int16_t, NumericRangeMatcher<int16_t>>; +template class SingleNumericSearchContext<int32_t, NumericRangeMatcher<int32_t>>; +template class SingleNumericSearchContext<int64_t, NumericRangeMatcher<int64_t>>; +template class SingleNumericSearchContext<float, NumericRangeMatcher<float>>; +template class SingleNumericSearchContext<double, NumericRangeMatcher<double>>; + +} diff --git a/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.h b/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.h new file mode 100644 index 00000000000..b68be69530f --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.h @@ -0,0 +1,51 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "search_context.h" +#include <vespa/vespalib/util/atomic.h> + +namespace search::attribute { + +/* + * SingleNumericSearchContext handles the creation of search iterators for + * a query term on a single value numeric attribute vector. + */ +template <typename T, typename M> +class SingleNumericSearchContext final : public M, public SearchContext +{ +private: + const T* _data; + + int32_t onFind(DocId docId, int32_t elemId, int32_t& weight) const override { + return find(docId, elemId, weight); + } + + int32_t onFind(DocId docId, int elemId) const override { + 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 { + if ( elemId != 0) return -1; + const T v = vespalib::atomic::load_ref_relaxed(_data[docId]); + weight = 1; + return this->match(v) ? 0 : -1; + } + + int32_t find(DocId docId, int elemId) const { + if ( elemId != 0) return -1; + const T v = vespalib::atomic::load_ref_relaxed(_data[docId]); + 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 new file mode 100644 index 00000000000..7459ce53f6b --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.hpp @@ -0,0 +1,49 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "single_numeric_search_context.h" +#include "attributeiterators.hpp" +#include <vespa/searchlib/queryeval/emptysearch.h> + +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), + _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()) { + return std::make_unique<queryeval::EmptySearch>(); + } + if (getIsFilter()) { + return strict + ? std::make_unique<FilterAttributeIteratorStrict<SingleNumericSearchContext<T, M>>>(*this, matchData) + : std::make_unique<FilterAttributeIteratorT<SingleNumericSearchContext<T, M>>>(*this, matchData); + } + return strict + ? std::make_unique<AttributeIteratorStrict<SingleNumericSearchContext<T, M>>>(*this, matchData) + : std::make_unique<AttributeIteratorT<SingleNumericSearchContext<T, M>>>(*this, matchData); +} + +} diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.h b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.h index 30b205482e8..71a5f4f738e 100644 --- a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.h +++ b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.h @@ -34,47 +34,6 @@ private: return T(); } - /* - * Specialization of SearchContext - */ - template <typename M> - class SingleSearchContext final : public M, public attribute::SearchContext - { - private: - const T * _data; - - int32_t onFind(DocId docId, int32_t elemId, int32_t & weight) const override { - return find(docId, elemId, weight); - } - - int32_t onFind(DocId docId, int elemId) const override { - return find(docId, elemId); - } - - bool valid() const override; - - public: - SingleSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const NumericAttribute & toBeSearched); - int32_t find(DocId docId, int32_t elemId, int32_t & weight) const { - if ( elemId != 0) return -1; - const T v = vespalib::atomic::load_ref_relaxed(_data[docId]); - weight = 1; - return this->match(v) ? 0 : -1; - } - - int32_t find(DocId docId, int elemId) const { - if ( elemId != 0) return -1; - const T v = vespalib::atomic::load_ref_relaxed(_data[docId]); - return this->match(v) ? 0 : -1; - } - - Int64Range getAsIntegerTerm() const override; - - std::unique_ptr<queryeval::SearchIterator> - createFilterIterator(fef::TermFieldMatchData * matchData, bool strict) override; - }; - - protected: bool findEnum(T value, EnumHandle & e) const override { (void) value; (void) e; diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp index 859ad34a7e1..cf60183e2ca 100644 --- a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp @@ -9,6 +9,7 @@ #include "primitivereader.h" #include "singlenumericattribute.h" #include "singlenumericattributesaver.h" +#include "single_numeric_search_context.h" #include <vespa/searchlib/query/query_term_simple.h> #include <vespa/searchlib/queryeval/emptysearch.h> @@ -159,10 +160,11 @@ SingleValueNumericAttribute<B>::getSearch(QueryTermSimple::UP qTerm, { (void) params; QueryTermSimple::RangeResult<T> res = qTerm->getRange<T>(); + const T* data = &_data.acquire_elem_ref(0); if (res.isEqual()) { - return std::make_unique<SingleSearchContext<attribute::NumericMatcher<T>>>(std::move(qTerm), *this); + return std::make_unique<attribute::SingleNumericSearchContext<T, attribute::NumericMatcher<T>>>(std::move(qTerm), *this, data); } else { - return std::make_unique<SingleSearchContext<attribute::NumericRangeMatcher<T>>>(std::move(qTerm), *this); + return std::make_unique<attribute::SingleNumericSearchContext<T, attribute::NumericRangeMatcher<T>>>(std::move(qTerm), *this, data); } } @@ -208,44 +210,5 @@ SingleValueNumericAttribute<B>::onInitSave(vespalib::stringref fileName) (this->createAttributeHeader(fileName), &_data[0], numDocs * sizeof(T)); } -template <typename B> -template <typename M> -bool SingleValueNumericAttribute<B>::SingleSearchContext<M>::valid() const { return M::isValid(); } - -template <typename B> -template <typename M> -SingleValueNumericAttribute<B>::SingleSearchContext<M>::SingleSearchContext(QueryTermSimple::UP qTerm, - const NumericAttribute & toBeSearched) : - M(*qTerm, true), - attribute::SearchContext(toBeSearched), - _data(&static_cast<const SingleValueNumericAttribute<B> &>(toBeSearched)._data.acquire_elem_ref(0)) -{ } - - -template <typename B> -template <typename M> -Int64Range -SingleValueNumericAttribute<B>::SingleSearchContext<M>::getAsIntegerTerm() const { - return M::getRange(); -} - -template <typename B> -template <typename M> -std::unique_ptr<queryeval::SearchIterator> -SingleValueNumericAttribute<B>::SingleSearchContext<M>:: -createFilterIterator(fef::TermFieldMatchData * matchData, bool strict) -{ - if (!valid()) { - return std::make_unique<queryeval::EmptySearch>(); - } - if (getIsFilter()) { - return strict - ? std::make_unique<FilterAttributeIteratorStrict<SingleSearchContext<M>>>(*this, matchData) - : std::make_unique<FilterAttributeIteratorT<SingleSearchContext<M>>>(*this, matchData); - } - return strict - ? std::make_unique<AttributeIteratorStrict<SingleSearchContext<M>>>(*this, matchData) - : std::make_unique<AttributeIteratorT<SingleSearchContext<M>>>(*this, matchData); -} } |