diff options
author | Cassie Wang <cassiewang@google.com> | 2019-12-20 15:11:45 -0800 |
---|---|---|
committer | Cassie Wang <cassiewang@google.com> | 2019-12-20 16:18:05 -0800 |
commit | 128c9db88925c8425f2ad81e1d8985461d7ba21a (patch) | |
tree | f97ee47cc99d2c162eb30a5e051c606823dfd1ec /icing/index/iterator/doc-hit-info-iterator-section-restrict.h | |
parent | 1897505cb34f3d53e848da13fafe7691c17417ea (diff) | |
download | icing-128c9db88925c8425f2ad81e1d8985461d7ba21a.tar.gz |
Port over Icing c++ code from upstream
Change-Id: Ia3981fed7e0e70589efc027d4123f306cdfbe990
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 | 67 |
1 files changed, 67 insertions, 0 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 new file mode 100644 index 0000000..f9b9b04 --- /dev/null +++ b/icing/index/iterator/doc-hit-info-iterator-section-restrict.h @@ -0,0 +1,67 @@ +// 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. + +#ifndef ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_SECTION_RESTRICT_H_ +#define ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_SECTION_RESTRICT_H_ + +#include <cstdint> +#include <memory> +#include <string> +#include <string_view> + +#include "utils/base/status.h" +#include "icing/index/iterator/doc-hit-info-iterator.h" +#include "icing/schema/schema-store.h" +#include "icing/store/document-store.h" + +namespace icing { +namespace lib { + +// A iterator that helps filter for DocHitInfos whose term was in a section +// named target_section. +// +// NOTE: This is a little different from the DocHitInfoIteratorFilter class. +// That class is meant to be applied to the root of a query tree and filter over +// all results at the end. This class is more used in the limited scope of a +// term or a small group of terms. +class DocHitInfoIteratorSectionRestrict : public DocHitInfoIterator { + public: + // Does not take any ownership, and all pointers must refer to valid objects + // that outlive the one constructed. + explicit DocHitInfoIteratorSectionRestrict( + std::unique_ptr<DocHitInfoIterator> delegate, + const DocumentStore* document_store, const SchemaStore* schema_store, + std::string_view target_section); + + libtextclassifier3::Status Advance() override; + + int32_t GetNumBlocksInspected() const override; + + int32_t GetNumLeafAdvanceCalls() const override; + + std::string ToString() const override; + + private: + std::unique_ptr<DocHitInfoIterator> delegate_; + const DocumentStore& document_store_; + const SchemaStore& schema_store_; + + // Ensure that this does not outlive the underlying string value. + std::string_view target_section_; +}; + +} // namespace lib +} // namespace icing + +#endif // ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_SECTION_RESTRICT_H_ |