diff options
author | Yogesh Singh <yosing@google.com> | 2023-08-05 21:06:22 +0000 |
---|---|---|
committer | Yogesh Singh <yosing@google.com> | 2023-08-07 22:59:47 +0000 |
commit | 7edd8a42d2ad4b80e95557a7e4c615f97450b968 (patch) | |
tree | 7e8ce2a244cf50de9ead16fea57297e0b3d3316f /icing/index/iterator/doc-hit-info-iterator-section-restrict.h | |
parent | f8a8e6c2e2b55900e082d2657f3691ee6d9b2d27 (diff) | |
download | icing-7edd8a42d2ad4b80e95557a7e4c615f97450b968.tar.gz |
Update Icing from upstream.
Descriptions:
========================================================================
Add join test for SetSchemaNewIndexedDocumentPropertyTriggersIndexRestorationAndReturnsOk
========================================================================
Support different sets of properties to search for different schema types.
========================================================================
Do not cache the section mask for a schema type if no property filters apply while processing the type property filters.
========================================================================
Bug: 288310393
Bug: 291019114
Change-Id: Icb867b40a603c0d63e2d96a0e2ec641e424aad7e
Diffstat (limited to 'icing/index/iterator/doc-hit-info-iterator-section-restrict.h')
-rw-r--r-- | icing/index/iterator/doc-hit-info-iterator-section-restrict.h | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/icing/index/iterator/doc-hit-info-iterator-section-restrict.h b/icing/index/iterator/doc-hit-info-iterator-section-restrict.h index 58dd120..5d44ed7 100644 --- a/icing/index/iterator/doc-hit-info-iterator-section-restrict.h +++ b/icing/index/iterator/doc-hit-info-iterator-section-restrict.h @@ -19,10 +19,13 @@ #include <memory> #include <string> #include <string_view> +#include <unordered_map> #include "icing/text_classifier/lib3/utils/base/status.h" #include "icing/index/iterator/doc-hit-info-iterator.h" #include "icing/schema/schema-store.h" +#include "icing/schema/section.h" +#include "icing/store/document-filter-data.h" #include "icing/store/document-store.h" namespace icing { @@ -44,6 +47,12 @@ class DocHitInfoIteratorSectionRestrict : public DocHitInfoIterator { const DocumentStore* document_store, const SchemaStore* schema_store, std::set<std::string> target_sections, int64_t current_time_ms); + explicit DocHitInfoIteratorSectionRestrict( + std::unique_ptr<DocHitInfoIterator> delegate, + const DocumentStore* document_store, const SchemaStore* schema_store, + const SearchSpecProto& search_spec, + int64_t current_time_ms); + libtextclassifier3::Status Advance() override; libtextclassifier3::StatusOr<TrimmedNode> TrimRightMostNode() && override; @@ -72,12 +81,51 @@ class DocHitInfoIteratorSectionRestrict : public DocHitInfoIterator { } private: + explicit DocHitInfoIteratorSectionRestrict( + std::unique_ptr<DocHitInfoIterator> delegate, + const DocumentStore* document_store, const SchemaStore* schema_store, + std::unordered_map<std::string, std::set<std::string>> + type_property_filters, + std::unordered_map<std::string, SectionIdMask> type_property_masks, + int64_t current_time_ms); + // Calculates the section mask of allowed sections(determined by the property + // filters map) for the given schema type and caches the same for any future + // calls. + // + // Returns: + // - If type_property_filters_ has an entry for the given schema type or + // wildcard(*), return a bitwise or of section IDs in the schema type that + // that are also present in the relevant filter list. + // - Otherwise, return kSectionIdMaskAll. + SectionIdMask ComputeAndCacheSchemaTypeAllowedSectionsMask( + const std::string& schema_type); + // Generates a section mask for the given schema type and the target sections. + // + // Returns: + // - A bitwise or of section IDs in the schema_type that that are also + // present in the target_sections list. + // - If none of the sections in the schema_type are present in the + // target_sections list, return kSectionIdMaskNone. + // This is done by doing a bitwise or of the target section ids for the given + // schema type. + SectionIdMask GenerateSectionMask(const std::string& schema_type, + const std::set<std::string>& + target_sections) const; + std::unique_ptr<DocHitInfoIterator> delegate_; const DocumentStore& document_store_; const SchemaStore& schema_store_; - - std::set<std::string> target_sections_; int64_t current_time_ms_; + + // Map of property filters per schema type. Supports wildcard(*) for schema + // type that will apply to all schema types that are not specifically + // specified in the mapping otherwise. + std::unordered_map<std::string, std::set<std::string>> + type_property_filters_; + // Mapping of schema type to the section mask of allowed sections for that + // schema type. This section mask is lazily calculated based on the specified + // property filters and cached for any future use. + std::unordered_map<std::string, SectionIdMask> type_property_masks_; }; } // namespace lib |