Coverage Report

Created: 2025-09-15 19:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/olap/collection_similarity.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 "rowset/segment_v2/common.h"
21
#include "vec/columns/column.h"
22
23
namespace doris {
24
#include "common/compile_check_begin.h"
25
26
using ScoreMap = phmap::flat_hash_map<segment_v2::rowid_t, float>;
27
using ScoreMapIterator = ScoreMap::const_iterator;
28
29
enum class OrderType {
30
    ASC,
31
    DESC,
32
};
33
34
class CollectionSimilarity {
35
public:
36
27
    CollectionSimilarity() { _bm25_scores.reserve(1024); }
37
27
    ~CollectionSimilarity() = default;
38
39
    void collect(segment_v2::rowid_t row_id, float score);
40
41
    void get_bm25_scores(roaring::Roaring* row_bitmap, vectorized::IColumn::MutablePtr& scores,
42
                         std::unique_ptr<std::vector<uint64_t>>& row_ids) const;
43
44
    void get_topn_bm25_scores(roaring::Roaring* row_bitmap, vectorized::IColumn::MutablePtr& scores,
45
                              std::unique_ptr<std::vector<uint64_t>>& row_ids, OrderType order_type,
46
                              size_t top_k) const;
47
48
private:
49
    template <OrderType order, typename Compare>
50
    void find_top_k_scores(const roaring::Roaring* row_bitmap, const ScoreMap& all_scores,
51
                           size_t top_k, Compare comp,
52
                           std::vector<std::pair<uint32_t, float>>& top_k_results) const;
53
54
    ScoreMap _bm25_scores;
55
};
56
using CollectionSimilarityPtr = std::shared_ptr<CollectionSimilarity>;
57
58
#include "common/compile_check_end.h"
59
} // namespace doris