blob: c4ca460b572d8a9c01bc7ba4e76064b3fdd1b849 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "rankfeaturesdfw.h"
#include "docsumstate.h"
#include <vespa/vespalib/data/slime/cursor.h>
#include <vespa/vespalib/data/slime/inserter.h>
using vespalib::FeatureSet;
namespace search::docsummary {
RankFeaturesDFW::RankFeaturesDFW() = default;
RankFeaturesDFW::~RankFeaturesDFW() = default;
void
RankFeaturesDFW::insertField(uint32_t docid, GetDocsumsState& state,
vespalib::slime::Inserter &target) const
{
if ( !state._rankFeatures ) {
state._callback.fillRankFeatures(state);
if (state._rankFeatures.get() == nullptr) { // still no rank features to write
return;
}
}
const FeatureSet::StringVector & names = state._rankFeatures->getNames();
const FeatureSet::Value * values = state._rankFeatures->getFeaturesByDocId(docid);
if (values == nullptr) { return; }
vespalib::slime::Cursor& obj = target.insertObject();
for (uint32_t i = 0; i < names.size(); ++i) {
vespalib::Memory name(names[i].c_str(), names[i].size());
if (values[i].is_data()) {
obj.setData(name, values[i].as_data());
} else {
obj.setDouble(name, values[i].as_double());
}
}
}
}
|