aboutsummaryrefslogtreecommitdiff
path: root/icing/index/numeric/posting-list-integer-index-accessor.h
diff options
context:
space:
mode:
authorTerry Wang <tytytyww@google.com>2023-01-23 14:54:45 -0800
committerTerry Wang <tytytyww@google.com>2023-01-23 14:54:45 -0800
commitcccafab8dfcae94d7072eb49ea971e3c688bdfc4 (patch)
treec5658335e3a0287ab3a7b25a3f18585920515f75 /icing/index/numeric/posting-list-integer-index-accessor.h
parentec29b14d5a908748d6e0699df7c85842a95a7b3c (diff)
downloadicing-cccafab8dfcae94d7072eb49ea971e3c688bdfc4.tar.gz
Update Icing from upstream.
Descriptions: ====================================================================== Fix time complexity regression for snippet retriever ====================================================================== Add support for QueryTerms SectionRestrict Map in Advanced Query. ====================================================================== [NumericSearch][Storage][9/x] Create unit tests for AddKeys and GetIterator ====================================================================== [NumericSearch][Storage][8/x] Add options ====================================================================== Fix the stack overflow issue for icing advanced scoring/query parsers/visitors by limiting the number of tokens allowed ====================================================================== Improves the has joinspec check ====================================================================== Fix the bug of DocHitInfoIteratorTermMain found by monkey test ====================================================================== Rename tests defined in DestructibleDirectoryTest to include "directory" instead of "file". ====================================================================== Support projection in icing monkey test ====================================================================== [NumericSearch][Storage][7/x] Implement iterator for query ====================================================================== [NumericSearch][Storage][6/x] Implement AddKeys ====================================================================== Add support for relevance scoring by enabling term_frequency retrieval in DocHitInfoIterators and by populating the QueryTermIteratorsMap. ====================================================================== [JoinableCache][1/x] Compute SchemaDelta for joinable properties ====================================================================== [NumericSearch][Storage][5/x] PersistToDisk ====================================================================== [NumericSearch][Storage][4.1/x] Create unit tests for initialize ====================================================================== [NumericSearch][Storage][4.0/x] Implement Create and Initialize functions ====================================================================== Rename PostingListUsedSerializer related classes Bug: 193244409 Bug: 208654892 Bug: 246984163 Bug: 249829533 Bug: 256022027 Bug: 265258364 Bug: 265834832 Change-Id: Ibc7011a793ef5ed09eace0fb05d168adf5b4faca
Diffstat (limited to 'icing/index/numeric/posting-list-integer-index-accessor.h')
-rw-r--r--icing/index/numeric/posting-list-integer-index-accessor.h108
1 files changed, 108 insertions, 0 deletions
diff --git a/icing/index/numeric/posting-list-integer-index-accessor.h b/icing/index/numeric/posting-list-integer-index-accessor.h
new file mode 100644
index 0000000..64a8901
--- /dev/null
+++ b/icing/index/numeric/posting-list-integer-index-accessor.h
@@ -0,0 +1,108 @@
+// Copyright (C) 2022 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_NUMERIC_POSTING_LIST_INTEGER_INDEX_ACCESSOR_H_
+#define ICING_INDEX_NUMERIC_POSTING_LIST_INTEGER_INDEX_ACCESSOR_H_
+
+#include <cstdint>
+#include <memory>
+#include <vector>
+
+#include "icing/text_classifier/lib3/utils/base/status.h"
+#include "icing/text_classifier/lib3/utils/base/statusor.h"
+#include "icing/file/posting_list/flash-index-storage.h"
+#include "icing/file/posting_list/posting-list-accessor.h"
+#include "icing/file/posting_list/posting-list-identifier.h"
+#include "icing/file/posting_list/posting-list-used.h"
+#include "icing/index/numeric/integer-index-data.h"
+#include "icing/index/numeric/posting-list-integer-index-serializer.h"
+
+namespace icing {
+namespace lib {
+
+// TODO(b/259743562): Refactor PostingListAccessor derived classes
+
+// This class is used to provide a simple abstraction for adding integer index
+// data to posting lists. PostingListIntegerIndexAccessor handles:
+// 1) selection of properly-sized posting lists for the accumulated integer
+// index data during Finalize()
+// 2) chaining of max-sized posting lists.
+class PostingListIntegerIndexAccessor : public PostingListAccessor {
+ public:
+ // Creates an empty PostingListIntegerIndexAccessor.
+ //
+ // RETURNS:
+ // - On success, a valid instance of PostingListIntegerIndexAccessor
+ // - INVALID_ARGUMENT error if storage has an invalid block_size.
+ static libtextclassifier3::StatusOr<
+ std::unique_ptr<PostingListIntegerIndexAccessor>>
+ Create(FlashIndexStorage* storage,
+ PostingListIntegerIndexSerializer* serializer);
+
+ // Create a PostingListIntegerIndexAccessor with an existing posting list
+ // identified by existing_posting_list_id.
+ //
+ // RETURNS:
+ // - On success, a valid instance of PostingListIntegerIndexAccessor
+ // - INVALID_ARGUMENT if storage has an invalid block_size.
+ static libtextclassifier3::StatusOr<
+ std::unique_ptr<PostingListIntegerIndexAccessor>>
+ CreateFromExisting(FlashIndexStorage* storage,
+ PostingListIntegerIndexSerializer* serializer,
+ PostingListIdentifier existing_posting_list_id);
+
+ PostingListSerializer* GetSerializer() override { return serializer_; }
+
+ // Retrieve the next batch of data in the posting list chain
+ //
+ // RETURNS:
+ // - On success, a vector of integer index data in the posting list chain
+ // - INTERNAL if called on an instance that was created via Create, if
+ // unable to read the next posting list in the chain or if the posting
+ // list has been corrupted somehow.
+ libtextclassifier3::StatusOr<std::vector<IntegerIndexData>>
+ GetNextDataBatch();
+
+ // Prepend one data. This may result in flushing the posting list to disk (if
+ // the PostingListIntegerIndexAccessor holds a max-sized posting list that
+ // is full) or freeing a pre-existing posting list if it is too small to fit
+ // all data necessary.
+ //
+ // RETURNS:
+ // - OK, on success
+ // - INVALID_ARGUMENT if !data.is_valid() or if data is greater than the
+ // previously added data.
+ // - RESOURCE_EXHAUSTED error if unable to grow the index to allocate a new
+ // posting list.
+ libtextclassifier3::Status PrependData(const IntegerIndexData& data);
+
+ // TODO(b/259743562): [Optimization 1] add GetAndClear, IsFull for split
+
+ private:
+ explicit PostingListIntegerIndexAccessor(
+ FlashIndexStorage* storage,
+ std::unique_ptr<uint8_t[]> posting_list_buffer_array,
+ PostingListUsed posting_list_buffer,
+ PostingListIntegerIndexSerializer* serializer)
+ : PostingListAccessor(storage, std::move(posting_list_buffer_array),
+ std::move(posting_list_buffer)),
+ serializer_(serializer) {}
+
+ PostingListIntegerIndexSerializer* serializer_; // Does not own.
+};
+
+} // namespace lib
+} // namespace icing
+
+#endif // ICING_INDEX_NUMERIC_POSTING_LIST_INTEGER_INDEX_ACCESSOR_H_