summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-09-04 21:41:42 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-09-08 07:50:16 +0000
commit8a2279f1c8a50903960a8e3854c270377eed3f54 (patch)
treed6ac792c2df814fed4dfedce28c2ffad52d657d9 /searchlib
parent5425fb81e33874f0d767743b01859b9efe26139b (diff)
Find and locate range query item in the 'and' path of a query.
If found and correlates with match phase limiter, copy the limits into the limiter.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchcommon/attribute/i_search_context.h1
-rw-r--r--searchlib/src/vespa/searchcommon/common/range.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp30
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_search_context.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/numeric_matcher.h5
-rw-r--r--searchlib/src/vespa/searchlib/attribute/numeric_range_matcher.h5
-rw-r--r--searchlib/src/vespa/searchlib/attribute/numeric_search_context.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/numeric_search_context.hpp7
-rw-r--r--searchlib/src/vespa/searchlib/attribute/search_context.h4
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/blueprint.cpp5
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/blueprint.h1
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/leaf_blueprints.cpp5
13 files changed, 64 insertions, 6 deletions
diff --git a/searchlib/src/vespa/searchcommon/attribute/i_search_context.h b/searchlib/src/vespa/searchcommon/attribute/i_search_context.h
index aa5e216ecd9..8867d1b87e4 100644
--- a/searchlib/src/vespa/searchcommon/attribute/i_search_context.h
+++ b/searchlib/src/vespa/searchcommon/attribute/i_search_context.h
@@ -51,6 +51,7 @@ public:
virtual bool valid() const = 0;
virtual Int64Range getAsIntegerTerm() const = 0;
+ virtual DoubleRange getAsDoubleTerm() const = 0;
virtual const QueryTermUCS4 * queryTerm() const = 0;
virtual const vespalib::string &attributeName() const = 0;
diff --git a/searchlib/src/vespa/searchcommon/common/range.h b/searchlib/src/vespa/searchcommon/common/range.h
index ea2553c129b..214d39327a0 100644
--- a/searchlib/src/vespa/searchcommon/common/range.h
+++ b/searchlib/src/vespa/searchcommon/common/range.h
@@ -25,5 +25,6 @@ private:
};
using Int64Range = Range<int64_t>;
+using DoubleRange = Range<double>;
} // namespace search
diff --git a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp
index 57423f42a10..c1a46649d23 100644
--- a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp
@@ -117,15 +117,23 @@ class AttributeFieldBlueprint : public SimpleLeafBlueprint
{
private:
ISearchContext::UP _search_context;
+ enum Type {INT, FLOAT, OTHER};
+ Type _type;
AttributeFieldBlueprint(const FieldSpec &field, const IAttributeVector &attribute,
QueryTermSimple::UP term, const attribute::SearchContextParams &params)
: SimpleLeafBlueprint(field),
- _search_context(attribute.createSearchContext(std::move(term), params))
+ _search_context(attribute.createSearchContext(std::move(term), params)),
+ _type(OTHER)
{
uint32_t estHits = _search_context->approximateHits();
HitEstimate estimate(estHits, estHits == 0);
setEstimate(estimate);
+ if (attribute.isFloatingPointType()) {
+ _type = FLOAT;
+ } else if (attribute.isIntegerType()) {
+ _type = INT;
+ }
}
AttributeFieldBlueprint(const FieldSpec &field, const IAttributeVector &attribute,
@@ -180,6 +188,7 @@ public:
const attribute::ISearchContext *get_attribute_search_context() const override {
return _search_context.get();
}
+ bool getRange(vespalib::string &from, vespalib::string &to) const override;
};
void
@@ -535,6 +544,25 @@ DirectWandBlueprint::createFilterSearch(bool, FilterConstraint constraint) const
}
}
+bool
+AttributeFieldBlueprint::getRange(vespalib::string &from, vespalib::string &to) const {
+ if (_type == INT) {
+ Int64Range range = _search_context->getAsIntegerTerm();
+ char buf[32];
+ auto res = std::to_chars(buf, buf + sizeof(buf), range.lower(), 10);
+ from = vespalib::stringref(buf, res.ptr - buf);
+ res = std::to_chars(buf, buf + sizeof(buf), range.upper(), 10);
+ to = vespalib::stringref(buf, res.ptr - buf);
+ return true;
+ } else if (_type == FLOAT) {
+ DoubleRange range = _search_context->getAsDoubleTerm();
+ from = vespalib::make_string("%g", range.lower());
+ to = vespalib::make_string("%g", range.upper());
+ return true;
+ }
+ return false;
+}
+
//-----------------------------------------------------------------------------
class DirectAttributeBlueprint : public queryeval::SimpleLeafBlueprint
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp b/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
index d949ea40c4a..9c4f8395fec 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
@@ -255,6 +255,10 @@ Int64Range ImportedSearchContext::getAsIntegerTerm() const {
return _target_search_context->getAsIntegerTerm();
}
+DoubleRange ImportedSearchContext::getAsDoubleTerm() const {
+ return _target_search_context->getAsDoubleTerm();
+}
+
const QueryTermUCS4 * ImportedSearchContext::queryTerm() const {
return _target_search_context->queryTerm();
}
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_search_context.h b/searchlib/src/vespa/searchlib/attribute/imported_search_context.h
index 15e0c3228bb..7b32d64e11f 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_search_context.h
+++ b/searchlib/src/vespa/searchlib/attribute/imported_search_context.h
@@ -63,6 +63,7 @@ public:
void fetchPostings(const queryeval::ExecuteInfo &execInfo) override;
bool valid() const override;
Int64Range getAsIntegerTerm() const override;
+ DoubleRange getAsDoubleTerm() const override;
const QueryTermUCS4 * queryTerm() const override;
const vespalib::string& attributeName() const override;
diff --git a/searchlib/src/vespa/searchlib/attribute/numeric_matcher.h b/searchlib/src/vespa/searchlib/attribute/numeric_matcher.h
index 9d42b653c0e..b5095128dd5 100644
--- a/searchlib/src/vespa/searchlib/attribute/numeric_matcher.h
+++ b/searchlib/src/vespa/searchlib/attribute/numeric_matcher.h
@@ -23,7 +23,10 @@ protected:
bool isValid() const { return _valid; }
bool match(T v) const { return v == _value; }
Int64Range getRange() const {
- return Int64Range(static_cast<int64_t>(_value));
+ return {static_cast<int64_t>(_value)};
+ }
+ DoubleRange getDoubleRange() const {
+ return {static_cast<double>(_value)};
}
};
diff --git a/searchlib/src/vespa/searchlib/attribute/numeric_range_matcher.h b/searchlib/src/vespa/searchlib/attribute/numeric_range_matcher.h
index 3be73554268..f1e609e9314 100644
--- a/searchlib/src/vespa/searchlib/attribute/numeric_range_matcher.h
+++ b/searchlib/src/vespa/searchlib/attribute/numeric_range_matcher.h
@@ -27,7 +27,10 @@ public:
NumericRangeMatcher(const QueryTermSimple& queryTerm, bool avoidUndefinedInRange=false);
protected:
Int64Range getRange() const {
- return Int64Range(static_cast<int64_t>(_low), static_cast<int64_t>(_high));
+ return {static_cast<int64_t>(_low), static_cast<int64_t>(_high)};
+ }
+ DoubleRange getDoubleRange() const {
+ return {static_cast<double>(_low), static_cast<double>(_high)};
}
bool isValid() const { return _valid; }
bool match(T v) const { return (_low <= v) && (v <= _high); }
diff --git a/searchlib/src/vespa/searchlib/attribute/numeric_search_context.h b/searchlib/src/vespa/searchlib/attribute/numeric_search_context.h
index 9c17af3677b..ab2ea4758c3 100644
--- a/searchlib/src/vespa/searchlib/attribute/numeric_search_context.h
+++ b/searchlib/src/vespa/searchlib/attribute/numeric_search_context.h
@@ -19,6 +19,7 @@ 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;
+ DoubleRange getAsDoubleTerm() 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
index f9435578303..56e6b3321d4 100644
--- a/searchlib/src/vespa/searchlib/attribute/numeric_search_context.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/numeric_search_context.hpp
@@ -28,6 +28,13 @@ NumericSearchContext<Matcher>::getAsIntegerTerm() const
}
template <typename Matcher>
+DoubleRange
+NumericSearchContext<Matcher>::getAsDoubleTerm() const
+{
+ return Matcher::getDoubleRange();
+}
+
+template <typename Matcher>
bool
NumericSearchContext<Matcher>::valid() const
{
diff --git a/searchlib/src/vespa/searchlib/attribute/search_context.h b/searchlib/src/vespa/searchlib/attribute/search_context.h
index 6ae92e0cb85..8e1297ad2df 100644
--- a/searchlib/src/vespa/searchlib/attribute/search_context.h
+++ b/searchlib/src/vespa/searchlib/attribute/search_context.h
@@ -29,7 +29,7 @@ public:
SearchContext(const SearchContext&) = delete;
SearchContext(SearchContext&&) noexcept = default;
SearchContext& operator=(const SearchContext&) = delete;
- SearchContext& operator=(SearchContext&&) = delete;
+ SearchContext& operator=(SearchContext&&) noexcept = delete;
~SearchContext() override;
unsigned int approximateHits() const override;
@@ -37,6 +37,8 @@ public:
void fetchPostings(const queryeval::ExecuteInfo& execInfo) override;
bool valid() const override { return false; }
Int64Range getAsIntegerTerm() const override { return Int64Range(); }
+ DoubleRange getAsDoubleTerm() const override { return DoubleRange(); }
+
const QueryTermUCS4* queryTerm() const override {
return static_cast<const QueryTermUCS4*>(nullptr);
}
diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
index f066e84407b..ff83dd92f3b 100644
--- a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
@@ -618,6 +618,11 @@ LeafBlueprint::createSearch(fef::MatchData &md, bool strict) const
return createLeafSearch(tfmda, strict);
}
+bool
+LeafBlueprint::getRange(vespalib::string &, vespalib::string &) const {
+ return false;
+}
+
void
LeafBlueprint::optimize(Blueprint* &self)
{
diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.h b/searchlib/src/vespa/searchlib/queryeval/blueprint.h
index 83836f874f0..6dbd3cb9a5c 100644
--- a/searchlib/src/vespa/searchlib/queryeval/blueprint.h
+++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.h
@@ -362,6 +362,7 @@ public:
void freeze() final;
SearchIteratorUP createSearch(fef::MatchData &md, bool strict) const override;
+ virtual bool getRange(vespalib::string & from, vespalib::string & to) const;
virtual SearchIteratorUP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool strict) const = 0;
};
diff --git a/searchlib/src/vespa/searchlib/queryeval/leaf_blueprints.cpp b/searchlib/src/vespa/searchlib/queryeval/leaf_blueprints.cpp
index 53ffe839a72..8880c7ef24e 100644
--- a/searchlib/src/vespa/searchlib/queryeval/leaf_blueprints.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/leaf_blueprints.cpp
@@ -125,8 +125,9 @@ struct FakeContext : attribute::ISearchContext {
std::unique_ptr<SearchIterator> createIterator(fef::TermFieldMatchData *, bool) override { abort(); }
void fetchPostings(const ExecuteInfo &) override { }
bool valid() const override { return true; }
- search::Int64Range getAsIntegerTerm() const override { abort(); }
- const search::QueryTermUCS4 * queryTerm() const override { abort(); }
+ Int64Range getAsIntegerTerm() const override { abort(); }
+ DoubleRange getAsDoubleTerm() const override { abort(); }
+ const QueryTermUCS4 * queryTerm() const override { abort(); }
const vespalib::string &attributeName() const override { return name; }
};