aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
blob: bd018df52737899a23163dbcefeea5016d33109e (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
74
75
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "readable_attribute_vector.h"
#include <vespa/searchcommon/attribute/i_document_meta_store_context.h>
#include <vespa/vespalib/stllike/string.h>

namespace search::attribute {

class BitVectorSearchCache;
class ReadableAttributeVector;
class ReferenceAttribute;

/**
 * Attribute vector which does not store values of its own, but rather serves as a
 * convenient indirection wrapper towards a target vector, usually in another
 * document type altogether. Imported attributes are meant to be used in conjunction
 * with a reference attribute, which specifies a dynamic mapping from a local LID to
 * a target LID (via an intermediate GID).
 *
 * Any accessor on the imported attribute for a local LID yields the same result as
 * if the same accessor were invoked with the target LID on the target attribute vector.
 */
class ImportedAttributeVector : public ReadableAttributeVector {
public:
    using SP = std::shared_ptr<ImportedAttributeVector>;
    using MetaStoreReadGuard = search::IDocumentMetaStoreContext::IReadGuard;
    ImportedAttributeVector(vespalib::stringref name,
                            std::shared_ptr<ReferenceAttribute> reference_attribute,
                            std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
                            std::shared_ptr<ReadableAttributeVector> target_attribute,
                            std::shared_ptr<const IDocumentMetaStoreContext> target_document_meta_store,
                            bool use_search_cache);
    ImportedAttributeVector(vespalib::stringref name,
                            std::shared_ptr<ReferenceAttribute> reference_attribute,
                            std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
                            std::shared_ptr<ReadableAttributeVector> target_attribute,
                            std::shared_ptr<const IDocumentMetaStoreContext> target_document_meta_store,
                            std::shared_ptr<BitVectorSearchCache> search_cache);
    ~ImportedAttributeVector() override;

    const std::shared_ptr<ReferenceAttribute>& getReferenceAttribute() const noexcept {
        return _reference_attribute;
    }
    const std::shared_ptr<IDocumentMetaStoreContext> &getDocumentMetaStore() const {
        return _document_meta_store;
    }
    const std::shared_ptr<ReadableAttributeVector>& getTargetAttribute() const noexcept {
        return _target_attribute;
    }
    const std::shared_ptr<const IDocumentMetaStoreContext> &getTargetDocumentMetaStore() const {
        return _target_document_meta_store;
    }
    const std::shared_ptr<BitVectorSearchCache> &getSearchCache() const {
        return _search_cache;
    }
    void clearSearchCache();
    const vespalib::string &getName() const {
        return _name;
    }

    std::unique_ptr<AttributeReadGuard> makeReadGuard(bool stableEnumGuard) const override;
    virtual std::unique_ptr<AttributeReadGuard> makeReadGuard(std::shared_ptr<MetaStoreReadGuard> targetMetaStoreReadGuard, bool stableEnumGuard) const;

protected:
    vespalib::string                           _name;
    std::shared_ptr<ReferenceAttribute>        _reference_attribute;
    std::shared_ptr<IDocumentMetaStoreContext> _document_meta_store;
    std::shared_ptr<ReadableAttributeVector>   _target_attribute;
    std::shared_ptr<const IDocumentMetaStoreContext> _target_document_meta_store;
    std::shared_ptr<BitVectorSearchCache>      _search_cache;
};

}