blob: f68c322dafd00424608b4a4dc2a830b221dd7b39 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "resultclass.h"
#include "docsum_field_writer.h"
#include <vespa/vespalib/stllike/hashtable.hpp>
namespace search::docsummary {
ResultClass::ResultClass(const char *name)
: _name(name),
_entries(),
_nameMap(),
_dynInfo(),
_omit_summary_features(false),
_num_field_writer_states(0)
{ }
ResultClass::~ResultClass() = default;
int
ResultClass::getIndexFromName(const char* name) const
{
auto found = _nameMap.find(name);
return (found != _nameMap.end()) ? found->second : -1;
}
bool
ResultClass::addConfigEntry(const char *name, std::unique_ptr<DocsumFieldWriter> docsum_field_writer)
{
if (_nameMap.find(name) != _nameMap.end()) {
return false;
}
_nameMap[name] = _entries.size();
ResConfigEntry e(name);
if (docsum_field_writer) {
docsum_field_writer->setIndex(_entries.size());
bool generated = docsum_field_writer->isGenerated();
_dynInfo.update_override_counts(generated);
if (docsum_field_writer->setFieldWriterStateIndex(_num_field_writer_states)) {
++_num_field_writer_states;
}
}
e.set_writer(std::move(docsum_field_writer));
_entries.push_back(std::move(e));
return true;
}
bool
ResultClass::addConfigEntry(const char *name)
{
return addConfigEntry(name, {});
}
bool
ResultClass::all_fields_generated(const vespalib::hash_set<vespalib::string>& fields) const
{
if (_dynInfo._generateCnt == getNumEntries()) {
return true;
}
if (fields.empty()) {
return false;
}
for (const auto& entry : _entries) {
if (fields.contains(entry.name()) && !entry.is_generated()) {
return false;
}
}
return true;
}
}
|