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 guonix
17 * \date Nov 2020
18 * \brief
19 */
20
21#pragma once
22
23#include "executor/bthread_task.h"
24#include "context.h"
25
26namespace proxima {
27namespace be {
28namespace query {
29
30//! Predefine class
31class KNNTask;
32
33// Alias knn task pointer
34using KNNTaskPtr = std::shared_ptr<KNNTask>;
35using KNNTaskPtrList = std::list<KNNTaskPtr>;
36
37
38/*!
39 * KNNTask
40 */
41class KNNTask : public BthreadTask {
42 public:
43 //! Constructor
44 KNNTask(index::SegmentPtr segment, KNNQueryContext *context);
45
46 //! Constructor
47 KNNTask(const std::string &name, index::SegmentPtr segment,
48 KNNQueryContext *context);
49
50 //! Destructor
51 ~KNNTask() override;
52
53 public:
54 //! Retrieve result of knn_search
55 const std::vector<index::QueryResultList> &result() const;
56
57 private:
58 //! Run search task
59 int do_run() override;
60
61 private:
62 //! Segment handle
63 index::SegmentPtr segment_{nullptr};
64
65 //! KnnQueryContext handler
66 KNNQueryContext *context_{nullptr};
67
68 //! Query Result, corresponding to the field of proto::QueryResponse
69 std::vector<index::QueryResultList> result_{};
70};
71
72
73} // namespace query
74} // namespace be
75} // namespace proxima
76