blob: 44ac62eee05195f4975568f1507372c27f7564e6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Copyright Vespa.ai. 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
|