// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include #include namespace search { class QueryTermSimple; } namespace search::attribute { /* * Class used to determine if an attribute vector value is a match for * the query range. */ template class NumericRangeMatcher { protected: T _low; T _high; private: bool _valid; int _limit; size_t _max_per_group; public: NumericRangeMatcher(const QueryTermSimple& queryTerm) : NumericRangeMatcher(queryTerm, false) {} NumericRangeMatcher(const QueryTermSimple& queryTerm, bool avoidUndefinedInRange); protected: Int64Range getRange() const { return {static_cast(_low), static_cast(_high)}; } DoubleRange getDoubleRange() const { return {static_cast(_low), static_cast(_high)}; } bool isValid() const { return _valid; } bool match(T v) const { return (_low <= v) && (v <= _high); } int getRangeLimit() const { return _limit; } size_t getMaxPerGroup() const { return _max_per_group; } template search::Range cappedRange(bool isFloat) { auto low = static_cast(_low); auto high = static_cast(_high); BaseType numMin = std::numeric_limits::min(); BaseType numMax = std::numeric_limits::max(); if (isFloat) { if (_low <= (-numMax)) { low = -numMax; } } else { if (_low <= (numMin)) { low = numMin + 1; // we must avoid the undefined value } } if (_high >= (numMax)) { high = numMax; } return search::Range(low, high); } }; }