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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "mock_attribute_manager.h"
#include <vespa/searchlib/attribute/attributefactory.h>
#include <vespa/searchlib/attribute/floatbase.h>
#include <vespa/searchlib/attribute/integerbase.h>
#include <vespa/searchlib/attribute/stringbase.h>
#include <vespa/searchlib/attribute/single_raw_attribute.h>
#include <vespa/searchcommon/attribute/config.h>
#include <cassert>
using search::attribute::BasicType;
using search::attribute::CollectionType;
using search::attribute::Config;
using search::attribute::SingleRawAttribute;
namespace search::docsummary::test {
template <typename AttributeType, typename ValueType>
void
MockAttributeManager::build_attribute(const vespalib::string& name, BasicType type,
CollectionType col_type,
const std::vector<std::vector<ValueType>>& values)
{
Config cfg(type, col_type);
auto attr_base = AttributeFactory::createAttribute(name, cfg);
assert(attr_base);
auto attr = std::dynamic_pointer_cast<AttributeType>(attr_base);
assert(attr);
attr->addReservedDoc();
for (const auto& docValues : values) {
uint32_t docId = 0;
attr->addDoc(docId);
attr->clearDoc(docId);
if (attr->hasMultiValue()) {
for (const auto& value : docValues) {
attr->append(docId, value, 1);
}
} else if (!docValues.empty()) {
assert(docValues.size() == 1);
attr->update(docId, docValues[0]);
}
attr->commit();
}
_mgr.add(attr);
}
MockAttributeManager::MockAttributeManager()
: _mgr()
{
}
MockAttributeManager::~MockAttributeManager() = default;
void
MockAttributeManager::build_string_attribute(const vespalib::string& name,
const std::vector<std::vector<vespalib::string>>& values,
CollectionType col_type)
{
build_attribute<StringAttribute, vespalib::string>(name, BasicType::Type::STRING, col_type, values);
}
void
MockAttributeManager::build_float_attribute(const vespalib::string& name,
const std::vector<std::vector<double>>& values,
CollectionType col_type)
{
build_attribute<FloatingPointAttribute, double>(name, BasicType::Type::DOUBLE, col_type, values);
}
void
MockAttributeManager::build_int_attribute(const vespalib::string& name, BasicType type,
const std::vector<std::vector<int64_t>>& values,
CollectionType col_type)
{
build_attribute<IntegerAttribute, int64_t>(name, type, col_type, values);
}
void
MockAttributeManager::build_raw_attribute(const vespalib::string& name,
const std::vector<std::vector<std::vector<char>>>& values)
{
build_attribute<SingleRawAttribute, std::vector<char>>(name, BasicType::Type::RAW, CollectionType::SINGLE, values);
}
}
|