summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2017-08-17 16:24:32 +0000
committerHåvard Pettersen <havardpe@oath.com>2017-08-18 13:19:57 +0000
commite303676db9689853dd205989a553dbd035e467d1 (patch)
tree6b1d29c2a38862662dac85302abba691f326206c /searchlib
parentf8316175b4ac6e715d358dc33934b6253bd584a1 (diff)
intrinsic blueprint adapter
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/features/rankingexpression/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_blueprint_adapter.cpp75
-rw-r--r--searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_blueprint_adapter.h25
3 files changed, 101 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/features/rankingexpression/CMakeLists.txt b/searchlib/src/vespa/searchlib/features/rankingexpression/CMakeLists.txt
index 3ca8c36398c..68b4c4bb043 100644
--- a/searchlib/src/vespa/searchlib/features/rankingexpression/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/features/rankingexpression/CMakeLists.txt
@@ -3,6 +3,7 @@ vespa_add_library(searchlib_features_rankingexpression OBJECT
SOURCES
expression_replacer.cpp
feature_name_extractor.cpp
+ intrinsic_blueprint_adapter.cpp
intrinsic_expression.cpp
DEPENDS
)
diff --git a/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_blueprint_adapter.cpp b/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_blueprint_adapter.cpp
new file mode 100644
index 00000000000..92dbfb75eda
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_blueprint_adapter.cpp
@@ -0,0 +1,75 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "intrinsic_blueprint_adapter.h"
+#include <vespa/searchlib/fef/fef.h>
+
+using search::fef::Blueprint;
+using search::fef::FeatureExecutor;
+using search::fef::FeatureNameBuilder;
+using search::fef::FeatureType;
+
+namespace search::features::rankingexpression {
+
+namespace {
+
+bool is_valid(const FeatureType *type) {
+ if (type == nullptr) {
+ return false;
+ }
+ if (!type->is_object()) {
+ return true;
+ }
+ return !type->type().is_error();
+}
+
+struct IntrinsicBlueprint : IntrinsicExpression {
+ Blueprint::UP blueprint;
+ FeatureType type;
+ IntrinsicBlueprint(Blueprint::UP blueprint_in, const FeatureType &type_in)
+ : blueprint(std::move(blueprint_in)), type(type_in) {}
+ FeatureType result_type() const override { return type; }
+ FeatureExecutor &create_executor(const QueryEnv &queryEnv, vespalib::Stash &stash) const override {
+ return blueprint->createExecutor(queryEnv, stash);
+ }
+};
+
+struct ResultTypeExtractor : Blueprint::DependencyHandler {
+ std::unique_ptr<FeatureType> result_type;
+ bool too_much;
+ ResultTypeExtractor() : result_type(), too_much(false) {}
+ const FeatureType &resolve_input(const vespalib::string &, Blueprint::AcceptInput) override {
+ too_much = true;
+ return FeatureType::number();
+ }
+ void define_output(const vespalib::string &, const FeatureType &type) override {
+ too_much = (too_much || bool(result_type));
+ result_type = std::make_unique<FeatureType>(type);
+ }
+ bool valid() const { return (is_valid(result_type.get()) && !too_much); }
+ const FeatureType &get() const { return *result_type; }
+};
+
+} // namespace search::features::rankingexpression::<unnamed>
+
+IntrinsicExpression::UP
+IntrinsicBlueprintAdapter::try_create(const search::fef::Blueprint &proto,
+ const search::fef::IIndexEnvironment &env,
+ const std::vector<vespalib::string> &params)
+{
+ FeatureNameBuilder name_builder;
+ ResultTypeExtractor result_type;
+ Blueprint::UP blueprint = proto.createInstance();
+ name_builder.baseName(blueprint->getBaseName());
+ for (const auto &param: params) {
+ name_builder.parameter(param);
+ }
+ blueprint->setName(name_builder.buildName());
+ blueprint->attach_dependency_handler(result_type);
+ if (!blueprint->setup(env, params) || !result_type.valid()) {
+ return IntrinsicExpression::UP(nullptr);
+ }
+ blueprint->detach_dependency_handler();
+ return std::make_unique<IntrinsicBlueprint>(std::move(blueprint), result_type.get());
+}
+
+} // namespace search::features::rankingexpression
diff --git a/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_blueprint_adapter.h b/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_blueprint_adapter.h
new file mode 100644
index 00000000000..01c6ced2391
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_blueprint_adapter.h
@@ -0,0 +1,25 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "intrinsic_expression.h"
+#include <vespa/vespalib/stllike/string.h>
+#include <vector>
+
+namespace search::fef { class Blueprint; }
+namespace search::fef { class IIndexEnvironment; }
+
+namespace search::features::rankingexpression {
+
+/**
+ * Adapt a Blueprint with no inputs and a single output to the
+ * IntrinsicExpression interface.
+ **/
+struct IntrinsicBlueprintAdapter
+{
+ static IntrinsicExpression::UP try_create(const search::fef::Blueprint &proto,
+ const search::fef::IIndexEnvironment &env,
+ const std::vector<vespalib::string> &params);
+};
+
+} // namespace search::features::rankingexpression