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 Hechong.xyf
17 * \date Oct 2019
18 * \brief Interface of AiTheta Index Reformer
19 */
20
21#ifndef __AITHETA2_INDEX_REFORMER_H__
22#define __AITHETA2_INDEX_REFORMER_H__
23
24#include "index_container.h"
25#include "index_document.h"
26
27namespace aitheta2 {
28
29/*! Index Reformer
30 */
31class IndexReformer : public IndexModule {
32 public:
33 //! Index Reformer Pointer
34 typedef std::shared_ptr<IndexReformer> Pointer;
35
36 //! Destructor
37 virtual ~IndexReformer(void) {}
38
39 //! Initialize Reformer
40 virtual int init(const IndexParams &params) = 0;
41
42 //! Cleanup Reformer
43 virtual int cleanup(void) = 0;
44
45 //! Load index from container
46 virtual int load(IndexContainer::Pointer cntr) = 0;
47
48 //! Unload index
49 virtual int unload(void) = 0;
50
51 //! Transform a query
52 virtual int transform(const void *query, const IndexQueryMeta &qmeta,
53 std::string *out, IndexQueryMeta *ometa) const = 0;
54
55 //! Transform queries
56 virtual int transform(const void *query, const IndexQueryMeta &qmeta,
57 uint32_t count, std::string *out,
58 IndexQueryMeta *ometa) const = 0;
59
60 //! Convert a record
61 virtual int convert(const void *record, const IndexQueryMeta &rmeta,
62 std::string *out, IndexQueryMeta *ometa) const {
63 return this->transform(record, rmeta, out, ometa);
64 }
65
66 //! Convert records
67 virtual int convert(const void *records, const IndexQueryMeta &rmeta,
68 uint32_t count, std::string *out,
69 IndexQueryMeta *ometa) const {
70 return this->transform(records, rmeta, count, out, ometa);
71 }
72
73 //! Normalize results
74 virtual int normalize(const void *query, const IndexQueryMeta &qmeta,
75 IndexDocumentList &result) const = 0;
76};
77
78} // namespace aitheta2
79
80#endif // __AITHETA2_INDEX_REFORMER_H__
81