• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_NOT_H_
16 #define ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_NOT_H_
17 
18 #include <cstdint>
19 #include <memory>
20 #include <string>
21 
22 #include "icing/text_classifier/lib3/utils/base/status.h"
23 #include "icing/index/iterator/doc-hit-info-iterator-all-document-id.h"
24 #include "icing/index/iterator/doc-hit-info-iterator.h"
25 #include "icing/store/document-id.h"
26 
27 namespace icing {
28 namespace lib {
29 
30 // Iterator that will return all documents that are *not* specified by the
31 // to_be_excluded_iterator.
32 //
33 // NOTE: The hit_intersect_section_ids_mask is meaningless for this iterator.
34 // When this iterator produces a result, it's because the Document was not
35 // present in the to_be_excluded_iterator. There is no concept of the Document
36 // having been chosen because it's term was in a specific section. Since we
37 // don't know anything about the sections for the Document, the
38 // hit_intersect_section_ids_mask is always kSectionIdMaskNone. Correspondingly,
39 // this means that the doc_hit_info.hit_section_ids_mask will also always be
40 // kSectionIdMaskNone.
41 class DocHitInfoIteratorNot : public DocHitInfoIterator {
42  public:
43   // to_be_excluded_iterator: The results of this iterator will be excluded
44   //     from this iterator's results.
45   // document_id_limit: The DocumentId that represents the most recently added
46   //     Document to the DocumentStore
47   explicit DocHitInfoIteratorNot(
48       std::unique_ptr<DocHitInfoIterator> to_be_excluded_iterator,
49       const DocumentId document_id_limit);
50 
51   libtextclassifier3::Status Advance() override;
52 
53   // The NOT operator is not suppose to be trimmed.
54   // We shouldn't generate suggestion for the last term if the last term belongs
55   // to NOT operator.
56   libtextclassifier3::StatusOr<TrimmedNode> TrimRightMostNode() && override;
57 
58   int32_t GetNumBlocksInspected() const override;
59 
60   int32_t GetNumLeafAdvanceCalls() const override;
61 
62   std::string ToString() const override;
63 
64  private:
65   std::unique_ptr<DocHitInfoIterator> to_be_excluded_;
66   DocHitInfoIteratorAllDocumentId all_document_id_iterator_;
67 };
68 
69 }  // namespace lib
70 }  // namespace icing
71 
72 #endif  // ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_NOT_H_
73