xref: /aosp_15_r20/external/icing/icing/index/main/main-index-merger.h (revision 8b6cd535a057e39b3b86660c4aa06c99747c2136)
1 // Copyright (C) 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ICING_INDEX_MAIN_MAIN_INDEX_MERGER_H_
16 #define ICING_INDEX_MAIN_MAIN_INDEX_MERGER_H_
17 
18 #include <vector>
19 
20 #include "icing/text_classifier/lib3/utils/base/statusor.h"
21 #include "icing/index/lite/lite-index.h"
22 #include "icing/index/lite/term-id-hit-pair.h"
23 #include "icing/index/main/main-index.h"
24 #include "icing/index/term-id-codec.h"
25 
26 namespace icing {
27 namespace lib {
28 
29 // Class used to merge hits from the lite_index and lite_lexicon into main_index
30 // and main_lexicon.
31 class MainIndexMerger {
32  public:
33   // Retrieves all hits in the lite index, translates the term ids of each
34   // LiteIndex::Element and expands prefix hits based on the mapping from
35   // lexicon_merge_outputs.other_tvi_to_prefix_main_tvis.
36   //
37   // RETURNS:
38   //  - OK on success
39   //  - INVALID_ARGUMENT if one of the elements in the lite index has a term_id
40   //  that exceeds the max TermId
41   static libtextclassifier3::StatusOr<std::vector<TermIdHitPair>>
42   TranslateAndExpandLiteHits(
43       const LiteIndex& lite_index, const TermIdCodec& term_id_codec,
44       const MainIndex::LexiconMergeOutputs& lexicon_merge_outputs);
45 };
46 
47 }  // namespace lib
48 }  // namespace icing
49 
50 #endif  // ICING_INDEX_MAIN_MAIN_INDEX_MERGER_H_
51