be/src/runtime/index_policy/index_policy_mgr.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 <gen_cpp/AgentService_types.h> |
21 | | |
22 | | #include <cstdint> |
23 | | #include <functional> |
24 | | #include <map> |
25 | | #include <shared_mutex> |
26 | | #include <string> |
27 | | #include <string_view> |
28 | | #include <unordered_map> |
29 | | #include <unordered_set> |
30 | | |
31 | | #include "storage/index/inverted/analyzer/custom_analyzer.h" |
32 | | #include "storage/index/inverted/normalizer/custom_normalizer.h" |
33 | | |
34 | | namespace doris { |
35 | | |
36 | | using Policys = std::unordered_map<int64_t, TIndexPolicy>; |
37 | | using AnalyzerPtr = std::shared_ptr<lucene::analysis::Analyzer>; |
38 | | using AnalyzerProviderPtr = segment_v2::inverted_index::AnalyzerProviderPtr; |
39 | | |
40 | | class IndexPolicyMgr { |
41 | | public: |
42 | 21 | IndexPolicyMgr() = default; |
43 | 21 | ~IndexPolicyMgr() = default; |
44 | | |
45 | | void apply_policy_changes(const std::vector<TIndexPolicy>& policies_to_update, |
46 | | const std::vector<int64_t>& policies_to_delete); |
47 | | |
48 | | Policys get_index_policys(); |
49 | | AnalyzerPtr get_policy_by_name(const std::string& name); |
50 | | AnalyzerPtr get_analyzer_by_name(const std::string& name, |
51 | | segment_v2::inverted_index::AnalysisPurpose purpose); |
52 | | AnalyzerProviderPtr get_analyzer_provider_by_name( |
53 | | const std::string& name, |
54 | | const std::map<std::string, std::string>& outer_char_filter_map = {}); |
55 | | AnalyzerProviderPtr get_analyzer_provider_by_base_fingerprint( |
56 | | std::string_view base_analyzer_fingerprint, |
57 | | const std::map<std::string, std::string>& outer_char_filter_map = {}); |
58 | | |
59 | | private: |
60 | | segment_v2::inverted_index::CustomAnalyzerConfigPtr build_analyzer_config_from_policy( |
61 | | const TIndexPolicy& index_policy_analyzer); |
62 | | AnalyzerProviderPtr build_analyzer_provider_from_config( |
63 | | segment_v2::inverted_index::CustomAnalyzerConfigPtr config, |
64 | | const std::map<std::string, std::string>& outer_char_filter_map); |
65 | | AnalyzerPtr build_analyzer_from_policy(const TIndexPolicy& index_policy_analyzer); |
66 | | AnalyzerPtr build_normalizer_from_policy(const TIndexPolicy& index_policy_normalizer); |
67 | | |
68 | | void process_filter_configs( |
69 | | const TIndexPolicy& index_policy_analyzer, const std::string& prop_name, |
70 | | const std::string& error_prefix, |
71 | | std::function<void(const std::string&, const segment_v2::inverted_index::Settings&)> |
72 | | add_config_func); |
73 | | |
74 | | bool is_builtin_normalizer(const std::string& name); |
75 | | AnalyzerPtr build_builtin_normalizer(const std::string& name); |
76 | | |
77 | | // Normalize policy name to lowercase for case-insensitive lookup |
78 | | static std::string normalize_name(const std::string& name); |
79 | | |
80 | | constexpr static auto PROP_TOKENIZER = "tokenizer"; |
81 | | constexpr static auto PROP_CHAR_FILTER = "char_filter"; |
82 | | constexpr static auto PROP_TOKEN_FILTER = "token_filter"; |
83 | | constexpr static auto PROP_TYPE = "type"; |
84 | | |
85 | | static const std::unordered_set<std::string> BUILTIN_NORMALIZERS; |
86 | | |
87 | | std::shared_mutex _mutex; |
88 | | |
89 | | Policys _policys; |
90 | | std::unordered_map<std::string, int64_t> _name_to_id; |
91 | | }; |
92 | | |
93 | | } // namespace doris |