Coverage Report

Created: 2026-03-17 00:16

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
#include "common/compile_check_begin.h"
25
26
class IndexReaderHelper {
27
public:
28
16
    static bool is_fulltext_index(const IndexReaderPtr& reader) {
29
16
        if (reader == nullptr || reader->index_type() != IndexType::INVERTED) {
30
4
            return false;
31
4
        }
32
33
12
        auto inverted_index_reader = std::static_pointer_cast<InvertedIndexReader>(reader);
34
12
        return inverted_index_reader->type() == InvertedIndexReaderType::FULLTEXT;
35
16
    }
36
37
14
    static bool is_string_index(const IndexReaderPtr& reader) {
38
14
        if (reader == nullptr || reader->index_type() != IndexType::INVERTED) {
39
2
            return false;
40
2
        }
41
42
12
        auto inverted_index_reader = std::static_pointer_cast<InvertedIndexReader>(reader);
43
12
        return inverted_index_reader->type() == InvertedIndexReaderType::STRING_TYPE;
44
14
    }
45
46
15
    static bool is_bkd_index(const IndexReaderPtr& reader) {
47
15
        if (reader == nullptr || reader->index_type() != IndexType::INVERTED) {
48
3
            return false;
49
3
        }
50
51
12
        auto inverted_index_reader = std::static_pointer_cast<InvertedIndexReader>(reader);
52
12
        return inverted_index_reader->type() == InvertedIndexReaderType::BKD;
53
15
    }
54
55
24
    static bool is_support_phrase(const IndexReaderPtr& reader) {
56
24
        if (reader == nullptr || reader->index_type() != IndexType::INVERTED) {
57
4
            return false;
58
4
        }
59
60
20
        auto inverted_index_reader = std::static_pointer_cast<InvertedIndexReader>(reader);
61
20
        const auto& properties = inverted_index_reader->get_index_properties();
62
20
        return get_parser_phrase_support_string_from_properties(properties) ==
63
20
               INVERTED_INDEX_PARSER_PHRASE_SUPPORT_YES;
64
24
    }
65
66
    // only string type or bkd index reader can be used for equal
67
1
    static bool has_string_or_bkd_index(const IndexIterator* iter) {
68
1
        if (iter == nullptr) {
69
0
            return false;
70
0
        }
71
72
1
        return iter->get_reader(InvertedIndexReaderType::STRING_TYPE) != nullptr ||
73
1
               iter->get_reader(InvertedIndexReaderType::BKD) != nullptr;
74
1
    }
75
76
2
    static bool has_bkd_index(const IndexIterator* iter) {
77
2
        if (iter == nullptr) {
78
0
            return false;
79
0
        }
80
81
2
        return iter->get_reader(InvertedIndexReaderType::BKD) != nullptr;
82
2
    }
83
84
0
    static bool has_string_index(const IndexIterator* iter) {
85
0
        if (iter == nullptr) {
86
0
            return false;
87
0
        }
88
0
89
0
        return iter->get_reader(InvertedIndexReaderType::STRING_TYPE) != nullptr;
90
0
    }
91
92
    static bool is_need_similarity_score(InvertedIndexQueryType query_type,
93
24
                                         const TabletIndex* index_meta) {
94
24
        if (query_type == InvertedIndexQueryType::MATCH_ANY_QUERY ||
95
24
            query_type == InvertedIndexQueryType::MATCH_ALL_QUERY ||
96
24
            query_type == InvertedIndexQueryType::MATCH_PHRASE_QUERY ||
97
24
            query_type == InvertedIndexQueryType::MATCH_PHRASE_PREFIX_QUERY) {
98
21
            const auto& properties = index_meta->properties();
99
21
            if (get_parser_phrase_support_string_from_properties(properties) ==
100
21
                INVERTED_INDEX_PARSER_PHRASE_SUPPORT_YES) {
101
21
                return true;
102
21
            }
103
21
        }
104
3
        return false;
105
24
    }
106
107
    static bool is_need_similarity_score(TExprOpcode::type query_type,
108
4
                                         const TabletIndex* index_meta) {
109
4
        if (query_type == TExprOpcode::MATCH_ANY || query_type == TExprOpcode::MATCH_ALL ||
110
4
            query_type == TExprOpcode::MATCH_PHRASE ||
111
4
            query_type == TExprOpcode::MATCH_PHRASE_PREFIX) {
112
2
            const auto& properties = index_meta->properties();
113
2
            if (get_parser_phrase_support_string_from_properties(properties) ==
114
2
                INVERTED_INDEX_PARSER_PHRASE_SUPPORT_YES) {
115
2
                return true;
116
2
            }
117
2
        }
118
2
        return false;
119
4
    }
120
};
121
122
#include "common/compile_check_end.h"
123
} // namespace doris::segment_v2