aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/diskindex/zcposocc.cpp
blob: 2dc49130efb26224cd4d9123c5b1225a53a81033 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "zcposocc.h"
#include <vespa/searchlib/index/postinglistcounts.h>
#include <vespa/searchlib/index/postinglistcountfile.h>
#include <vespa/searchlib/index/postinglistparams.h>

namespace search::diskindex {

using search::bitcompression::PosOccFieldsParams;
using search::bitcompression::EG2PosOccDecodeContext;
using search::bitcompression::EGPosOccDecodeContext;
using search::index::FieldLengthInfo;
using search::index::PostingListCountFileSeqRead;
using search::index::PostingListCountFileSeqWrite;

Zc4PosOccSeqRead::Zc4PosOccSeqRead(PostingListCountFileSeqRead *countFile)
    : Zc4PostingSeqRead(countFile, false),
      _fieldsParams(),
      _cookedDecodeContext(&_fieldsParams),
      _rawDecodeContext(&_fieldsParams)
{
    _reader.set_decode_features(&_cookedDecodeContext);
}


void
Zc4PosOccSeqRead::
setFeatureParams(const PostingListParams &params)
{
    bool oldCooked = &_reader.get_decode_features() == &_cookedDecodeContext;
    bool newCooked = oldCooked;
    params.get("cooked", newCooked);
    if (oldCooked != newCooked) {
        if (newCooked) {
            _cookedDecodeContext = _rawDecodeContext;
            _reader.set_decode_features(&_cookedDecodeContext);
        } else {
            _rawDecodeContext = _cookedDecodeContext;
            _reader.set_decode_features(&_rawDecodeContext);
        }
    }
}


const vespalib::string &
Zc4PosOccSeqRead::getSubIdentifier()
{
    PosOccFieldsParams fieldsParams;
    EG2PosOccDecodeContext<true> d(&fieldsParams);
    return d.getIdentifier();
}

const FieldLengthInfo &
Zc4PosOccSeqRead::get_field_length_info() const
{
    return _fieldsParams.getFieldParams()->get_field_length_info();
}

Zc4PosOccSeqWrite::Zc4PosOccSeqWrite(const Schema &schema,
                                     uint32_t indexId,
                                     const FieldLengthInfo &field_length_info,
                                     PostingListCountFileSeqWrite *countFile)
    : Zc4PostingSeqWrite(countFile),
      _fieldsParams(),
      _realEncodeFeatures(&_fieldsParams)
{
    _writer.set_encode_features(&_realEncodeFeatures);
    _fieldsParams.setSchemaParams(schema, indexId);
    _fieldsParams.set_field_length_info(field_length_info);
}


ZcPosOccSeqRead::ZcPosOccSeqRead(PostingListCountFileSeqRead *countFile)
    : Zc4PostingSeqRead(countFile, true),
      _fieldsParams(),
      _cookedDecodeContext(&_fieldsParams),
      _rawDecodeContext(&_fieldsParams)
{
    _reader.set_decode_features(&_cookedDecodeContext);
}


void
ZcPosOccSeqRead::
setFeatureParams(const PostingListParams &params)
{
    bool oldCooked = &_reader.get_decode_features() == &_cookedDecodeContext;
    bool newCooked = oldCooked;
    params.get("cooked", newCooked);
    if (oldCooked != newCooked) {
        if (newCooked) {
            _cookedDecodeContext = _rawDecodeContext;
            _reader.set_decode_features(&_cookedDecodeContext);
        } else {
            _rawDecodeContext = _cookedDecodeContext;
            _reader.set_decode_features(&_rawDecodeContext);
        }
    }
}


const vespalib::string &
ZcPosOccSeqRead::getSubIdentifier()
{
    PosOccFieldsParams fieldsParams;
    EGPosOccDecodeContext<true> d(&fieldsParams);
    return d.getIdentifier();
}

const FieldLengthInfo &
ZcPosOccSeqRead::get_field_length_info() const
{
    return _fieldsParams.getFieldParams()->get_field_length_info();
}

ZcPosOccSeqWrite::ZcPosOccSeqWrite(const Schema &schema,
                                   uint32_t indexId,
                                   const FieldLengthInfo &field_length_info,
                                   PostingListCountFileSeqWrite *countFile)
    : ZcPostingSeqWrite(countFile),
      _fieldsParams(),
      _realEncodeFeatures(&_fieldsParams)
{
    _writer.set_encode_features(&_realEncodeFeatures);
    _fieldsParams.setSchemaParams(schema, indexId);
    _fieldsParams.set_field_length_info(field_length_info);
}

}