diff options
author | Tim Barron <tjbarron@google.com> | 2023-05-11 06:22:44 +0000 |
---|---|---|
committer | Tim Barron <tjbarron@google.com> | 2023-05-11 15:45:06 +0000 |
commit | fc9e6aac9c62d4546cb25548e1bbb317b7a4fd9a (patch) | |
tree | 061f4d194144ae4d5f81e6b56c148ddb5495e694 /icing/index/iterator/doc-hit-info-iterator-property-in-schema.cc | |
parent | a7d57e98ea7168d66cf01ace85598e33d5e9e5db (diff) | |
download | icing-fc9e6aac9c62d4546cb25548e1bbb317b7a4fd9a.tar.gz |
Update Icing from upstream.
Descriptions:
========================================================================
Modify the definition of propertyDefined:
========================================================================
Remove default args in SchemaStore::SetSchema and fix calls
========================================================================
Add allow_circular_schema_definitions flag
========================================================================
Onboard version detection to Icing
========================================================================
Add version util to help read/write version info
========================================================================
Add support for the overlay schema.
========================================================================
Allow cycles in schema-property-iterator
========================================================================
Add joinable properties into schema definition cycle restrictions.
========================================================================
Loosen circular references restriction for Schema Definitions.
========================================================================
Implement BackupSchemaProducer to generate a backup schema
========================================================================
Minor fix: remove a redundant log
========================================================================
Allow schema types to inherit from more than one parent
========================================================================
allow nested document properties to accept documents of subtype
========================================================================
Support polymorphism for Icing projection in Search and Get API
========================================================================
Add max_joined_child_per_parent into ResultSpec and change behavior
========================================================================
Support Icing schema type polymorphism for the search filter API
========================================================================
Verify that every child type's property set has included all compatible properties from parent types
========================================================================
Add individual type index latency
========================================================================
Build the iterator node for the propertyDefined() custom function
========================================================================
Advance all hits with same doc id from and merge sections once for the same bucket iter
========================================================================
Introduce DocHitInfoIteratorPropertyInSchema for property existence check
========================================================================
Add SchemaUtil::BuildTransitiveInheritanceGraph to build an inheritance map from schema
========================================================================
Introduce a lookup method for a property defined in a schema
========================================================================
Rollback of: Allow LanguageSegmenter::Iterators to declare AccessType.
========================================================================
Adds join info to QueryStatsProto
========================================================================
Bug:280698419
Bug:280698125
Bug:280698121
Bug:280697513
Bug:276349029
Bug:272145329
Bug:270102295
Bug:269295094
Bug:268680462
Bug:265304217
Bug:259744228
Bug:259743562
Bug:256022027
Change-Id: I54cd1d22121c314f8c238d2d49f0809165dc0ca3
Diffstat (limited to 'icing/index/iterator/doc-hit-info-iterator-property-in-schema.cc')
-rw-r--r-- | icing/index/iterator/doc-hit-info-iterator-property-in-schema.cc | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/icing/index/iterator/doc-hit-info-iterator-property-in-schema.cc b/icing/index/iterator/doc-hit-info-iterator-property-in-schema.cc new file mode 100644 index 0000000..5f260a8 --- /dev/null +++ b/icing/index/iterator/doc-hit-info-iterator-property-in-schema.cc @@ -0,0 +1,114 @@ +// Copyright (C) 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "icing/index/iterator/doc-hit-info-iterator-property-in-schema.h" + +#include <cstdint> +#include <memory> +#include <string> +#include <string_view> +#include <utility> + +#include "icing/text_classifier/lib3/utils/base/status.h" +#include "icing/text_classifier/lib3/utils/base/statusor.h" +#include "icing/absl_ports/canonical_errors.h" +#include "icing/absl_ports/str_cat.h" +#include "icing/index/hit/doc-hit-info.h" +#include "icing/index/iterator/doc-hit-info-iterator.h" +#include "icing/schema/schema-store.h" +#include "icing/store/document-id.h" +#include "icing/store/document-store.h" + +namespace icing { +namespace lib { + +DocHitInfoIteratorPropertyInSchema::DocHitInfoIteratorPropertyInSchema( + std::unique_ptr<DocHitInfoIterator> delegate, + const DocumentStore* document_store, const SchemaStore* schema_store, + std::set<std::string> target_sections) + : delegate_(std::move(delegate)), + document_store_(*document_store), + schema_store_(*schema_store), + target_properties_(std::move(target_sections)) {} + +libtextclassifier3::Status DocHitInfoIteratorPropertyInSchema::Advance() { + doc_hit_info_ = DocHitInfo(kInvalidDocumentId); + hit_intersect_section_ids_mask_ = kSectionIdMaskNone; + + // Maps from SchemaTypeId to a bool indicating whether or not the type has + // the requested property. + std::unordered_map<SchemaTypeId, bool> property_defined_types; + while (delegate_->Advance().ok()) { + DocumentId document_id = delegate_->doc_hit_info().document_id(); + auto data_optional = + document_store_.GetAliveDocumentFilterData(document_id); + if (!data_optional) { + // Ran into some error retrieving information on this hit, skip + continue; + } + + // Guaranteed that the DocumentFilterData exists at this point + SchemaTypeId schema_type_id = data_optional.value().schema_type_id(); + bool valid_match = false; + auto itr = property_defined_types.find(schema_type_id); + if (itr != property_defined_types.end()) { + valid_match = itr->second; + } else { + for (const auto& property : target_properties_) { + if (schema_store_.IsPropertyDefinedInSchema(schema_type_id, property)) { + valid_match = true; + break; + } + } + property_defined_types[schema_type_id] = valid_match; + } + + if (valid_match) { + doc_hit_info_ = delegate_->doc_hit_info(); + hit_intersect_section_ids_mask_ = + delegate_->hit_intersect_section_ids_mask(); + doc_hit_info_.set_hit_section_ids_mask(hit_intersect_section_ids_mask_); + return libtextclassifier3::Status::OK; + } + + // The document's schema does not define any properties listed in + // target_properties_. Continue. + } + + // Didn't find anything on the delegate iterator. + return absl_ports::ResourceExhaustedError("No more DocHitInfos in iterator"); +} + +libtextclassifier3::StatusOr<DocHitInfoIterator::TrimmedNode> +DocHitInfoIteratorPropertyInSchema::TrimRightMostNode() && { + // Don't generate suggestion if the last operator is this custom function. + return absl_ports::InvalidArgumentError( + "Cannot generate suggestion if the last term is hasPropertyDefined()."); +} + +int32_t DocHitInfoIteratorPropertyInSchema::GetNumBlocksInspected() const { + return delegate_->GetNumBlocksInspected(); +} + +int32_t DocHitInfoIteratorPropertyInSchema::GetNumLeafAdvanceCalls() const { + return delegate_->GetNumLeafAdvanceCalls(); +} + +std::string DocHitInfoIteratorPropertyInSchema::ToString() const { + return absl_ports::StrCat("(", absl_ports::StrJoin(target_properties_, ","), + "): ", delegate_->ToString()); +} + +} // namespace lib +} // namespace icing |