-
Notifications
You must be signed in to change notification settings - Fork 20
/
segment_index_source.h
86 lines (70 loc) · 2.86 KB
/
segment_index_source.h
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
#pragma once
#include "index_source.h"
#include "terms.h"
#include "docidupdates.h"
namespace Trinity {
// You can use SegmentIndexSession to create a new segment
// This is a utility class
class SegmentIndexSource final
: public IndexSource {
private:
field_statistics defaultFieldStats;
std::unique_ptr<Trinity::Codecs::AccessProxy> accessProxy;
std::unique_ptr<SegmentTerms> terms; // all terms for this segment
range_base<const uint8_t *, uint32_t> index;
struct masked_documents_struct final {
updated_documents set;
range_base<const uint8_t *, uint32_t> fileData;
~masked_documents_struct() noexcept {
if (auto ptr = (void *)(fileData.offset))
munmap(ptr, fileData.size());
}
masked_documents_struct()
: set{} {
}
} maskedDocuments;
public:
SegmentIndexSource(const char *basePath);
bool index_empty() const noexcept override final {
return accessProxy.get() == nullptr;
}
auto backing_index() const noexcept {
return index;
}
auto access_proxy() {
return accessProxy.get();
}
field_statistics default_field_stats() override final {
return defaultFieldStats;
}
term_index_ctx resolve_term_ctx(const str8_t term) override final {
#if 1
return terms->lookup(term);
#else
const auto res = terms->lookup(term);
if (res.documents) {
SLog("MATCHED [", term, "] in ", generation(), "\n");
}
return res;
#endif
}
auto segment_terms() const {
return terms.get();
}
Trinity::Codecs::Decoder *new_postings_decoder(strwlen8_t, const term_index_ctx ctx) override final {
return accessProxy->new_decoder(ctx);
}
updated_documents masked_documents() override final {
return maskedDocuments.set;
}
~SegmentIndexSource() noexcept {
if (auto ptr = (void *)index.offset) {
#ifdef TRINITY_MEMRESIDENT_INDEX
std::free(ptr);
#else
munmap(ptr, index.size());
#endif
}
}
};
} // namespace Trinity