xref: /aosp_15_r20/external/icing/icing/index/iterator/doc-hit-info-iterator-all-document-id.cc (revision 8b6cd535a057e39b3b86660c4aa06c99747c2136)
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/index/iterator/doc-hit-info-iterator-all-document-id.h"
16 
17 #include "icing/text_classifier/lib3/utils/base/status.h"
18 #include "icing/absl_ports/canonical_errors.h"
19 #include "icing/index/hit/doc-hit-info.h"
20 #include "icing/index/iterator/doc-hit-info-iterator.h"
21 #include "icing/store/document-id.h"
22 
23 namespace icing {
24 namespace lib {
25 
DocHitInfoIteratorAllDocumentId(const DocumentId document_id_limit)26 DocHitInfoIteratorAllDocumentId::DocHitInfoIteratorAllDocumentId(
27     const DocumentId document_id_limit)
28     : document_id_limit_(document_id_limit),
29       current_document_id_(document_id_limit) {}
30 
Advance()31 libtextclassifier3::Status DocHitInfoIteratorAllDocumentId::Advance() {
32   if (!IsDocumentIdValid(current_document_id_)) {
33     // Reached the end, set these to invalid values and return
34     doc_hit_info_ = DocHitInfo(kInvalidDocumentId);
35     return absl_ports::ResourceExhaustedError(
36         "No more DocHitInfos in iterator");
37   }
38   doc_hit_info_.set_document_id(current_document_id_--);
39   return libtextclassifier3::Status::OK;
40 }
41 
42 libtextclassifier3::StatusOr<DocHitInfoIterator::TrimmedNode>
TrimRightMostNode()43 DocHitInfoIteratorAllDocumentId::TrimRightMostNode() && {
44   // The all document id node should be trimmed.
45   TrimmedNode node = {nullptr, /*term=*/"", /*term_start_index_=*/0,
46                       /*unnormalized_term_length_=*/0};
47   return node;
48 }
49 }  // namespace lib
50 }  // namespace icing
51