From a9197eae34dd3d0bec1e0c55e52aa37f5cfcd1a3 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Sun, 3 Apr 2022 23:26:35 +0200 Subject: Factor out SingleSmallNumericSearchContext from SingleSmallNumericAttribute. --- .../src/vespa/searchlib/attribute/CMakeLists.txt | 1 + .../single_small_numeric_search_context.cpp | 35 +++++++++++++ .../single_small_numeric_search_context.h | 58 ++++++++++++++++++++++ .../attribute/singlesmallnumericattribute.cpp | 39 +-------------- .../attribute/singlesmallnumericattribute.h | 50 ------------------- 5 files changed, 96 insertions(+), 87 deletions(-) create mode 100644 searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.cpp create mode 100644 searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h diff --git a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt index 3c34bf8a57d..b3aa3bd958b 100644 --- a/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/attribute/CMakeLists.txt @@ -110,6 +110,7 @@ vespa_add_library(searchlib_attribute OBJECT singlestringpostattribute.cpp single_numeric_enum_search_context.cpp single_numeric_search_context.cpp + single_small_numeric_search_context.cpp single_string_enum_search_context.cpp single_string_enum_hint_search_context.cpp sourceselector.cpp diff --git a/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.cpp b/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.cpp new file mode 100644 index 00000000000..5eeef7cd61a --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.cpp @@ -0,0 +1,35 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "single_small_numeric_search_context.h" +#include "attributeiterators.hpp" +#include + +namespace search::attribute { + +SingleSmallNumericSearchContext::SingleSmallNumericSearchContext(std::unique_ptr qTerm, const AttributeVector& toBeSearched, const Word* word_data, Word value_mask, uint32_t value_shift_shift, uint32_t value_shift_mask, uint32_t word_shift) + : NumericSearchContext>(toBeSearched, *qTerm, false), + _wordData(word_data), + _valueMask(value_mask), + _valueShiftShift(value_shift_shift), + _valueShiftMask(value_shift_mask), + _wordShift(word_shift) +{ +} + +std::unique_ptr +SingleSmallNumericSearchContext::createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) +{ + if (!valid()) { + return std::make_unique(); + } + if (getIsFilter()) { + return strict + ? std::make_unique>(*this, matchData) + : std::make_unique>(*this, matchData); + } + return strict + ? std::make_unique>(*this, matchData) + : std::make_unique>(*this, matchData); +} + +} diff --git a/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h b/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h new file mode 100644 index 00000000000..46ed02b3eca --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/single_small_numeric_search_context.h @@ -0,0 +1,58 @@ +// 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" +#include "numeric_range_matcher.h" +#include + +namespace search::attribute { + +/* + * SingleSmallNumericSearchContext handles the creation of search iterators for + * a query term on a single value small numeric attribute vector. + */ +class SingleSmallNumericSearchContext : public NumericSearchContext> +{ +private: + using Word = uint32_t; + using T = int8_t; + const Word *_wordData; + Word _valueMask; + uint32_t _valueShiftShift; + uint32_t _valueShiftMask; + uint32_t _wordShift; + + int32_t onFind(DocId docId, int32_t elementId, int32_t & weight) const override { + return find(docId, elementId, weight); + } + + int32_t onFind(DocId docId, int32_t elementId) const override { + return find(docId, elementId); + } + +public: + SingleSmallNumericSearchContext(std::unique_ptr qTerm, const AttributeVector& toBeSearched, const Word* word_data, Word value_mask, uint32_t value_shift_shift, uint32_t value_shift_mask, uint32_t word_shift); + + int32_t find(DocId docId, int32_t elemId, int32_t & weight) const { + if ( elemId != 0) return -1; + const Word &word = _wordData[docId >> _wordShift]; + uint32_t valueShift = (docId & _valueShiftMask) << _valueShiftShift; + T v = (vespalib::atomic::load_ref_relaxed(word) >> valueShift) & _valueMask; + weight = 1; + return match(v) ? 0 : -1; + } + + int32_t find(DocId docId, int32_t elemId) const { + if ( elemId != 0) return -1; + const Word &word = _wordData[docId >> _wordShift]; + uint32_t valueShift = (docId & _valueShiftMask) << _valueShiftShift; + T v = (vespalib::atomic::load_ref_relaxed(word) >> valueShift) & _valueMask; + return match(v) ? 0 : -1; + } + + std::unique_ptr + createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) override; +}; + +} diff --git a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp index 009078447dc..eca74255026 100644 --- a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp +++ b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp @@ -1,12 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "singlesmallnumericattribute.h" -#include "attributeiterators.hpp" #include "attributevector.hpp" #include "iattributesavetarget.h" #include "primitivereader.h" +#include "single_small_numeric_search_context.h" #include -#include #include #include #include @@ -172,7 +171,7 @@ std::unique_ptr SingleValueSmallNumericAttribute::getSearch(std::unique_ptr qTerm, const attribute::SearchContextParams &) const { - return std::make_unique(std::move(qTerm), *this); + return std::make_unique(std::move(qTerm), *this, &_wordData.acquire_elem_ref(0), _valueMask, _valueShiftShift, _valueShiftMask, _wordShift); } void @@ -208,40 +207,6 @@ SingleValueSmallNumericAttribute::getEstimatedSaveByteSize() const return headerSize + sz; } -bool SingleValueSmallNumericAttribute::SingleSearchContext::valid() const { return this->isValid(); } - - -SingleValueSmallNumericAttribute::SingleSearchContext::SingleSearchContext(std::unique_ptr qTerm, - const SingleValueSmallNumericAttribute & toBeSearched) - : attribute::NumericRangeMatcher(*qTerm), - SearchContext(toBeSearched), _wordData(&toBeSearched._wordData.acquire_elem_ref(0)), - _valueMask(toBeSearched._valueMask), - _valueShiftShift(toBeSearched._valueShiftShift), - _valueShiftMask(toBeSearched._valueShiftMask), - _wordShift(toBeSearched._wordShift) -{ } - -Int64Range -SingleValueSmallNumericAttribute::SingleSearchContext::getAsIntegerTerm() const { - return this->getRange(); -} - -std::unique_ptr -SingleValueSmallNumericAttribute::SingleSearchContext::createFilterIterator(fef::TermFieldMatchData * matchData, bool strict) -{ - if (!valid()) { - return std::make_unique(); - } - if (getIsFilter()) { - return strict - ? std::make_unique>(*this, matchData) - : std::make_unique>(*this, matchData); - } - return strict - ? std::make_unique>(*this, matchData) - : std::make_unique>(*this, matchData); -} - namespace { template diff --git a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.h b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.h index 77c4133817c..f6059d3d510 100644 --- a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.h +++ b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.h @@ -3,8 +3,6 @@ #pragma once #include "integerbase.h" -#include "floatbase.h" -#include "numeric_range_matcher.h" #include "search_context.h" #include #include @@ -15,7 +13,6 @@ namespace search { class SingleValueSmallNumericAttribute : public IntegerAttributeTemplate { private: -// friend class attribute::SearchContext; typedef IntegerAttributeTemplate B; typedef B::BaseType T; typedef B::DocId DocId; @@ -58,53 +55,6 @@ protected: public: - /* - * Specialization of SearchContext - */ - class SingleSearchContext : public attribute::NumericRangeMatcher, public attribute::SearchContext - { - private: - const Word *_wordData; - Word _valueMask; - uint32_t _valueShiftShift; - uint32_t _valueShiftMask; - uint32_t _wordShift; - - int32_t onFind(DocId docId, int32_t elementId, int32_t & weight) const override { - return find(docId, elementId, weight); - } - - int32_t onFind(DocId docId, int32_t elementId) const override { - return find(docId, elementId); - } - - bool valid() const override; - - public: - SingleSearchContext(std::unique_ptr qTerm, const SingleValueSmallNumericAttribute & toBeSearched); - - int32_t find(DocId docId, int32_t elemId, int32_t & weight) const { - if ( elemId != 0) return -1; - const Word &word = _wordData[docId >> _wordShift]; - uint32_t valueShift = (docId & _valueShiftMask) << _valueShiftShift; - T v = (vespalib::atomic::load_ref_relaxed(word) >> valueShift) & _valueMask; - weight = 1; - return match(v) ? 0 : -1; - } - - int32_t find(DocId docId, int32_t elemId) const { - if ( elemId != 0) return -1; - const Word &word = _wordData[docId >> _wordShift]; - uint32_t valueShift = (docId & _valueShiftMask) << _valueShiftShift; - T v = (vespalib::atomic::load_ref_relaxed(word) >> valueShift) & _valueMask; - return match(v) ? 0 : -1; - } - - Int64Range getAsIntegerTerm() const override; - - std::unique_ptr - createFilterIterator(fef::TermFieldMatchData * matchData, bool strict) override; - }; SingleValueSmallNumericAttribute(const vespalib::string & baseFileName, const Config &c, Word valueMask, uint32_t valueShiftShift, uint32_t valueShiftMask, uint32_t wordShift); -- cgit v1.2.3