blob: d630c7fc8c4d93083a626149cf95790fdab99b7d (
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "agefeature.h"
#include "valuefeature.h"
#include <vespa/searchlib/fef/featurenamebuilder.h>
#include <vespa/searchlib/fef/matchdata.h>
#include <vespa/vespalib/util/stash.h>
using search::attribute::IAttributeVector;
namespace search {
using FNB = fef::FeatureNameBuilder;
namespace features {
AgeExecutor::AgeExecutor(const IAttributeVector *attribute) :
search::fef::FeatureExecutor(),
_attribute(attribute),
_buf()
{
if (_attribute != nullptr) {
_buf.allocate(attribute->getMaxValueCount());
}
}
AgeBlueprint::~AgeBlueprint() = default;
void
AgeExecutor::execute(uint32_t docId)
{
feature_t age = 10000000000.0;
if (_attribute != nullptr) {
_buf.fill(*_attribute, docId);
int64_t docTime = _buf[0];
feature_t currTime = inputs().get_number(0);
age = currTime - docTime;
if (age < 0) {
age = 0;
}
}
outputs().set_number(0, age);
}
void
AgeBlueprint::visitDumpFeatures(const search::fef::IIndexEnvironment &,
search::fef::IDumpFeatureVisitor &) const
{
// empty
}
bool
AgeBlueprint::setup(const search::fef::IIndexEnvironment&,
const search::fef::ParameterList ¶ms)
{
_attribute = params[0].getValue();
defineInput("now");
describeOutput("out", "The age of the document, in seconds.");
return true;
}
search::fef::Blueprint::UP
AgeBlueprint::createInstance() const
{
return std::make_unique<AgeBlueprint>();
}
search::fef::FeatureExecutor &
AgeBlueprint::createExecutor(const search::fef::IQueryEnvironment &env, vespalib::Stash &stash) const
{
// Get docdate attribute vector
const IAttributeVector * attribute = env.getAttributeContext().getAttribute(_attribute);
return stash.create<AgeExecutor>(attribute);
}
fef::ParameterDescriptions
AgeBlueprint::getDescriptions() const
{
return fef::ParameterDescriptions().desc().attribute(fef::ParameterDataTypeSet::normalTypeSet(), fef::ParameterCollection::ANY);
}
}
}
|