1/**
2 * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15
16 * \author Haichao.chc
17 * \date Jun 2021
18 * \brief ColumnReader load column index data and provides read interfaces.
19 */
20
21#pragma once
22
23#include <thread>
24#include "index_provider.h"
25#include "../collection_dataset.h"
26#include "../collection_query.h"
27#include "../snapshot.h"
28
29namespace proxima {
30namespace be {
31namespace index {
32
33class ColumnReader;
34using ColumnReaderPtr = std::shared_ptr<ColumnReader>;
35
36using FilterFunction = std::function<bool(idx_t doc_id)>;
37
38/*
39 * ColumnReader load persist column index, and provides search interfaces.
40 */
41class ColumnReader : public IndexProvider {
42 public:
43 //! Constructor
44 ColumnReader() {
45 concurrency_ = std::thread::hardware_concurrency();
46 }
47
48 //! Destructor
49 virtual ~ColumnReader() = default;
50
51 //! Create an instance and return shared ptr
52 static ColumnReaderPtr Create(const std::string &collection_name,
53 const std::string &collection_path,
54 SegmentID segment_id,
55 const std::string &column_name,
56 IndexTypes index_type);
57
58 public:
59 //! Open snapshot on persist storage
60 virtual int open(const meta::ColumnMeta &column_meta,
61 const ReadOptions &read_options) = 0;
62
63 //! Close persist storage
64 virtual int close() = 0;
65
66
67 //! Search similar results with query
68 virtual int search(const std::string &query, const QueryParams &query_params,
69 FilterFunction filter, IndexDocumentList *result_list) = 0;
70
71 //! Batch search similar results with query
72 virtual int search(const std::string &query, const QueryParams &query_params,
73 uint32_t batch_count, FilterFunction filter,
74 std::vector<IndexDocumentList> *batch_result_list) = 0;
75
76 public:
77 //! Set concurrency
78 void set_concurrency(uint32_t val) {
79 concurrency_ = val;
80 }
81
82 //! Return concurrency
83 uint32_t concurrency() {
84 return concurrency_;
85 }
86
87 private:
88 uint32_t concurrency_{0U};
89};
90
91
92} // end namespace index
93} // namespace be
94} // end namespace proxima
95