diff options
author | Haavard <havardpe@yahoo-inc.com> | 2017-08-11 14:21:43 +0000 |
---|---|---|
committer | Haavard <havardpe@yahoo-inc.com> | 2017-08-14 10:21:43 +0000 |
commit | 892b13d604ea569695fd41ed89d6f0c2d91dee43 (patch) | |
tree | 6ac4f6320d9e71274958f8335c5a7c4471bfc2b6 /searchlib | |
parent | af45432e1bac450a771e7e7726e539f1e3d13ac5 (diff) |
basic concepts used to replace ranking expressions with intrinsic operations
Diffstat (limited to 'searchlib')
5 files changed, 149 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/features/rankingexpression/CMakeLists.txt b/searchlib/src/vespa/searchlib/features/rankingexpression/CMakeLists.txt index deb33fead55..3ca8c36398c 100644 --- a/searchlib/src/vespa/searchlib/features/rankingexpression/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/features/rankingexpression/CMakeLists.txt @@ -1,6 +1,8 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. vespa_add_library(searchlib_features_rankingexpression OBJECT SOURCES + expression_replacer.cpp feature_name_extractor.cpp + intrinsic_expression.cpp DEPENDS ) diff --git a/searchlib/src/vespa/searchlib/features/rankingexpression/expression_replacer.cpp b/searchlib/src/vespa/searchlib/features/rankingexpression/expression_replacer.cpp new file mode 100644 index 00000000000..7de5503582a --- /dev/null +++ b/searchlib/src/vespa/searchlib/features/rankingexpression/expression_replacer.cpp @@ -0,0 +1,50 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "expression_replacer.h" + +namespace search::features::rankingexpression { + +ExpressionReplacer::~ExpressionReplacer() +{ +} + +//----------------------------------------------------------------------------- + +IntrinsicExpression::UP +NullExpressionReplacer::maybe_replace(const vespalib::eval::Function &, + const search::fef::IIndexEnvironment &) const +{ + return IntrinsicExpression::UP(nullptr); +} + +NullExpressionReplacer::~NullExpressionReplacer() +{ +} + +//----------------------------------------------------------------------------- + +ListExpressionReplacer::ListExpressionReplacer() = default; + +void +ListExpressionReplacer::add(ExpressionReplacer::UP replacer) +{ + _list.push_back(std::move(replacer)); +} + +IntrinsicExpression::UP +ListExpressionReplacer::maybe_replace(const vespalib::eval::Function &function, + const search::fef::IIndexEnvironment &env) const +{ + for (const auto &item: _list) { + if (auto result = item.get()->maybe_replace(function, env)) { + return result; + } + } + return IntrinsicExpression::UP(nullptr); +} + +ListExpressionReplacer::~ListExpressionReplacer() +{ +} + +} // namespace search::features::rankingexpression diff --git a/searchlib/src/vespa/searchlib/features/rankingexpression/expression_replacer.h b/searchlib/src/vespa/searchlib/features/rankingexpression/expression_replacer.h new file mode 100644 index 00000000000..2a2d9f24439 --- /dev/null +++ b/searchlib/src/vespa/searchlib/features/rankingexpression/expression_replacer.h @@ -0,0 +1,54 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <memory> +#include <vector> +#include "intrinsic_expression.h" + +namespace vespalib::eval { class Function; } +namespace search::fef { class IIndexEnvironment; } + +namespace search::features::rankingexpression { + +/** + * Interface used to replace the calculation of a ranking expression + * (including calculating all its inputs) with a single intrinsic + * operation directly producing the final result without exposing + * intermediate results. + **/ +struct ExpressionReplacer { + using UP = std::unique_ptr<ExpressionReplacer>; + using SP = std::shared_ptr<ExpressionReplacer>; + virtual IntrinsicExpression::UP maybe_replace(const vespalib::eval::Function &function, + const search::fef::IIndexEnvironment &env) const = 0; + virtual ~ExpressionReplacer(); +}; + +/** + * Expression Replacer never replacing anything. + **/ +struct NullExpressionReplacer : public ExpressionReplacer { + IntrinsicExpression::UP maybe_replace(const vespalib::eval::Function &function, + const search::fef::IIndexEnvironment &env) const override; + ~NullExpressionReplacer(); +}; + +/** + * Expression Replacer that keeps a list of expression replacers and + * forwards the replace calls to each of them in order until the + * expression has been replaced or all of them have been tried. + **/ +class ListExpressionReplacer : public ExpressionReplacer +{ +private: + std::vector<ExpressionReplacer::UP> _list; +public: + ListExpressionReplacer(); + void add(ExpressionReplacer::UP replacer); + IntrinsicExpression::UP maybe_replace(const vespalib::eval::Function &function, + const search::fef::IIndexEnvironment &env) const override; + ~ListExpressionReplacer(); +}; + +} // namespace search::features::rankingexpression diff --git a/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_expression.cpp b/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_expression.cpp new file mode 100644 index 00000000000..cceefa58104 --- /dev/null +++ b/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_expression.cpp @@ -0,0 +1,11 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "intrinsic_expression.h" + +namespace search::features::rankingexpression { + +IntrinsicExpression::~IntrinsicExpression() +{ +} + +} // namespace search::features::rankingexpression diff --git a/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_expression.h b/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_expression.h new file mode 100644 index 00000000000..3180b828c79 --- /dev/null +++ b/searchlib/src/vespa/searchlib/features/rankingexpression/intrinsic_expression.h @@ -0,0 +1,32 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <memory> + +namespace vespalib { class Stash; } + +namespace search::fef { +class FeatureType; +class FeatureExecutor; +class IQueryEnvironment; +} + +namespace search::features::rankingexpression { + +/** + * Interface representing an intrinsic expression replacing the + * calculation of a ranking expression and its inputs. + **/ +struct IntrinsicExpression { + using FeatureType = search::fef::FeatureType; + using FeatureExecutor = search::fef::FeatureExecutor; + using QueryEnv = search::fef::IQueryEnvironment; + using UP = std::unique_ptr<IntrinsicExpression>; + virtual FeatureType result_type() const = 0; + virtual FeatureExecutor &create_executor(const QueryEnv &queryEnv, + vespalib::Stash &stash) const = 0; + virtual ~IntrinsicExpression(); +}; + +} // namespace search::features::rankingexpression |