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

#include <vespa/document/fieldvalue/document.h>
#include <vespa/persistence/spi/types.h>
#include <vespa/searchlib/query/base.h>

namespace proton::test {

/**
 * Representation of a test document.
 */
class Document
{
private:
    document::Document::SP  _doc;
    search::DocumentIdT     _lid;
    storage::spi::Timestamp _tstamp;
    uint32_t                _numUsedBits;
public:
    Document(document::Document::SP doc,
             search::DocumentIdT lid,
             storage::spi::Timestamp tstamp,
             uint32_t numUsedBits = 8u)
        : _doc(doc),
          _lid(lid),
          _tstamp(tstamp),
          _numUsedBits(numUsedBits)
    {
    }
    const document::Document::SP &getDoc() const { return _doc; }
    const document::DocumentId &getDocId() const { return _doc->getId(); }
    const document::GlobalId &getGid() const { return getDocId().getGlobalId(); }
    document::BucketId getBucket() const {
        document::BucketId retval = getGid().convertToBucketId();
        retval.setUsedBits(_numUsedBits);
        return retval;
    }
    search::DocumentIdT getLid() const { return _lid; }
    storage::spi::Timestamp getTimestamp() const { return _tstamp; }
    uint32_t getDocSize() const { return 1000; }
};

using DocumentVector = std::vector<Document>;

struct DocumentGidOrderCmp
{
    bool operator()(const Document &lhs, const Document &rhs) const {
        document::GlobalId::BucketOrderCmp cmp;
        return cmp(lhs.getGid(), rhs.getGid());
    }
};


}