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