aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/expression/expressiontree.h
blob: 9f7372c4a94be50a6635808d7aa71055ffe75fbf (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "expressionnode.h"
#include <vespa/vespalib/objects/objectoperation.h>
#include <vespa/vespalib/objects/objectpredicate.h>
#include <vespa/searchlib/common/hitrank.h>

namespace document {
    class DocumentType;
    class Document;
}

namespace search::attribute { class IAttributeContext; }

namespace search::expression {

class AttributeNode;
class DocumentAccessorNode;
class RelevanceNode;
class InterpolatedLookup;
class ArrayAtLookup;

struct ConfigureStaticParams {
    ConfigureStaticParams (const attribute::IAttributeContext * attrCtx,
                           const document::DocumentType * docType)
        : ConfigureStaticParams(attrCtx, docType, true)
    {}
    ConfigureStaticParams (const attribute::IAttributeContext * attrCtx,
                           const document::DocumentType * docType,
                           bool enableNesteddMultivalueGrouping)
        : _attrCtx(attrCtx),
          _docType(docType),
          _enableNestedMultivalueGrouping(enableNesteddMultivalueGrouping)
    { }
    const attribute::IAttributeContext * _attrCtx;
    const document::DocumentType * _docType;
    bool _enableNestedMultivalueGrouping;
};

class ExpressionTree : public ExpressionNode
{
public:
    DECLARE_EXPRESSIONNODE(ExpressionTree);
    class Configure : public vespalib::ObjectOperation, public vespalib::ObjectPredicate
    {
    private:
        void execute(vespalib::Identifiable &obj) override;
        bool check(const vespalib::Identifiable &obj) const override { return obj.inherits(ExpressionTree::classId); }
    };

    ExpressionTree() noexcept;
    ExpressionTree(const ExpressionNode & root);
    ExpressionTree(ExpressionNode::UP root);
    ExpressionTree(const ExpressionTree & rhs);
    ExpressionTree(ExpressionTree &&) noexcept = default;
    ~ExpressionTree();
    ExpressionTree & operator = (ExpressionNode::UP rhs);
    ExpressionTree & operator = (const ExpressionTree & rhs);
    ExpressionTree & operator = (ExpressionTree &&) noexcept = default;

    bool execute(DocId docId, HitRank rank) const;
    bool execute(const document::Document & doc, HitRank rank) const;
    const ExpressionNode * getRoot() const { return _root.get(); }
    ExpressionNode * getRoot() { return _root.get(); }
    const ResultNode * getResult() const override { return _root->getResult(); }
    friend vespalib::Serializer & operator << (vespalib::Serializer & os, const ExpressionTree & et);
    friend vespalib::Deserializer & operator >> (vespalib::Deserializer & is, ExpressionTree & et);
    void swap(ExpressionTree &);
private:
    void visitMembers(vespalib::ObjectVisitor &visitor) const override;
    void selectMembers(const vespalib::ObjectPredicate &predicate, vespalib::ObjectOperation &operation) override;
    bool onExecute() const override { return _root->execute(); }
    void onPrepare(bool preserveAccurateTypes) override;

    using AttributeNodeList = std::vector<AttributeNode *>;
    using DocumentAccessorNodeList = std::vector<DocumentAccessorNode *>;
    using RelevanceNodeList = std::vector<RelevanceNode *>;

    ExpressionNode::CP        _root;
    AttributeNodeList         _attributeNodes;
    DocumentAccessorNodeList  _documentAccessorNodes;
    RelevanceNodeList         _relevanceNodes;
};

}