Coverage Report

Created: 2026-03-17 19:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/index/analyzer_key_matcher.cpp
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
#include "storage/index/analyzer_key_matcher.h"
19
20
#include "storage/index/inverted/inverted_index_iterator.h"
21
22
namespace doris::segment_v2 {
23
24
AnalyzerMatchResult AnalyzerKeyMatcher::match(
25
        std::string_view analyzer_key, const std::vector<ReaderEntry>& entries,
26
20
        const std::unordered_map<std::string, std::vector<size_t>>& key_index) {
27
20
    AnalyzerMatchResult result;
28
29
20
    if (entries.empty()) {
30
1
        return result;
31
1
    }
32
33
    // Step 1: If fallback is allowed (__default__ or empty), return all readers
34
    // This allows query-type-based selection (e.g., FULLTEXT for MATCH queries,
35
    // STRING_TYPE for EQUAL queries) rather than being constrained to a single index.
36
19
    if (allows_fallback(analyzer_key)) {
37
5
        result.candidates.reserve(entries.size());
38
12
        for (const auto& entry : entries) {
39
12
            result.candidates.push_back(&entry);
40
12
        }
41
5
        result.used_fallback = true;
42
5
        return result;
43
5
    }
44
45
    // Step 2: Try exact match for explicit analyzer keys
46
14
    std::string key_str(analyzer_key);
47
14
    auto it = key_index.find(key_str);
48
14
    if (it != key_index.end() && !it->second.empty()) {
49
12
        result.candidates.reserve(it->second.size());
50
15
        for (size_t idx : it->second) {
51
15
            if (idx < entries.size()) {
52
15
                result.candidates.push_back(&entries[idx]);
53
15
            }
54
15
        }
55
12
    }
56
57
    // Step 3: If explicit key with no match, return empty (caller will bypass)
58
14
    return result;
59
19
}
60
61
} // namespace doris::segment_v2