blob: b7f61c0b1eff73059c4267907a95115af08108bb (
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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "single_raw_ext_attribute.h"
#include <vespa/searchcommon/attribute/config.h>
#include <vespa/log/log.h>
LOG_SETUP(".searchlib.attribute.single_raw_ext_attribute");
namespace search::attribute {
SingleRawExtAttribute::SingleRawExtAttribute(const vespalib::string& name)
: RawAttribute(name, Config(BasicType::RAW, CollectionType::SINGLE)),
IExtendAttribute(),
_buffer(),
_offsets()
{
}
SingleRawExtAttribute::~SingleRawExtAttribute() = default;
void
SingleRawExtAttribute::onCommit()
{
LOG_ABORT("should not be reached");
}
void
SingleRawExtAttribute::onUpdateStat()
{
}
bool
SingleRawExtAttribute::addDoc(DocId& docId)
{
size_t offset(_buffer.size());
docId = _offsets.size();
_offsets.push_back(offset);
incNumDocs();
setCommittedDocIdLimit(getNumDocs());
return true;
}
bool
SingleRawExtAttribute::add(vespalib::ConstArrayRef<char> v, int32_t)
{
const size_t start(_offsets.back());
const size_t sz(v.size());
_buffer.resize(start + sz);
memcpy(&_buffer[start], v.data(), sz);
return true;
}
vespalib::ConstArrayRef<char>
SingleRawExtAttribute::get_raw(DocId docid) const
{
if (docid >= _offsets.size()) {
return {};
}
auto offset = _offsets[docid];
auto size = ((docid + 1 >= _offsets.size()) ? _buffer.size() : _offsets[docid + 1]) - offset;
if (size == 0) {
return {};
}
return {_buffer.data() + offset, size};
}
IExtendAttribute*
SingleRawExtAttribute::getExtendInterface()
{
return this;
}
}
|