1 // Copyright (C) 2024 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_H_ 16 #define ICING_JOIN_JOIN_CHILDREN_FETCHER_H_ 17 18 #include <string_view> 19 #include <vector> 20 21 #include "icing/text_classifier/lib3/utils/base/statusor.h" 22 #include "icing/proto/search.pb.h" 23 #include "icing/scoring/scored-document-hit.h" 24 #include "icing/store/document-id.h" 25 26 namespace icing { 27 namespace lib { 28 29 // A virtual class that provides the GetChildren method for joins to fetch all 30 // children documents given a parent document id. 31 class JoinChildrenFetcher { 32 public: 33 virtual ~JoinChildrenFetcher() = default; 34 35 // Gets a vector of children ScoredDocumentHit by parent document id. 36 // 37 // TODO(b/256022027): Implement property value joins with types of string and 38 // int. In these cases, GetChildren should look up join index to fetch 39 // joinable property value of the given parent_doc_id according to 40 // join_spec_.parent_property_expression, and then fetch children by the 41 // corresponding map in this class using the joinable property value. 42 // 43 // Returns: 44 // - The vector of ScoredDocumentHits for its children on success. 45 // - Other errors, depending on the implementation. 46 virtual libtextclassifier3::StatusOr<std::vector<ScoredDocumentHit>> 47 GetChildren(DocumentId parent_doc_id) const = 0; 48 49 protected: JoinChildrenFetcher(const JoinSpecProto & join_spec)50 explicit JoinChildrenFetcher(const JoinSpecProto& join_spec) 51 : join_spec_(join_spec) {} 52 53 static constexpr std::string_view kQualifiedIdExpr = "this.qualifiedId()"; 54 55 const JoinSpecProto& join_spec_; // Does not own! 56 }; 57 58 } // namespace lib 59 } // namespace icing 60 61 #endif // ICING_JOIN_JOIN_CHILDREN_FETCHER_H_ 62