Coverage Report

Created: 2026-09-20 22:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/index/index_reader_helper.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include "storage/index/index_iterator.h"
21
#include "storage/index/inverted/inverted_index_reader.h"
22
23
namespace doris::segment_v2 {
24
25
class IndexReaderHelper {
26
public:
27
32
    static bool is_fulltext_index(const IndexReaderPtr& reader) {
28
32
        if (reader == nullptr || reader->index_type() != IndexType::INVERTED) {
29
8
            return false;
30
8
        }
31
32
24
        auto inverted_index_reader = std::static_pointer_cast<InvertedIndexReader>(reader);
33
24
        return inverted_index_reader->type() == InvertedIndexReaderType::FULLTEXT;
34
32
    }
35
36
28
    static bool is_string_index(const IndexReaderPtr& reader) {
37
28
        if (reader == nullptr || reader->index_type() != IndexType::INVERTED) {
38
4
            return false;
39
4
        }
40
41
24
        auto inverted_index_reader = std::static_pointer_cast<InvertedIndexReader>(reader);
42
24
        return inverted_index_reader->type() == InvertedIndexReaderType::STRING_TYPE;
43
28
    }
44
45
30
    static bool is_bkd_index(const IndexReaderPtr& reader) {
46
30
        if (reader == nullptr || reader->index_type() != IndexType::INVERTED) {
47
6
            return false;
48
6
        }
49
50
24
        auto inverted_index_reader = std::static_pointer_cast<InvertedIndexReader>(reader);
51
24
        return inverted_index_reader->type() == InvertedIndexReaderType::BKD;
52
30
    }
53
54
54
    static bool is_support_phrase(const IndexReaderPtr& reader) {
55
54
        if (reader == nullptr || reader->index_type() != IndexType::INVERTED) {
56
8
            return false;
57
8
        }
58
59
46
        auto inverted_index_reader = std::static_pointer_cast<InvertedIndexReader>(reader);
60
46
        const auto& properties = inverted_index_reader->get_index_properties();
61
46
        return get_parser_phrase_support_string_from_properties(properties) ==
62
46
               INVERTED_INDEX_PARSER_PHRASE_SUPPORT_YES;
63
54
    }
64
65
    // only string type or bkd index reader can be used for equal
66
18
    static bool has_string_or_bkd_index(const IndexIterator* iter) {
67
18
        if (iter == nullptr) {
68
0
            return false;
69
0
        }
70
71
18
        return iter->get_reader(InvertedIndexReaderType::STRING_TYPE) != nullptr ||
72
18
               iter->get_reader(InvertedIndexReaderType::BKD) != nullptr;
73
18
    }
74
75
16
    static bool has_bkd_index(const IndexIterator* iter) {
76
16
        if (iter == nullptr) {
77
0
            return false;
78
0
        }
79
80
16
        return iter->get_reader(InvertedIndexReaderType::BKD) != nullptr;
81
16
    }
82
83
0
    static bool has_string_index(const IndexIterator* iter) {
84
0
        if (iter == nullptr) {
85
0
            return false;
86
0
        }
87
0
88
0
        return iter->get_reader(InvertedIndexReaderType::STRING_TYPE) != nullptr;
89
0
    }
90
91
    static bool is_need_similarity_score(InvertedIndexQueryType query_type,
92
63
                                         const TabletIndex* index_meta) {
93
63
        if (query_type == InvertedIndexQueryType::MATCH_ANY_QUERY ||
94
63
            query_type == InvertedIndexQueryType::MATCH_ALL_QUERY ||
95
63
            query_type == InvertedIndexQueryType::MATCH_PHRASE_QUERY ||
96
63
            query_type == InvertedIndexQueryType::MATCH_PHRASE_PREFIX_QUERY) {
97
55
            const auto& properties = index_meta->properties();
98
55
            if (get_parser_phrase_support_string_from_properties(properties) ==
99
55
                INVERTED_INDEX_PARSER_PHRASE_SUPPORT_YES) {
100
55
                return true;
101
55
            }
102
55
        }
103
8
        return false;
104
63
    }
105
106
    static bool is_need_similarity_score(TExprOpcode::type query_type,
107
58
                                         const TabletIndex* index_meta) {
108
58
        if (query_type == TExprOpcode::MATCH_ANY || query_type == TExprOpcode::MATCH_ALL ||
109
58
            query_type == TExprOpcode::MATCH_PHRASE ||
110
58
            query_type == TExprOpcode::MATCH_PHRASE_PREFIX) {
111
54
            const auto& properties = index_meta->properties();
112
54
            if (get_parser_phrase_support_string_from_properties(properties) ==
113
54
                INVERTED_INDEX_PARSER_PHRASE_SUPPORT_YES) {
114
52
                return true;
115
52
            }
116
54
        }
117
6
        return false;
118
58
    }
119
};
120
121
} // namespace doris::segment_v2