aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/persistenceengine/i_document_retriever.h
blob: 7b15a19288c4d29fd7085f0985ab7a58e12cc8d0 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/persistence/spi/types.h>
#include <vespa/persistence/spi/bucket.h>
#include <vespa/persistence/spi/read_consistency.h>
#include <vespa/searchlib/common/idocumentmetastore.h>
#include <vespa/searchlib/docstore/idocumentstore.h>
#include <vespa/searchcore/proton/common/cachedselect.h>
#include <vespa/searchcore/proton/documentmetastore/i_document_meta_store_context.h>

namespace document { class FieldSet; }

namespace proton {

/**
 * This is an interface that allows retrieval of documents by local id and document metadata
 * by either bucket or document id.
 * It also provides a callback interface known in VDS as visitation.
 **/ 
class IDocumentRetriever
{
public:
    using ReadConsistency = storage::spi::ReadConsistency;
    using ReadGuard = IDocumentMetaStoreContext::IReadGuard::SP;
    using UP = std::unique_ptr<IDocumentRetriever>;
    using SP = std::shared_ptr<IDocumentRetriever>;

    using LidVector = search::IDocumentStore::LidVector;
    using DocumentUP = std::unique_ptr<document::Document>;

    virtual ~IDocumentRetriever() = default;

    virtual const document::DocumentTypeRepo & getDocumentTypeRepo() const = 0;
    virtual void getBucketMetaData(const storage::spi::Bucket &bucket, search::DocumentMetaData::Vector &result) const = 0;
    virtual search::DocumentMetaData getDocumentMetaData(const document::DocumentId &id) const = 0;
    /**
     * Extracts the full document based on the LID
     */
    virtual DocumentUP getFullDocument(search::DocumentIdT lid) const = 0;
    /**
     * Fetches the necessary set of fields, allowing for more optimal fetch when combining only from attributes.
     */
    virtual DocumentUP getPartialDocument(search::DocumentIdT lid, const document::DocumentId & docId, const document::FieldSet & fieldSet) const;
    virtual ReadGuard getReadGuard() const = 0;
    virtual uint32_t getDocIdLimit() const = 0;
    /**
     * Will visit all documents in the the given list. Visit order is undefined and will
     * be conducted in most efficient retrieval order.
     * @param lids to visit
     * @param Visitor to receive callback for each document found.
     */
    virtual void visitDocuments(const LidVector &lids, search::IDocumentVisitor &visitor, ReadConsistency readConsistency) const = 0;

    virtual CachedSelect::SP parseSelect(const vespalib::string &selection) const = 0;

    // Convenience to get all fields
    DocumentUP getDocument(search::DocumentIdT lid, const document::DocumentId & docId) const;
};

class DocumentRetrieverBaseForTest : public IDocumentRetriever {
public:
    void visitDocuments(const LidVector &lids, search::IDocumentVisitor &visitor, ReadConsistency readConsistency) const override;
    ReadGuard getReadGuard() const override { return ReadGuard(); }
    uint32_t getDocIdLimit() const override { return std::numeric_limits<uint32_t>::max(); }
};

} // namespace proton