aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/uca/ucafunctionnode.h
blob: e8deaa4beff8bac560a6343f5ce78e91dc838a52 (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
54
55
56
57
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/searchlib/expression/unaryfunctionnode.h>
#include <vespa/searchlib/common/sortspec.h>
#include <vespa/searchlib/expression/stringresultnode.h>
#include <vespa/searchlib/expression/resultvector.h>


namespace search::expression {

class UcaFunctionNode : public UnaryFunctionNode
{
public:
    DECLARE_EXPRESSIONNODE(UcaFunctionNode);
    DECLARE_NBO_SERIALIZE;
    UcaFunctionNode();
    ~UcaFunctionNode() override;
    UcaFunctionNode(ExpressionNode::UP arg, const vespalib::string & locale, const vespalib::string & strength);
    UcaFunctionNode(const UcaFunctionNode & rhs);
    UcaFunctionNode & operator = (const UcaFunctionNode & rhs);
private:
    bool onExecute() const override;
    void onPrepareResult() override;
    class Handler {
    public:
        Handler(const UcaFunctionNode & uca);
        virtual ~Handler() = default;
        virtual void handle(const ResultNode & arg) = 0;
    protected:
        void handleOne(const ResultNode & arg, RawResultNode & result) const;
    private:
        const common::BlobConverter & _converter;
        char                          _backingBuffer[32];
        vespalib::BufferRef           _buffer;
    };
    class SingleValueHandler : public Handler {
    public:
        SingleValueHandler(UcaFunctionNode & uca) : Handler(uca), _result(static_cast<RawResultNode &>(uca.updateResult())) { }
        void handle(const ResultNode & arg) override;
    private:
        RawResultNode & _result;
    };
    class MultiValueHandler : public Handler {
    public:
        MultiValueHandler(UcaFunctionNode & uca) : Handler(uca), _result(static_cast<RawResultNodeVector &>(uca.updateResult())) { }
        void handle(const ResultNode & arg) override;
    private:
        RawResultNodeVector & _result;
    };
    vespalib::string          _locale;
    vespalib::string          _strength;
    common::BlobConverter::SP _collator;
    std::unique_ptr<Handler>    _handler;
};

}