aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/fef/test/plugin/cfgvalue.cpp
blob: 8047c7bfedca62d901f881efeae029651d82f495 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "cfgvalue.h"
#include <vespa/searchlib/fef/properties.h>
#include <vespa/vespalib/util/stash.h>
#include <sstream>

namespace search::fef::test {

CfgValueBlueprint::CfgValueBlueprint() :
    Blueprint("test_cfgvalue"),
    _values()
{
}

CfgValueBlueprint::~CfgValueBlueprint() = default;

void
CfgValueBlueprint::visitDumpFeatures(const IIndexEnvironment &indexEnv, IDumpFeatureVisitor &visitor) const
{
    Property p = indexEnv.getProperties().lookup(getBaseName(), "dump");
    for (uint32_t i = 0; i < p.size(); ++i) {
        visitor.visitDumpFeature(p.getAt(i));
    }
}

bool
CfgValueBlueprint::setup(const IIndexEnvironment &indexEnv, const StringVector &params)
{
    (void) params;
    Property p = indexEnv.getProperties().lookup(getName(), "value");
    for (uint32_t i = 0; i < p.size(); ++i) {
        std::istringstream iss(p.getAt(i));
        feature_t value;
        iss >> std::dec >> value;
        _values.push_back(value);

        if (iss.fail()) {
            return false;
        }

        std::ostringstream name;
        name << i;
        std::ostringstream desc;
        desc << "value " << i;
        describeOutput(name.str(), desc.str());
        // we have no inputs
    }
    return true;
}

FeatureExecutor &
CfgValueBlueprint::createExecutor(const IQueryEnvironment & queryEnv, vespalib::Stash &stash) const
{
    (void) queryEnv;
    return stash.create<search::features::ValueExecutor>(_values);
}

}