aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/diskindex/zcposting.h
blob: c0132db83b516240c16fb4ca307f767dc9d50b9f (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "zc4_posting_writer.h"
#include "zc4_posting_reader.h"
#include <vespa/searchlib/index/postinglistfile.h>
#include <vespa/fastos/file.h>
#include "zc4_posting_params.h"

namespace search::index {
    class PostingListCountFileSeqRead;
    class PostingListCountFileSeqWrite;
}

namespace search::diskindex {

class Zc4PostingSeqRead : public index::PostingListFileSeqRead
{
    Zc4PostingSeqRead(const Zc4PostingSeqRead &);
    Zc4PostingSeqRead &operator=(const Zc4PostingSeqRead &);

protected:
    Zc4PostingReader<true> _reader;
    FastOS_File _file;
    uint64_t _numWords;     // Number of words in file
    uint64_t _fileBitSize;
    index::PostingListCountFileSeqRead *const _countFile;
    uint64_t _headerBitLen;       // Size of file header in bits
public:
    Zc4PostingSeqRead(index::PostingListCountFileSeqRead *countFile, bool dynamic_k);

    ~Zc4PostingSeqRead();

    using DocIdAndFeatures = index::DocIdAndFeatures;
    using PostingListCounts = index::PostingListCounts;
    using PostingListParams = index::PostingListParams;

    void readDocIdAndFeatures(DocIdAndFeatures &features) override;
    void readCounts(const PostingListCounts &counts) override; // Fill in for next word
    bool open(const vespalib::string &name, const TuneFileSeqRead &tuneFileRead) override;
    bool close() override;
    void getParams(PostingListParams &params) override;
    void getFeatureParams(PostingListParams &params) override;
    void readHeader();
    static const vespalib::string &getIdentifier(bool dynamic_k);
};


class Zc4PostingSeqWrite : public index::PostingListFileSeqWrite
{
    Zc4PostingSeqWrite(const Zc4PostingSeqWrite &);
    Zc4PostingSeqWrite &operator=(const Zc4PostingSeqWrite &);

protected:
    using EncodeContext = bitcompression::FeatureEncodeContextBE;

    Zc4PostingWriter<true> _writer;
    FastOS_File      _file;
    uint64_t _fileBitSize;
    index::PostingListCountFileSeqWrite *const _countFile;
    /**
     * Make header using feature encode write context.
     */
    void makeHeader(const search::common::FileHeaderContext &fileHeaderContext);
    bool updateHeader();
public:
    Zc4PostingSeqWrite(index::PostingListCountFileSeqWrite *countFile);
    ~Zc4PostingSeqWrite();

    using DocIdAndFeatures = index::DocIdAndFeatures;
    using PostingListCounts = index::PostingListCounts;
    using PostingListParams = index::PostingListParams;

    void writeDocIdAndFeatures(const DocIdAndFeatures &features) override;
    void flushWord() override;

    bool open(const vespalib::string &name,
              const TuneFileSeqWrite &tuneFileWrite,
              const search::common::FileHeaderContext &fileHeaderContext) override;

    bool close() override;
    void setParams(const PostingListParams &params) override;
    void getParams(PostingListParams &params) override;
    void setFeatureParams(const PostingListParams &params) override;
    void getFeatureParams(PostingListParams &params) override;
};

class ZcPostingSeqWrite : public Zc4PostingSeqWrite
{
public:
    ZcPostingSeqWrite(index::PostingListCountFileSeqWrite *countFile);
};

}