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_JOIN_CHILDREN_FETCHER_IMPL_DEPRECATED_H_ 16 #define ICING_JOIN_JOIN_CHILDREN_FETCHER_IMPL_DEPRECATED_H_ 17 18 #include <memory> 19 #include <unordered_map> 20 #include <utility> 21 #include <vector> 22 23 #include "icing/text_classifier/lib3/utils/base/statusor.h" 24 #include "icing/join/join-children-fetcher.h" 25 #include "icing/proto/search.pb.h" 26 #include "icing/scoring/scored-document-hit.h" 27 #include "icing/store/document-id.h" 28 29 namespace icing { 30 namespace lib { 31 32 // A class that provides the GetChildren method for joins to fetch all children 33 // documents given a parent document id. Only QualifiedIdJoinIndexImplV1 and 34 // QualifiedIdJoinIndexImplV2 will use this class, since we can construct the 35 // map without parent document id available. 36 // 37 // Internally, the class maintains a map for each joinable value type that 38 // groups children according to the joinable values. Currently we only support 39 // QUALIFIED_ID joining, in which the joinable value type is document id. 40 class JoinChildrenFetcherImplDeprecated : public JoinChildrenFetcher { 41 public: 42 // Creates JoinChildrenFetcherImplDeprecated. 43 // 44 // Returns: 45 // - A JoinChildrenFetcherImplDeprecated instance on success. 46 // - UNIMPLEMENTED_ERROR if the join type specified by join_spec is not 47 // supported. 48 static libtextclassifier3::StatusOr< 49 std::unique_ptr<JoinChildrenFetcherImplDeprecated>> 50 Create(const JoinSpecProto& join_spec, 51 std::unordered_map<DocumentId, std::vector<ScoredDocumentHit>>&& 52 map_joinable_qualified_id); 53 54 ~JoinChildrenFetcherImplDeprecated() override = default; 55 56 libtextclassifier3::StatusOr<std::vector<ScoredDocumentHit>> GetChildren( 57 DocumentId parent_doc_id) const override; 58 59 private: JoinChildrenFetcherImplDeprecated(const JoinSpecProto & join_spec,std::unordered_map<DocumentId,std::vector<ScoredDocumentHit>> && map_joinable_qualified_id)60 explicit JoinChildrenFetcherImplDeprecated( 61 const JoinSpecProto& join_spec, 62 std::unordered_map<DocumentId, std::vector<ScoredDocumentHit>>&& 63 map_joinable_qualified_id) 64 : JoinChildrenFetcher(join_spec), 65 map_joinable_qualified_id_(std::move(map_joinable_qualified_id)) {} 66 67 // The map that groups children by qualified id used to support QualifiedId 68 // joining. The joining type is document id. 69 std::unordered_map<DocumentId, std::vector<ScoredDocumentHit>> 70 map_joinable_qualified_id_; 71 }; 72 73 } // namespace lib 74 } // namespace icing 75 76 #endif // ICING_JOIN_JOIN_CHILDREN_FETCHER_IMPL_DEPRECATED_H_ 77