Coverage Report

Created: 2026-03-16 16:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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 <shared_mutex>
23
#include <unordered_set>
24
25
#include "storage/index/inverted/analyzer/custom_analyzer.h"
26
#include "storage/index/inverted/normalizer/custom_normalizer.h"
27
28
namespace doris {
29
30
using Policys = std::unordered_map<int64_t, TIndexPolicy>;
31
using AnalyzerPtr = std::shared_ptr<lucene::analysis::Analyzer>;
32
33
class IndexPolicyMgr {
34
public:
35
7
    IndexPolicyMgr() = default;
36
7
    ~IndexPolicyMgr() = default;
37
38
    void apply_policy_changes(const std::vector<TIndexPolicy>& policies_to_update,
39
                              const std::vector<int64_t>& policies_to_delete);
40
41
    Policys get_index_policys();
42
    AnalyzerPtr get_policy_by_name(const std::string& name);
43
44
private:
45
    AnalyzerPtr build_analyzer_from_policy(const TIndexPolicy& index_policy_analyzer);
46
    AnalyzerPtr build_normalizer_from_policy(const TIndexPolicy& index_policy_normalizer);
47
48
    void process_filter_configs(
49
            const TIndexPolicy& index_policy_analyzer, const std::string& prop_name,
50
            const std::string& error_prefix,
51
            std::function<void(const std::string&, const segment_v2::inverted_index::Settings&)>
52
                    add_config_func);
53
54
    bool is_builtin_normalizer(const std::string& name);
55
    AnalyzerPtr build_builtin_normalizer(const std::string& name);
56
57
    // Normalize policy name to lowercase for case-insensitive lookup
58
    static std::string normalize_name(const std::string& name);
59
60
    constexpr static auto PROP_TOKENIZER = "tokenizer";
61
    constexpr static auto PROP_CHAR_FILTER = "char_filter";
62
    constexpr static auto PROP_TOKEN_FILTER = "token_filter";
63
    constexpr static auto PROP_TYPE = "type";
64
65
    static const std::unordered_set<std::string> BUILTIN_NORMALIZERS;
66
67
    std::shared_mutex _mutex;
68
69
    Policys _policys;
70
    std::unordered_map<std::string, int64_t> _name_to_id;
71
};
72
73
} // namespace doris