aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/attribute/document_field_populator.cpp
blob: 00ece636510641136671df7bce0f928cee0308b3 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "document_field_populator.h"
#include "document_field_retriever.h"
#include <vespa/searchcore/proton/common/eventlogger.h>
#include <vespa/searchlib/attribute/attributevector.h>
#include <vespa/log/log.h>
LOG_SETUP(".proton.attribute.document_field_populator");

using document::Document;
using search::AttributeGuard;

namespace proton {

namespace {

vespalib::string
getFieldName(const vespalib::string &subDbName,
             const vespalib::string &fieldName)
{
    return subDbName + ".documentfield." + fieldName;
}

}

DocumentFieldPopulator::DocumentFieldPopulator(const vespalib::string &fieldName,
                                               AttributeVectorSP attr,
                                               const vespalib::string &subDbName)
    : _fieldName(fieldName),
      _attr(attr),
      _subDbName(subDbName),
      _documentsPopulated(0)
{
    if (LOG_WOULD_LOG(event)) {
        EventLogger::populateDocumentFieldStart(getFieldName(subDbName, fieldName));
    }
}

DocumentFieldPopulator::~DocumentFieldPopulator()
{
    if (LOG_WOULD_LOG(event)) {
        EventLogger::populateDocumentFieldComplete(getFieldName(_subDbName, _fieldName),
                _documentsPopulated);
    }
}

void
DocumentFieldPopulator::handleExisting(uint32_t lid, const std::shared_ptr<Document> &doc)
{
    DocumentFieldRetriever::populate(lid, *doc, doc->getField(_fieldName), *_attr);
    ++_documentsPopulated;
}

} // namespace proton