blob: 586e086cf9756db3800c774a74d8b82c28a58b8e (
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
85
86
87
88
89
90
91
92
93
94
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "item_raw_score_feature.h"
#include "valuefeature.h"
#include "utils.h"
#include <vespa/vespalib/util/stash.h>
using namespace search::fef;
namespace search::features {
void
ItemRawScoreExecutor::execute(uint32_t docId)
{
feature_t output = 0.0;
for (uint32_t i = 0; i < _handles.size(); ++i) {
const TermFieldMatchData *tfmd = _md->resolveTermField(_handles[i]);
if (tfmd->getDocId() == docId) {
output += tfmd->getRawScore();
}
}
outputs().set_number(0, output);
}
void
ItemRawScoreExecutor::handle_bind_match_data(const MatchData &md)
{
_md = &md;
}
//-----------------------------------------------------------------------------
void
SimpleItemRawScoreExecutor::execute(uint32_t docId)
{
feature_t output = 0.0;
const TermFieldMatchData *tfmd = _md->resolveTermField(_handle);
if (tfmd->getDocId() == docId) {
output = tfmd->getRawScore();
}
outputs().set_number(0, output);
}
void
SimpleItemRawScoreExecutor::handle_bind_match_data(const MatchData &md)
{
_md = &md;
}
//-----------------------------------------------------------------------------
ItemRawScoreBlueprint::~ItemRawScoreBlueprint() = default;
bool
ItemRawScoreBlueprint::setup(const IIndexEnvironment &,
const ParameterList ¶ms)
{
_label = params[0].getValue();
describeOutput("out", "raw score for the given query item");
return true;
}
FeatureExecutor &
ItemRawScoreBlueprint::createExecutor(const IQueryEnvironment &queryEnv, vespalib::Stash &stash) const
{
HandleVector handles = resolve(queryEnv, _label);
if (handles.size() == 1) {
return stash.create<SimpleItemRawScoreExecutor>(handles[0]);
} else if (handles.size() == 0) {
return stash.create<SingleZeroValueExecutor>();
} else {
return stash.create<ItemRawScoreExecutor>(handles);
}
}
ItemRawScoreBlueprint::HandleVector
ItemRawScoreBlueprint::resolve(const IQueryEnvironment &env,
const vespalib::string &label)
{
HandleVector handles;
const ITermData *term = util::getTermByLabel(env, label);
if (term != nullptr) {
uint32_t numFields(term->numFields());
for (uint32_t i(0); i < numFields; ++i) {
TermFieldHandle handle = term->field(i).getHandle();
if (handle != IllegalHandle) {
handles.push_back(handle);
}
}
}
return handles;
}
}
|