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 #include "icing/result/projection-tree.h" 16 17 #include <algorithm> 18 19 #include "icing/proto/search.pb.h" 20 #include "icing/schema/property-util.h" 21 22 namespace icing { 23 namespace lib { 24 ProjectionTree(const SchemaStore::ExpandedTypePropertyMask & type_field_mask)25ProjectionTree::ProjectionTree( 26 const SchemaStore::ExpandedTypePropertyMask& type_field_mask) { 27 for (const std::string& field_mask : type_field_mask.paths) { 28 Node* current_node = &root_; 29 for (std::string_view sub_field_mask : 30 property_util::SplitPropertyPathExpr(field_mask)) { 31 current_node = AddChildNode(sub_field_mask, ¤t_node->children); 32 } 33 } 34 } 35 AddChildNode(std::string_view property_name,std::vector<Node> * current_children)36ProjectionTree::Node* ProjectionTree::AddChildNode( 37 std::string_view property_name, std::vector<Node>* current_children) { 38 auto itr = std::find_if(current_children->begin(), current_children->end(), 39 [&property_name](const Node& node) { 40 return node.name == property_name; 41 }); 42 if (itr != current_children->end()) { 43 return &(*itr); 44 } 45 current_children->push_back(ProjectionTree::Node(std::string(property_name))); 46 return ¤t_children->back(); 47 } 48 49 } // namespace lib 50 } // namespace icing 51