1 // Copyright (C) 2023 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_JOIN_QUALIFIED_ID_JOIN_INDEXING_HANDLER_H_ 16 #define ICING_JOIN_QUALIFIED_ID_JOIN_INDEXING_HANDLER_H_ 17 18 #include <memory> 19 20 #include "icing/text_classifier/lib3/utils/base/status.h" 21 #include "icing/text_classifier/lib3/utils/base/statusor.h" 22 #include "icing/index/data-indexing-handler.h" 23 #include "icing/join/qualified-id-join-index.h" 24 #include "icing/proto/logging.pb.h" 25 #include "icing/store/document-id.h" 26 #include "icing/store/document-store.h" 27 #include "icing/util/clock.h" 28 #include "icing/util/tokenized-document.h" 29 30 namespace icing { 31 namespace lib { 32 33 class QualifiedIdJoinIndexingHandler : public DataIndexingHandler { 34 public: 35 // Creates a QualifiedIdJoinIndexingHandler instance which does not take 36 // ownership of any input components. All pointers must refer to valid objects 37 // that outlive the created QualifiedIdJoinIndexingHandler instance. 38 // 39 // Returns: 40 // - A QualifiedIdJoinIndexingHandler instance on success 41 // - FAILED_PRECONDITION_ERROR if any of the input pointer is null 42 static libtextclassifier3::StatusOr< 43 std::unique_ptr<QualifiedIdJoinIndexingHandler>> 44 Create(const Clock* clock, const DocumentStore* doc_store, 45 QualifiedIdJoinIndex* qualified_id_join_index); 46 47 ~QualifiedIdJoinIndexingHandler() override = default; 48 49 // Handles the joinable qualified id data indexing process: add data into the 50 // qualified id join index. 51 // 52 /// Returns: 53 // - OK on success. 54 // - INVALID_ARGUMENT_ERROR if document_id is invalid OR document_id is less 55 // than or equal to the document_id of a previously indexed document in 56 // non recovery mode. 57 // - INTERNAL_ERROR if any other errors occur. 58 // - Any QualifiedIdJoinIndex errors. 59 libtextclassifier3::Status Handle( 60 const TokenizedDocument& tokenized_document, DocumentId document_id, 61 bool recovery_mode, PutDocumentStatsProto* put_document_stats) override; 62 63 private: QualifiedIdJoinIndexingHandler(const Clock * clock,const DocumentStore * doc_store,QualifiedIdJoinIndex * qualified_id_join_index)64 explicit QualifiedIdJoinIndexingHandler( 65 const Clock* clock, const DocumentStore* doc_store, 66 QualifiedIdJoinIndex* qualified_id_join_index) 67 : DataIndexingHandler(clock), 68 doc_store_(*doc_store), 69 qualified_id_join_index_(*qualified_id_join_index) {} 70 71 const DocumentStore& doc_store_; // Does not own. 72 QualifiedIdJoinIndex& qualified_id_join_index_; // Does not own. 73 }; 74 75 } // namespace lib 76 } // namespace icing 77 78 #endif // ICING_JOIN_QUALIFIED_ID_JOIN_INDEXING_HANDLER_H_ 79