aboutsummaryrefslogtreecommitdiffstats
path: root/streamingvisitors/src/vespa/vsm/common/documenttypemapping.h
blob: 0ee641135b0c18d6ec03a7d3c7cc6ced7fa033da (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 Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/vsm/common/storagedocument.h>

namespace document { class DocumentTypeRepo; }

namespace vsm
{

class DocumentTypeMapping
{
public:
    DocumentTypeMapping();
    ~DocumentTypeMapping();

    /**
     * Prepares the given document by sharing the field info map
     * registered for that document type.
     **/
    bool prepareBaseDoc(SharedFieldPathMap & doc) const;

    /**
     * Builds a field info map for all registered document types.
     **/
    void init(const vespalib::string & defaultDocumentType,
              const StringFieldIdTMapT & fieldList,
              const document::DocumentTypeRepo &repo);

    const document::DocumentType & getCurrentDocumentType() const;
    const vespalib::string & getDefaultDocumentTypeName() const
    { return _defaultDocumentTypeName; }
    const document::DocumentType *getDefaultDocumentType() const
    { return _defaultDocumentType; }

private:
    /**
     * Builds a field info map for the given type id. This is a
     * mapping from field id to field path and field value for all
     * field names in the given list based on the given document type.
     **/
    void buildFieldMap(const document::DocumentType *docType,
                       const StringFieldIdTMapT & fieldList,
                       const vespalib::string & typeId);
    using FieldPathMapMapT = vespalib::hash_map<vespalib::string, FieldPathMapT>;
    using DocumentTypeUsage = std::multimap<size_t, const document::DocumentType *>;
    FieldPathMapMapT        _fieldMap;
    vespalib::string        _defaultDocumentTypeName;
    const document::DocumentType *_defaultDocumentType;
    DocumentTypeUsage       _documentTypeFreq;
};

}