aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/fef/test/indexenvironment.cpp
blob: 0665f274e535cd6c83d3fbb7b4108636f7079c39 (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
87
88
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "indexenvironment.h"
#include <vespa/searchlib/attribute/attributefactory.h>
#include <vespa/vespalib/util/stringfmt.h>

namespace search::fef::test {

using vespalib::eval::ValueType;

IndexEnvironment::IndexEnvironment() = default;

IndexEnvironment::~IndexEnvironment() = default;
IndexEnvironment::Constant::~Constant() = default;

const FieldInfo *
IndexEnvironment::getField(uint32_t id) const
{
    return id < _fields.size() ? &_fields[id] : nullptr;
}

const FieldInfo *
IndexEnvironment::getFieldByName(const string &name) const
{
    for (const auto & field : _fields) {
        if (field.name() == name) {
            return &field;
        }
    }
    return nullptr;
}


vespalib::eval::ConstantValue::UP
IndexEnvironment::getConstantValue(const vespalib::string &name) const
{
    auto it = _constants.find(name);
    if (it != _constants.end()) {
        return std::make_unique<ConstantRef>(it->second);
    } else {
        return {nullptr};
    }
}

void
IndexEnvironment::addConstantValue(const vespalib::string &name,
                                   vespalib::eval::ValueType type,
                                   std::unique_ptr<vespalib::eval::Value> value)
{
    auto insertRes = _constants.emplace(name, Constant(std::move(type), std::move(value)));
    assert(insertRes.second); // successful insert
    (void) insertRes;
}

vespalib::string
IndexEnvironment::getRankingExpression(const vespalib::string &name) const
{
    auto pos = _expressions.find(name);
    if (pos != _expressions.end()) {
        return pos->second;
    }
    return {};
}

void
IndexEnvironment::addRankingExpression(const vespalib::string &name, const vespalib::string &value)
{
    _expressions.insert_or_assign(name, value);    
}

const OnnxModel *
IndexEnvironment::getOnnxModel(const vespalib::string &name) const
{
    auto pos = _models.find(name);
    if (pos != _models.end()) {
        return &pos->second;
    }
    return nullptr;
}

void
IndexEnvironment::addOnnxModel(OnnxModel model)
{
    _models.insert_or_assign(model.name(), std::move(model));
}


}