summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-06-13 06:09:23 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-06-13 06:09:23 +0000
commit3fe11e1d35189ec551dfdad820260bf09cb9312a (patch)
tree200d271e6ff54c9cffd98f584640c4e4ec8501e4 /searchlib
parent9d028d9319b252a29d66f633f1627f3b42055228 (diff)
Precompute lookup keys
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/features/dotproductfeature.cpp106
-rw-r--r--searchlib/src/vespa/searchlib/features/dotproductfeature.h2
-rw-r--r--searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.h2
4 files changed, 59 insertions, 55 deletions
diff --git a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp
index 1f51ee5cef6..2424bfdee9b 100644
--- a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp
+++ b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp
@@ -351,51 +351,6 @@ size_t SparseDotProductByContentFillExecutor<BaseType>::getAttributeValues(uint3
}
-DotProductBlueprint::DotProductBlueprint() :
- Blueprint("dotProduct"),
- _defaultAttribute(),
- _queryVector()
-{ }
-
-DotProductBlueprint::~DotProductBlueprint() = default;
-
-vespalib::string
-DotProductBlueprint::getAttribute(const IQueryEnvironment & env) const
-{
- Property prop = env.getProperties().lookup(getBaseName(), _defaultAttribute + ".override.name");
- if (prop.found() && !prop.get().empty()) {
- return prop.get();
- }
- return _defaultAttribute;
-}
-
-void
-DotProductBlueprint::visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const
-{
-}
-
-bool
-DotProductBlueprint::setup(const IIndexEnvironment & env, const ParameterList & params)
-{
- _defaultAttribute = params[0].getValue();
- _queryVector = params[1].getValue();
- describeOutput("scalar", "The result after calculating the dot product of the vector represented by the weighted set "
- "and the vector sent down with the query");
- env.hintAttributeAccess(_defaultAttribute);
- return true;
-}
-
-ParameterDescriptions
-DotProductBlueprint::getDescriptions() const {
- return ParameterDescriptions().desc().attribute(ParameterDataTypeSet::normalTypeSet(), ParameterCollection::ANY).string();
-}
-
-Blueprint::UP
-DotProductBlueprint::createInstance() const
-{
- return std::make_unique<DotProductBlueprint>();
-}
-
namespace {
template <typename T, typename AsT = T>
@@ -849,19 +804,66 @@ createQueryVector(const IQueryEnvironment & env, const IAttributeVector * attrib
}
+DotProductBlueprint::DotProductBlueprint() :
+ Blueprint("dotProduct"),
+ _defaultAttribute(),
+ _queryVector(),
+ _attrKey(),
+ _queryVectorKey()
+{ }
+
+DotProductBlueprint::~DotProductBlueprint() = default;
+
+vespalib::string
+DotProductBlueprint::getAttribute(const IQueryEnvironment & env) const
+{
+ Property prop = env.getProperties().lookup(getBaseName(), _defaultAttribute + ".override.name");
+ if (prop.found() && !prop.get().empty()) {
+ return prop.get();
+ }
+ return _defaultAttribute;
+}
+
+void
+DotProductBlueprint::visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const
+{
+}
+
+bool
+DotProductBlueprint::setup(const IIndexEnvironment & env, const ParameterList & params)
+{
+ _defaultAttribute = params[0].getValue();
+ _queryVector = params[1].getValue();
+ _attrKey = make_attribute_key(getBaseName(), _defaultAttribute);
+ _queryVectorKey = make_queryvector_key(getBaseName(), _queryVector);
+ describeOutput("scalar", "The result after calculating the dot product of the vector represented by the weighted set "
+ "and the vector sent down with the query");
+ env.hintAttributeAccess(_defaultAttribute);
+ return true;
+}
+
+ParameterDescriptions
+DotProductBlueprint::getDescriptions() const {
+ return ParameterDescriptions().desc().attribute(ParameterDataTypeSet::normalTypeSet(), ParameterCollection::ANY).string();
+}
+
+Blueprint::UP
+DotProductBlueprint::createInstance() const
+{
+ return std::make_unique<DotProductBlueprint>();
+}
+
void
DotProductBlueprint::prepareSharedState(const IQueryEnvironment & env, IObjectStore & store) const
{
- vespalib::string attributeKey = make_attribute_key(getBaseName(), _defaultAttribute);
- const IAttributeVector * attribute = lookupAndStoreAttribute(attributeKey, getAttribute(env), env, store);
+ const IAttributeVector * attribute = lookupAndStoreAttribute(_attrKey, getAttribute(env), env, store);
if (attribute == nullptr) return;
- vespalib::string queryVectorKey = make_queryvector_key(getBaseName(), _queryVector);
- const fef::Anything * queryVector = env.getObjectStore().get(queryVectorKey);
+ const fef::Anything * queryVector = env.getObjectStore().get(_queryVectorKey);
if (queryVector == nullptr) {
fef::Anything::UP arguments = createQueryVector(env, attribute, getBaseName(), _queryVector);
if (arguments) {
- store.add(queryVectorKey, std::move(arguments));
+ store.add(_queryVectorKey, std::move(arguments));
}
}
@@ -872,7 +874,7 @@ FeatureExecutor &
DotProductBlueprint::createExecutor(const IQueryEnvironment & env, vespalib::Stash &stash) const
{
// Doing it "manually" here to avoid looking up attribute override unless needed.
- const fef::Anything * attributeArg = env.getObjectStore().get(make_attribute_key(getBaseName(), _defaultAttribute));
+ const fef::Anything * attributeArg = env.getObjectStore().get(_attrKey);
const IAttributeVector * attribute = (attributeArg != nullptr)
? static_cast<const fef::AnyWrapper<const IAttributeVector *> *>(attributeArg)->getValue()
: env.getAttributeContext().getAttribute(getAttribute(env));
@@ -882,7 +884,7 @@ DotProductBlueprint::createExecutor(const IQueryEnvironment & env, vespalib::Sta
return stash.create<SingleZeroValueExecutor>();
}
attribute = upgradeIfNecessary(attribute, env);
- const fef::Anything * queryVectorArg = env.getObjectStore().get(make_queryvector_key(getBaseName(), _queryVector));
+ const fef::Anything * queryVectorArg = env.getObjectStore().get(_queryVectorKey);
if (queryVectorArg != nullptr) {
return createFromObject(attribute, *queryVectorArg, stash);
} else {
diff --git a/searchlib/src/vespa/searchlib/features/dotproductfeature.h b/searchlib/src/vespa/searchlib/features/dotproductfeature.h
index 94c72233c4b..b7dc8215310 100644
--- a/searchlib/src/vespa/searchlib/features/dotproductfeature.h
+++ b/searchlib/src/vespa/searchlib/features/dotproductfeature.h
@@ -303,6 +303,8 @@ private:
using IAttributeVector = attribute::IAttributeVector;
vespalib::string _defaultAttribute;
vespalib::string _queryVector;
+ vespalib::string _attrKey;
+ vespalib::string _queryVectorKey;
vespalib::string getAttribute(const fef::IQueryEnvironment & env) const;
const IAttributeVector * upgradeIfNecessary(const IAttributeVector * attribute, const fef::IQueryEnvironment & env) const;
diff --git a/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.cpp b/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.cpp
index b1be75e21f9..26583598b34 100644
--- a/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.cpp
+++ b/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.cpp
@@ -133,7 +133,7 @@ InternalMaxReduceProdJoinBlueprint::setup(const IIndexEnvironment &env, const Pa
{
_attribute = params[0].getValue();
_attrKey = createAttributeKey(_attribute);
- _query = params[1].getValue();
+ _queryVector = params[1].getValue();
describeOutput("scalar", "Internal executor for optimized execution of reduce(join(A,Q,f(x,y)(x*y)),max)");
env.hintAttributeAccess(_attribute);
return true;
@@ -204,7 +204,7 @@ InternalMaxReduceProdJoinBlueprint::createExecutor(const IQueryEnvironment &env,
"returning executor with default value.", _attribute.c_str());
return stash.create<SingleZeroValueExecutor>();
}
- Property prop = env.getProperties().lookup(_query);
+ Property prop = env.getProperties().lookup(_queryVector);
if (prop.found() && !prop.get().empty()) {
IntegerVector vector;
WeightedSetParser::parse(prop.get(), vector);
diff --git a/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.h b/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.h
index 3c296e06bbb..4ff4a05853c 100644
--- a/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.h
+++ b/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.h
@@ -26,7 +26,7 @@ class InternalMaxReduceProdJoinBlueprint : public fef::Blueprint {
private:
vespalib::string _attribute;
vespalib::string _attrKey; // Used for looking up the attribute in the ObjectStore.
- vespalib::string _query;
+ vespalib::string _queryVector;
public:
InternalMaxReduceProdJoinBlueprint();