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_DOCUMENT_H_ 16 #define ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_PROPERTY_IN_DOCUMENT_H_ 17 18 #include <cstdint> 19 #include <memory> 20 #include <string> 21 #include <utility> 22 #include <vector> 23 24 #include "icing/text_classifier/lib3/utils/base/status.h" 25 #include "icing/text_classifier/lib3/utils/base/statusor.h" 26 #include "icing/index/iterator/doc-hit-info-iterator.h" 27 #include "icing/schema/section.h" 28 #include "icing/store/document-id.h" 29 30 namespace icing { 31 namespace lib { 32 33 // The iterator returned by the "hasProperty" function in advanced query that 34 // post-processes metadata hits added by PropertyExistenceIndexingHandler. 35 // Specifically, it filters out hits that are not recognized as metadata, and 36 // always set hit_section_ids_mask to 0. 37 // 38 // It is marked as a subclass of DocHitInfoLeafIterator because section 39 // restriction should not be passed down to meta_hit_iterator. 40 class DocHitInfoIteratorPropertyInDocument : public DocHitInfoLeafIterator { 41 public: 42 explicit DocHitInfoIteratorPropertyInDocument( 43 std::unique_ptr<DocHitInfoIterator> meta_hit_iterator); 44 45 libtextclassifier3::Status Advance() override; 46 47 libtextclassifier3::StatusOr<TrimmedNode> TrimRightMostNode() && override; 48 GetCallStats()49 CallStats GetCallStats() const override { 50 return meta_hit_iterator_->GetCallStats(); 51 } 52 53 std::string ToString() const override; 54 55 void PopulateMatchedTermsStats( 56 std::vector<TermMatchInfo>* matched_terms_stats, 57 SectionIdMask filtering_section_mask = kSectionIdMaskAll) const override { 58 if (doc_hit_info_.document_id() == kInvalidDocumentId) { 59 // Current hit isn't valid, return. 60 return; 61 } 62 meta_hit_iterator_->PopulateMatchedTermsStats(matched_terms_stats, 63 filtering_section_mask); 64 } 65 66 private: 67 std::unique_ptr<DocHitInfoIterator> meta_hit_iterator_; 68 }; 69 70 } // namespace lib 71 } // namespace icing 72 73 #endif // ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_PROPERTY_IN_DOCUMENT_H_ 74