summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2022-07-05 12:19:56 +0000
committerGeir Storli <geirst@yahooinc.com>2022-07-05 12:19:56 +0000
commit9bd21837203e76da9a0f935a902b0403ec67a2de (patch)
treeca8e164fc377eaa5a2732534efe542104c994bd0 /searchcore
parentf2802027f402d5b16f5fffb9cfc5a3d7f7401ab4 (diff)
Reduce code duplication by using fef::QueryValue in RequestContext implementation.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/tests/proton/matching/request_context/request_context_test.cpp23
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp2
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_tools.h2
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp32
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/requestcontext.h16
-rw-r--r--searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp2
-rw-r--r--searchcore/src/vespa/searchcorespi/index/warmupindexcollection.h2
7 files changed, 45 insertions, 34 deletions
diff --git a/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp b/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp
index 191c1718f61..3e74ed152b1 100644
--- a/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp
+++ b/searchcore/src/tests/proton/matching/request_context/request_context_test.cpp
@@ -5,7 +5,8 @@
#include <vespa/eval/eval/tensor_spec.h>
#include <vespa/searchcore/proton/matching/requestcontext.h>
#include <vespa/searchlib/attribute/attribute_blueprint_params.h>
-#include <vespa/searchlib/fef/properties.h>
+#include <vespa/searchlib/fef/test/indexenvironment.h>
+#include <vespa/searchlib/fef/test/queryenvironment.h>
#include <vespa/vespalib/util/testclock.h>
#include <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/objects/nbostream.h>
@@ -14,11 +15,14 @@ using search::attribute::AttributeBlueprintParams;
using search::attribute::IAttributeContext;
using search::attribute::IAttributeFunctor;
using search::attribute::IAttributeVector;
-using search::fef::Properties;
+using search::fef::test::IndexEnvironment;
+using search::fef::test::QueryEnvironment;
using vespalib::eval::SimpleValue;
using vespalib::eval::TensorSpec;
using vespalib::eval::Value;
+
using namespace proton;
+using namespace search::fef::indexproperties;
class MyAttributeContext : public search::attribute::IAttributeContext {
public:
@@ -33,14 +37,15 @@ private:
vespalib::TestClock _clock;
vespalib::Doom _doom;
MyAttributeContext _attr_ctx;
- Properties _props;
+ IndexEnvironment _index_env;
+ QueryEnvironment _query_env;
RequestContext _request_ctx;
Value::UP _query_tensor;
void insert_tensor_in_properties(const vespalib::string& tensor_name, const Value& tensor_value) {
vespalib::nbostream stream;
encode_value(tensor_value, stream);
- _props.add(tensor_name, vespalib::stringref(stream.data(), stream.size()));
+ _query_env.getProperties().add(tensor_name, vespalib::stringref(stream.data(), stream.size()));
}
public:
@@ -48,18 +53,20 @@ public:
: _clock(),
_doom(_clock.clock(), vespalib::steady_time(), vespalib::steady_time(), false),
_attr_ctx(),
- _props(),
- _request_ctx(_doom, _attr_ctx, _props, AttributeBlueprintParams()),
+ _index_env(),
+ _query_env(&_index_env),
+ _request_ctx(_doom, _attr_ctx, _query_env, _query_env.getObjectStore(), AttributeBlueprintParams()),
_query_tensor(SimpleValue::from_spec(TensorSpec("tensor(x[2])")
.add({{"x", 0}}, 3).add({{"x", 1}}, 5)))
{
+ type::QueryFeature::set(_index_env.getProperties(), "my_tensor", "tensor(x[2])");
insert_tensor_in_properties("my_tensor", *_query_tensor);
- _props.add("my_string", "foo bar");
+ _query_env.getProperties().add("my_string", "foo bar");
}
TensorSpec expected_query_tensor() const {
return spec_from_value(*_query_tensor);
}
- Value::UP get_query_tensor(const vespalib::string& tensor_name) const {
+ const Value* get_query_tensor(const vespalib::string& tensor_name) const {
return _request_ctx.get_query_tensor(tensor_name);
}
};
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp
index 8379f8b1a3a..e0449236af0 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp
@@ -172,10 +172,10 @@ MatchToolsFactory(QueryLimiter & queryLimiter,
bool is_search)
: _queryLimiter(queryLimiter),
_global_filter_params(extract_global_filter_params(rankSetup, rankProperties, metaStore.getNumActiveLids(), searchContext.getDocIdLimit())),
- _requestContext(doom, attributeContext, rankProperties, _global_filter_params),
_query(),
_match_limiter(),
_queryEnv(indexEnv, attributeContext, rankProperties, searchContext.getIndexes()),
+ _requestContext(doom, attributeContext, _queryEnv, _queryEnv.getObjectStore(), _global_filter_params),
_mdl(),
_rankSetup(rankSetup),
_featureOverrides(featureOverrides),
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_tools.h b/searchcore/src/vespa/searchcore/proton/matching/match_tools.h
index d01ea05f3f7..11e943957ef 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_tools.h
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_tools.h
@@ -94,10 +94,10 @@ private:
using IAttributeFunctor = search::attribute::IAttributeFunctor;
QueryLimiter & _queryLimiter;
search::attribute::AttributeBlueprintParams _global_filter_params;
- RequestContext _requestContext;
Query _query;
MaybeMatchPhaseLimiter::UP _match_limiter;
QueryEnvironment _queryEnv;
+ RequestContext _requestContext;
search::fef::MatchDataLayout _mdl;
const search::fef::RankSetup & _rankSetup;
const search::fef::Properties & _featureOverrides;
diff --git a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp
index 055ee586856..0d5edf44d05 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp
@@ -4,9 +4,9 @@
#include <vespa/eval/eval/fast_value.h>
#include <vespa/eval/eval/value_codec.h>
#include <vespa/searchlib/attribute/attributevector.h>
-#include <vespa/searchlib/fef/properties.h>
+#include <vespa/searchlib/fef/iqueryenvironment.h>
+#include <vespa/searchlib/fef/query_value.h>
#include <vespa/vespalib/objects/nbostream.h>
-#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/util/issue.h>
#include <vespa/log/log.h>
@@ -20,11 +20,13 @@ namespace proton {
using search::attribute::IAttributeVector;
RequestContext::RequestContext(const Doom & doom, IAttributeContext & attributeContext,
- const search::fef::Properties& rank_properties,
+ const search::fef::IQueryEnvironment& query_env,
+ search::fef::IObjectStore& shared_store,
const search::attribute::AttributeBlueprintParams& attribute_blueprint_params)
: _doom(doom),
_attributeContext(attributeContext),
- _rank_properties(rank_properties),
+ _query_env(query_env),
+ _shared_store(shared_store),
_attribute_blueprint_params(attribute_blueprint_params)
{
}
@@ -47,22 +49,18 @@ RequestContext::asyncForAttribute(const vespalib::string &name, std::unique_ptr<
_attributeContext.asyncForAttribute(name, std::move(func));
}
-vespalib::eval::Value::UP
+const vespalib::eval::Value*
RequestContext::get_query_tensor(const vespalib::string& tensor_name) const
{
- auto property = _rank_properties.lookup(tensor_name);
- if (property.found() && !property.get().empty()) {
- const vespalib::string& value = property.get();
- vespalib::nbostream stream(value.data(), value.size());
- try {
- return decode_value(stream, FastValueBuilderFactory::get());
- } catch (vespalib::eval::DecodeValueException& ex) {
- Issue::report("Query tensor '%s' could not be deserialized: %s",
- tensor_name.c_str(), ex.getMessage().c_str());
- return {};
- }
+ try {
+ auto value = search::fef::QueryValue::from_config(tensor_name, _query_env.getIndexEnvironment());
+ value.prepare_shared_state(_query_env, _shared_store);
+ return value.lookup_value(_shared_store);
+ } catch (const search::fef::InvalidValueTypeException& ex) {
+ Issue::report("Invalid type '%s' for query tensor '%s'",
+ ex.getMessage().c_str(), tensor_name.c_str());
+ return nullptr;
}
- return {};
}
const search::attribute::AttributeBlueprintParams&
diff --git a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h
index b9e566c2429..9ab9acc6d71 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h
+++ b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.h
@@ -8,7 +8,10 @@
#include <vespa/searchlib/attribute/attribute_blueprint_params.h>
#include <vespa/vespalib/util/doom.h>
-namespace search::fef { class Properties; }
+namespace search::fef {
+class IObjectStore;
+class IQueryEnvironment;
+}
namespace proton {
@@ -19,8 +22,10 @@ public:
using IAttributeContext = search::attribute::IAttributeContext;
using IAttributeFunctor = search::attribute::IAttributeFunctor;
using Doom = vespalib::Doom;
- RequestContext(const Doom & softDoom, IAttributeContext & attributeContext,
- const search::fef::Properties& rank_properties,
+ RequestContext(const Doom& softDoom,
+ IAttributeContext& attributeContext,
+ const search::fef::IQueryEnvironment& query_env,
+ search::fef::IObjectStore& shared_store,
const search::attribute::AttributeBlueprintParams& attribute_blueprint_params);
const Doom & getDoom() const override { return _doom; }
@@ -30,14 +35,15 @@ public:
const search::attribute::IAttributeVector *getAttributeStableEnum(const vespalib::string &name) const override;
- vespalib::eval::Value::UP get_query_tensor(const vespalib::string& tensor_name) const override;
+ const vespalib::eval::Value* get_query_tensor(const vespalib::string& tensor_name) const override;
const search::attribute::AttributeBlueprintParams& get_attribute_blueprint_params() const override;
private:
const Doom _doom;
IAttributeContext & _attributeContext;
- const search::fef::Properties & _rank_properties;
+ const search::fef::IQueryEnvironment& _query_env;
+ search::fef::IObjectStore& _shared_store;
search::attribute::AttributeBlueprintParams _attribute_blueprint_params;
};
diff --git a/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp b/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp
index bf437dd7ee3..8807def03d4 100644
--- a/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp
+++ b/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.cpp
@@ -233,7 +233,7 @@ WarmupIndexCollection::WarmupRequestContext::WarmupRequestContext(const vespalib
{}
WarmupIndexCollection::WarmupRequestContext::~WarmupRequestContext() = default;
-std::unique_ptr<vespalib::eval::Value>
+const vespalib::eval::Value*
WarmupIndexCollection::WarmupRequestContext::get_query_tensor(const vespalib::string&) const {
return {};
}
diff --git a/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.h b/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.h
index c2d70b4fd5c..2623de5b98f 100644
--- a/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.h
+++ b/searchcore/src/vespa/searchcorespi/index/warmupindexcollection.h
@@ -82,7 +82,7 @@ private:
const vespalib::Doom & getDoom() const override { return _doom; }
const IAttributeVector *getAttribute(const vespalib::string &) const override { return nullptr; }
const IAttributeVector *getAttributeStableEnum(const vespalib::string &) const override { return nullptr; }
- std::unique_ptr<vespalib::eval::Value> get_query_tensor(const vespalib::string&) const override;
+ const vespalib::eval::Value* get_query_tensor(const vespalib::string&) const override;
const AttributeBlueprintParams& get_attribute_blueprint_params() const override { return _params; }
private:
const vespalib::Doom _doom;