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-filter.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-filter.cc')
-rw-r--r-- | icing/index/iterator/doc-hit-info-iterator-filter.cc | 93 |
1 files changed, 40 insertions, 53 deletions
diff --git a/icing/index/iterator/doc-hit-info-iterator-filter.cc b/icing/index/iterator/doc-hit-info-iterator-filter.cc index c6cb86d..933f9b5 100644 --- a/icing/index/iterator/doc-hit-info-iterator-filter.cc +++ b/icing/index/iterator/doc-hit-info-iterator-filter.cc @@ -31,7 +31,6 @@ #include "icing/store/document-filter-data.h" #include "icing/store/document-id.h" #include "icing/store/document-store.h" -#include "icing/util/clock.h" namespace icing { namespace lib { @@ -39,12 +38,11 @@ namespace lib { DocHitInfoIteratorFilter::DocHitInfoIteratorFilter( std::unique_ptr<DocHitInfoIterator> delegate, const DocumentStore* document_store, const SchemaStore* schema_store, - const Clock* clock, const Options& options) + const Options& options) : delegate_(std::move(delegate)), document_store_(*document_store), schema_store_(*schema_store), - options_(options), - current_time_milliseconds_(clock->GetSystemTimeMilliseconds()) { + options_(options) { // Precompute all the NamespaceIds for (std::string_view name_space : options_.namespaces) { auto namespace_id_or = document_store_.GetNamespaceId(name_space); @@ -67,61 +65,50 @@ DocHitInfoIteratorFilter::DocHitInfoIteratorFilter( } libtextclassifier3::Status DocHitInfoIteratorFilter::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"); - } - - if (current_time_milliseconds_ < 0) { - // This shouldn't happen, but we add a sanity check here for any unknown - // errors. - return absl_ports::InternalError( - "Couldn't get current time. Try again in a bit"); - } - - if (!document_store_.DoesDocumentExist( - delegate_->doc_hit_info().document_id())) { - // Document doesn't exist, keep searching - return Advance(); - } + while (delegate_->Advance().ok()) { + if (!document_store_.DoesDocumentExist( + delegate_->doc_hit_info().document_id())) { + // Document doesn't exist, keep searching. This handles deletions and + // expired documents. + continue; + } - // Try to get the DocumentFilterData - auto document_filter_data_or = document_store_.GetDocumentFilterData( - delegate_->doc_hit_info().document_id()); - if (!document_filter_data_or.ok()) { - // Didn't find the DocumentFilterData in the filter cache. This could be - // because the DocumentId isn't valid or the filter cache is in some invalid - // state. This is bad, but not the query's responsibility to fix, so just - // skip this result for now. - return Advance(); - } - // We should be guaranteed that this exists now. - DocumentFilterData data = std::move(document_filter_data_or).ValueOrDie(); + // Try to get the DocumentFilterData + auto document_filter_data_or = document_store_.GetDocumentFilterData( + delegate_->doc_hit_info().document_id()); + if (!document_filter_data_or.ok()) { + // Didn't find the DocumentFilterData in the filter cache. This could be + // because the DocumentId isn't valid or the filter cache is in some + // invalid state. This is bad, but not the query's responsibility to fix, + // so just skip this result for now. + continue; + } + // We should be guaranteed that this exists now. + DocumentFilterData data = std::move(document_filter_data_or).ValueOrDie(); - if (!options_.namespaces.empty() && - target_namespace_ids_.count(data.namespace_id()) == 0) { - // Doesn't match one of the specified namespaces. Keep searching - return Advance(); - } + if (!options_.namespaces.empty() && + target_namespace_ids_.count(data.namespace_id()) == 0) { + // Doesn't match one of the specified namespaces. Keep searching + continue; + } - if (!options_.schema_types.empty() && - target_schema_type_ids_.count(data.schema_type_id()) == 0) { - // Doesn't match one of the specified schema types. Keep searching - return Advance(); - } + if (!options_.schema_types.empty() && + target_schema_type_ids_.count(data.schema_type_id()) == 0) { + // Doesn't match one of the specified schema types. Keep searching + continue; + } - if (current_time_milliseconds_ >= data.expiration_timestamp_ms()) { - // Current time has exceeded the document's expiration time - return Advance(); + // Satisfied all our specified filters + doc_hit_info_ = delegate_->doc_hit_info(); + hit_intersect_section_ids_mask_ = + delegate_->hit_intersect_section_ids_mask(); + return libtextclassifier3::Status::OK; } - // Satisfied all our specified filters - doc_hit_info_ = delegate_->doc_hit_info(); - hit_intersect_section_ids_mask_ = delegate_->hit_intersect_section_ids_mask(); - return libtextclassifier3::Status::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"); } int32_t DocHitInfoIteratorFilter::GetNumBlocksInspected() const { |