aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/fef/test/plugin/staticrank.cpp
blob: 9299af90d52107c31e3ffee0bfa5325b3489afe0 (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.

#include "staticrank.h"
#include <vespa/searchcommon/attribute/attributecontent.h>
#include <vespa/vespalib/util/stash.h>

namespace search::fef::test {

StaticRankExecutor::StaticRankExecutor(const search::attribute::IAttributeVector * attribute) :
    FeatureExecutor(),
    _attribute(attribute)
{
}

void
StaticRankExecutor::execute(uint32_t docId)
{
    search::attribute::FloatContent staticRank;
    if (_attribute != nullptr) {
        staticRank.allocate(_attribute->getMaxValueCount());
        staticRank.fill(*_attribute, docId);
    }
    outputs().set_number(0, static_cast<feature_t>(staticRank[0]));
}


StaticRankBlueprint::StaticRankBlueprint() :
    Blueprint("staticrank"),
    _attributeName()
{
}

StaticRankBlueprint::~StaticRankBlueprint() = default;

bool
StaticRankBlueprint::setup(const IIndexEnvironment & indexEnv, const StringVector & params)
{
    (void) indexEnv;
    if (params.size() != 1) {
        return false;
    }
    _attributeName = params[0];
    describeOutput("out", "static rank");
    return true;
}

FeatureExecutor &
StaticRankBlueprint::createExecutor(const IQueryEnvironment & queryEnv, vespalib::Stash &stash) const
{
    const search::attribute::IAttributeVector * av = queryEnv.getAttributeContext().getAttribute(_attributeName);
    return stash.create<StaticRankExecutor>(av);
}

}