aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/fef/test/test_features.h
blob: 5aa8ed514c2ef46f7fac9673720d5b1884af79fb (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
55
56
57
58
59
60
61
62
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchlib/fef/blueprint.h>
#include <vespa/searchlib/fef/featureexecutor.h>

namespace search {
namespace fef {
namespace test {

//-----------------------------------------------------------------------------

// "ivalue(5)" calculates non-const 5.0
struct ImpureValueBlueprint : Blueprint {
    double value;
    ImpureValueBlueprint() : Blueprint("ivalue"), value(31212.0) {}
    void visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const override {}
    Blueprint::UP createInstance() const override { return Blueprint::UP(new ImpureValueBlueprint()); }
    bool setup(const IIndexEnvironment &, const std::vector<vespalib::string> &params) override;
    FeatureExecutor &createExecutor(const IQueryEnvironment &, vespalib::Stash &stash) const override;
};

//-----------------------------------------------------------------------------

// "docid" calculates local document id
struct DocidBlueprint : Blueprint {
    DocidBlueprint() : Blueprint("docid") {}
    void visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const override {}
    Blueprint::UP createInstance() const override { return Blueprint::UP(new DocidBlueprint()); }
    bool setup(const IIndexEnvironment &, const std::vector<vespalib::string> &) override;
    FeatureExecutor &createExecutor(const IQueryEnvironment &, vespalib::Stash &stash) const override;
};

//-----------------------------------------------------------------------------

// "box(ivalue(5))" calculates DoubleValue(5)
struct BoxingBlueprint : Blueprint {
    BoxingBlueprint() : Blueprint("box") {}
    void visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const override {}
    Blueprint::UP createInstance() const override { return Blueprint::UP(new BoxingBlueprint()); }
    bool setup(const IIndexEnvironment &, const std::vector<vespalib::string> &params) override;
    FeatureExecutor &createExecutor(const IQueryEnvironment &, vespalib::Stash &stash) const override;
};

//-----------------------------------------------------------------------------

// "track(docid)" calculates docid and counts execution as a side-effect
struct TrackingBlueprint : Blueprint {
    size_t &ext_cnt;
    TrackingBlueprint(size_t &ext_cnt_in) : Blueprint("track"), ext_cnt(ext_cnt_in) {}
    void visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const override {}
    Blueprint::UP createInstance() const override { return Blueprint::UP(new TrackingBlueprint(ext_cnt)); }
    bool setup(const IIndexEnvironment &, const std::vector<vespalib::string> &params) override;
    FeatureExecutor &createExecutor(const IQueryEnvironment &, vespalib::Stash &stash) const override;
};

//-----------------------------------------------------------------------------

} // namespace test
} // namespace fef
} // namespace search