diff options
author | Alexander Dorokhine <adorokhine@google.com> | 2021-08-13 11:07:18 -0700 |
---|---|---|
committer | Alexander Dorokhine <adorokhine@google.com> | 2021-08-13 11:07:18 -0700 |
commit | 71eeeb436ec794daef5187d12ca9aba2c5773d7d (patch) | |
tree | 5129f3a74eb616eb2856c6db3392011c1ce384f8 /icing/index/iterator/doc-hit-info-iterator-section-restrict.cc | |
parent | 40c7203fab1d491f62f223fad10eddc180605729 (diff) | |
download | icing-71eeeb436ec794daef5187d12ca9aba2c5773d7d.tar.gz |
Merge androidx-platform-dev/external/icing upstream-master into upstream-master
Change-Id: Id39bea14b3a3d378d722dc552e4f3bd4249f3f94
Diffstat (limited to 'icing/index/iterator/doc-hit-info-iterator-section-restrict.cc')
-rw-r--r-- | icing/index/iterator/doc-hit-info-iterator-section-restrict.cc | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/icing/index/iterator/doc-hit-info-iterator-section-restrict.cc b/icing/index/iterator/doc-hit-info-iterator-section-restrict.cc index e6ee8e3..034c8cb 100644 --- a/icing/index/iterator/doc-hit-info-iterator-section-restrict.cc +++ b/icing/index/iterator/doc-hit-info-iterator-section-restrict.cc @@ -45,56 +45,54 @@ DocHitInfoIteratorSectionRestrict::DocHitInfoIteratorSectionRestrict( target_section_(target_section) {} libtextclassifier3::Status DocHitInfoIteratorSectionRestrict::Advance() { - if (!delegate_->Advance().ok()) { - // Didn't find anything on the delegate iterator. - doc_hit_info_ = DocHitInfo(kInvalidDocumentId); - hit_intersect_section_ids_mask_ = kSectionIdMaskNone; - return absl_ports::ResourceExhaustedError( - "No more DocHitInfos in iterator"); - } - - DocumentId document_id = delegate_->doc_hit_info().document_id(); - - SectionIdMask section_id_mask = - delegate_->doc_hit_info().hit_section_ids_mask(); - - auto data_or = document_store_.GetDocumentFilterData(document_id); - if (!data_or.ok()) { - // Ran into some error retrieving information on this hit, skip - return Advance(); - } + while (delegate_->Advance().ok()) { + DocumentId document_id = delegate_->doc_hit_info().document_id(); - // Guaranteed that the DocumentFilterData exists at this point - DocumentFilterData data = std::move(data_or).ValueOrDie(); - SchemaTypeId schema_type_id = data.schema_type_id(); + SectionIdMask section_id_mask = + delegate_->doc_hit_info().hit_section_ids_mask(); - // A hit can be in multiple sections at once, need to check that at least one - // of the confirmed section ids match the name of the target section - while (section_id_mask != 0) { - // There was a hit in this section id - SectionId section_id = __builtin_ctz(section_id_mask); - - auto section_metadata_or = - schema_store_.GetSectionMetadata(schema_type_id, section_id); - - if (section_metadata_or.ok()) { - const SectionMetadata* section_metadata = - section_metadata_or.ValueOrDie(); + auto data_or = document_store_.GetDocumentFilterData(document_id); + if (!data_or.ok()) { + // Ran into some error retrieving information on this hit, skip + continue; + } - if (section_metadata->path == target_section_) { - // The hit was in the target section name, return OK/found - doc_hit_info_ = delegate_->doc_hit_info(); - hit_intersect_section_ids_mask_ = 1u << section_id; - return libtextclassifier3::Status::OK; + // Guaranteed that the DocumentFilterData exists at this point + DocumentFilterData data = std::move(data_or).ValueOrDie(); + SchemaTypeId schema_type_id = data.schema_type_id(); + + // A hit can be in multiple sections at once, need to check that at least + // one of the confirmed section ids match the name of the target section + while (section_id_mask != 0) { + // There was a hit in this section id + SectionId section_id = __builtin_ctz(section_id_mask); + + auto section_metadata_or = + schema_store_.GetSectionMetadata(schema_type_id, section_id); + + if (section_metadata_or.ok()) { + const SectionMetadata* section_metadata = + section_metadata_or.ValueOrDie(); + + if (section_metadata->path == target_section_) { + // The hit was in the target section name, return OK/found + doc_hit_info_ = delegate_->doc_hit_info(); + hit_intersect_section_ids_mask_ = 1u << section_id; + return libtextclassifier3::Status::OK; + } } + + // Mark this section as checked + section_id_mask &= ~(1U << section_id); } - // Mark this section as checked - section_id_mask &= ~(1U << section_id); + // Didn't find a matching section name for this hit. Continue. } - // Didn't find a matching section name for this hit, go to the next hit - return Advance(); + // Didn't find anything on the delegate iterator. + doc_hit_info_ = DocHitInfo(kInvalidDocumentId); + hit_intersect_section_ids_mask_ = kSectionIdMaskNone; + return absl_ports::ResourceExhaustedError("No more DocHitInfos in iterator"); } int32_t DocHitInfoIteratorSectionRestrict::GetNumBlocksInspected() const { |