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_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_BY_URI_H_ 16 #define ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_BY_URI_H_ 17 18 #include <memory> 19 #include <string> 20 #include <utility> 21 #include <vector> 22 23 #include "icing/text_classifier/lib3/utils/base/status.h" 24 #include "icing/text_classifier/lib3/utils/base/statusor.h" 25 #include "icing/absl_ports/canonical_errors.h" 26 #include "icing/index/iterator/doc-hit-info-iterator.h" 27 #include "icing/proto/search.pb.h" 28 #include "icing/store/document-id.h" 29 #include "icing/store/document-store.h" 30 31 namespace icing { 32 namespace lib { 33 34 class DocHitInfoIteratorByUri : public DocHitInfoIterator { 35 public: 36 // Creates a DocHitInfoIteratorByUri based on the given search_spec. 37 // 38 // Returns: 39 // - A DocHitInfoIteratorByUri instance on success. 40 // - INVALID_ARGUMENT error if the search_spec's document_uri_filters is 41 // empty or if any namespace in the document_uri_filters has no document 42 // URIs specified. 43 static libtextclassifier3::StatusOr<std::unique_ptr<DocHitInfoIteratorByUri>> 44 Create(const DocumentStore* document_store, 45 const SearchSpecProto& search_spec); 46 47 libtextclassifier3::Status Advance() override; 48 TrimRightMostNode()49 libtextclassifier3::StatusOr<TrimmedNode> TrimRightMostNode() && override { 50 return absl_ports::InvalidArgumentError( 51 "DocHitInfoIteratorByUri should not be used in suggestion."); 52 } 53 MapChildren(const ChildrenMapper & mapper)54 void MapChildren(const ChildrenMapper& mapper) override {} 55 GetCallStats()56 CallStats GetCallStats() const override { 57 return CallStats( 58 /*num_leaf_advance_calls_lite_index_in=*/0, 59 /*num_leaf_advance_calls_main_index_in=*/0, 60 /*num_leaf_advance_calls_integer_index_in=*/0, 61 /*num_leaf_advance_calls_no_index_in=*/num_advance_calls_, 62 /*num_blocks_inspected_in=*/0); 63 } 64 ToString()65 std::string ToString() const override { return "uri_iterator"; } 66 67 private: DocHitInfoIteratorByUri(std::vector<DocumentId> target_document_ids)68 explicit DocHitInfoIteratorByUri(std::vector<DocumentId> target_document_ids) 69 : target_document_ids_(std::move(target_document_ids)), 70 current_document_id_index_(-1), 71 num_advance_calls_(0) {} 72 73 std::vector<DocumentId> target_document_ids_; 74 int current_document_id_index_; 75 76 int num_advance_calls_; 77 }; 78 79 } // namespace lib 80 } // namespace icing 81 82 #endif // ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_BY_URI_H_ 83