blob: e23cb20ef37a18a79e5ddab3a2568e3babc68028 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "summaryfeaturesdfw.h"
#include "docsumstate.h"
#include <vespa/vespalib/data/slime/cursor.h>
#include <vespa/vespalib/data/slime/inserter.h>
using vespalib::FeatureSet;
namespace search::docsummary {
SummaryFeaturesDFW::SummaryFeaturesDFW() = default;
SummaryFeaturesDFW::~SummaryFeaturesDFW() = default;
static vespalib::Memory _M_cached("vespa.summaryFeatures.cached");
void
SummaryFeaturesDFW::insertField(uint32_t docid, GetDocsumsState& state, vespalib::slime::Inserter &target) const
{
if (state._omit_summary_features) {
return;
}
if ( ! state._summaryFeatures) {
state._callback.fillSummaryFeatures(state);
if ( !state._summaryFeatures) { // still no summary features to write
return;
}
}
const FeatureSet::StringVector &names = state._summaryFeatures->getNames();
const FeatureSet::Value *values = state._summaryFeatures->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());
}
}
obj.setDouble(_M_cached, 0.0); // TODO Remove, has not been cached for many years
}
}
|