xref: /aosp_15_r20/external/icing/icing/index/iterator/doc-hit-info-iterator-property-in-schema.h (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 #ifndef ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_PROPERTY_IN_SCHEMA_H_
16 #define ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_PROPERTY_IN_SCHEMA_H_
17 
18 #include <cstdint>
19 #include <memory>
20 #include <set>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 
25 #include "icing/text_classifier/lib3/utils/base/status.h"
26 #include "icing/text_classifier/lib3/utils/base/statusor.h"
27 #include "icing/index/iterator/doc-hit-info-iterator.h"
28 #include "icing/schema/schema-store.h"
29 #include "icing/schema/section.h"
30 #include "icing/store/document-id.h"
31 #include "icing/store/document-store.h"
32 
33 namespace icing {
34 namespace lib {
35 
36 // An iterator that helps filter for DocHitInfos whose schemas define the
37 // properties named in target_properties_.
38 class DocHitInfoIteratorPropertyInSchema : public DocHitInfoIterator {
39  public:
40   // Does not take any ownership, and all pointers must refer to valid objects
41   // that outlive the one constructed. The delegate should be at minimum be
42   // a DocHitInfoIteratorAllDocumentId, but other optimizations are possible,
43   // cf. go/icing-property-in-schema-existence.
44   explicit DocHitInfoIteratorPropertyInSchema(
45       std::unique_ptr<DocHitInfoIterator> delegate,
46       const DocumentStore* document_store, const SchemaStore* schema_store,
47       std::set<std::string> target_sections, int64_t current_time_ms);
48 
49   libtextclassifier3::Status Advance() override;
50 
51   libtextclassifier3::StatusOr<TrimmedNode> TrimRightMostNode() && override;
52 
MapChildren(const ChildrenMapper & mapper)53   void MapChildren(const ChildrenMapper& mapper) override {
54     delegate_ = mapper(std::move(delegate_));
55   }
56 
GetCallStats()57   CallStats GetCallStats() const override { return delegate_->GetCallStats(); }
58 
59   std::string ToString() const override;
60 
61   void PopulateMatchedTermsStats(
62       std::vector<TermMatchInfo>* matched_terms_stats,
63       SectionIdMask filtering_section_mask = kSectionIdMaskAll) const override {
64     if (doc_hit_info_.document_id() == kInvalidDocumentId) {
65       // Current hit isn't valid, return.
66       return;
67     }
68     delegate_->PopulateMatchedTermsStats(matched_terms_stats,
69                                          filtering_section_mask);
70   }
71 
72  private:
73   std::unique_ptr<DocHitInfoIterator> delegate_;
74   const DocumentStore& document_store_;
75   const SchemaStore& schema_store_;
76 
77   std::set<std::string> target_properties_;
78   int64_t current_time_ms_;
79 };
80 
81 }  // namespace lib
82 }  // namespace icing
83 
84 #endif  // ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_PROPERTY_IN_SCHEMA_H_
85