aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Storages/MeiliSearch/SourceMeiliSearch.h
blob: 6ab24e47635196111a7b1bbb1bc7cc3349c74e36 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once

#include <cstddef>
#include <unordered_map>
#include <Core/ColumnsWithTypeAndName.h>
#include <Core/ExternalResultDescription.h>
#include <Processors/Chunk.h>
#include <Processors/ISource.h>
#include <Storages/MeiliSearch/MeiliSearchConnection.h>
#include <base/JSON.h>

namespace DB
{
class MeiliSearchSource final : public ISource
{
public:
    enum QueryRoute
    {
        search,
        documents
    };

    MeiliSearchSource(
        const MeiliSearchConfiguration & config,
        const Block & sample_block,
        UInt64 max_block_size_,
        QueryRoute route,
        std::unordered_map<String, String> query_params_);

    ~MeiliSearchSource() override;

    String getName() const override { return "MeiliSearchSource"; }

private:
    String doubleQuoteIfNeed(const String & param) const;

    String constructAttributesToRetrieve() const;

    size_t parseJSON(MutableColumns & columns, const JSON & jres) const;

    Chunk generate() override;

    MeiliSearchConnection connection;
    const UInt64 max_block_size;
    const QueryRoute route;
    ExternalResultDescription description;
    std::unordered_map<String, String> query_params;

    UInt64 offset;
    bool all_read = false;
};

}