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 <memory>
19 
20 #include "icing/text_classifier/lib3/utils/base/statusor.h"
21 #include "icing/index/lite/lite-index.h"
22 #include "icing/index/main/main-index.h"
23 #include "icing/index/term-id-codec.h"
24 
25 namespace icing {
26 namespace lib {
27 
28 // Class used to merge hits from the lite_index and lite_lexicon into main_index
29 // and main_lexicon.
30 class MainIndexMerger {
31  public:
32   // Retrieves all hits in the lite index, translates the term ids of each
33   // LiteIndex::Element and expands prefix hits based on the mapping from
34   // lexicon_merge_outputs.other_tvi_to_prefix_main_tvis.
35   //
36   // RETURNS:
37   //  - OK on success
38   //  - INVALID_ARGUMENT if one of the elements in the lite index has a term_id
39   //  that exceeds the max TermId
40   static libtextclassifier3::StatusOr<std::vector<TermIdHitPair>>
41   TranslateAndExpandLiteHits(
42       const LiteIndex& lite_index, const TermIdCodec& term_id_codec,
43       const MainIndex::LexiconMergeOutputs& lexicon_merge_outputs);
44 };
45 
46 }  // namespace lib
47 }  // namespace icing
48 
49 #endif  // ICING_INDEX_MAIN_MAIN_INDEX_MERGER_H_
50