• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 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_INTEGER_SECTION_INDEXING_HANDLER_H_
16 #define ICING_INDEX_INTEGER_SECTION_INDEXING_HANDLER_H_
17 
18 #include <cstdint>
19 #include <memory>
20 
21 #include "icing/text_classifier/lib3/utils/base/status.h"
22 #include "icing/text_classifier/lib3/utils/base/statusor.h"
23 #include "icing/index/data-indexing-handler.h"
24 #include "icing/index/numeric/numeric-index.h"
25 #include "icing/store/document-id.h"
26 #include "icing/util/clock.h"
27 #include "icing/util/tokenized-document.h"
28 
29 namespace icing {
30 namespace lib {
31 
32 class IntegerSectionIndexingHandler : public DataIndexingHandler {
33  public:
34   // Creates an IntegerSectionIndexingHandler instance which does not take
35   // ownership of any input components. All pointers must refer to valid objects
36   // that outlive the created IntegerSectionIndexingHandler instance.
37   //
38   // Returns:
39   //   - An IntegerSectionIndexingHandler instance on success
40   //   - FAILED_PRECONDITION_ERROR if any of the input pointer is null
41   static libtextclassifier3::StatusOr<
42       std::unique_ptr<IntegerSectionIndexingHandler>>
43   Create(const Clock* clock, NumericIndex<int64_t>* integer_index);
44 
45   ~IntegerSectionIndexingHandler() override = default;
46 
47   // Handles the integer indexing process: add hits into the integer index for
48   // all contents in tokenized_document.integer_sections.
49   //
50   // Returns:
51   //   - OK on success.
52   //   - INVALID_ARGUMENT_ERROR if document_id is invalid OR document_id is less
53   //     than or equal to the document_id of a previously indexed document in
54   //     non recovery mode.
55   //   - Any NumericIndex<int64_t>::Editor errors.
56   libtextclassifier3::Status Handle(
57       const TokenizedDocument& tokenized_document, DocumentId document_id,
58       bool recovery_mode, PutDocumentStatsProto* put_document_stats) override;
59 
60  private:
IntegerSectionIndexingHandler(const Clock * clock,NumericIndex<int64_t> * integer_index)61   explicit IntegerSectionIndexingHandler(const Clock* clock,
62                                          NumericIndex<int64_t>* integer_index)
63       : DataIndexingHandler(clock), integer_index_(*integer_index) {}
64 
65   NumericIndex<int64_t>& integer_index_;  // Does not own.
66 };
67 
68 }  // namespace lib
69 }  // namespace icing
70 
71 #endif  // ICING_INDEX_INTEGER_SECTION_INDEXING_HANDLER_H_
72