aboutsummaryrefslogtreecommitdiffstats
path: root/streamingvisitors/src/vespa/searchvisitor/indexenvironment.cpp
blob: 25c8d982f0f079b4260ef8b48dc416ed7da069ba (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "indexenvironment.h"
#include <vespa/searchlib/fef/i_ranking_assets_repo.h>

using namespace search::fef;

namespace streaming {

IndexEnvironment::IndexEnvironment(const ITableManager & tableManager) :
    _tableManager(&tableManager),
    _properties(),
    _fields(),
    _fieldNames(),
    _motivation(RANK),
    _ranking_assets_repo()
{
}

IndexEnvironment::IndexEnvironment(const IndexEnvironment &) = default;
IndexEnvironment::IndexEnvironment(IndexEnvironment &&) noexcept = default;
IndexEnvironment::~IndexEnvironment() = default;

bool
IndexEnvironment::addField(const vespalib::string& name,
                           bool isAttribute,
                           search::fef::FieldInfo::DataType data_type)
{
    if (getFieldByName(name) != nullptr) {
        return false;
    }
    FieldInfo info(isAttribute ? FieldType::ATTRIBUTE : FieldType::INDEX,
                   FieldInfo::CollectionType::SINGLE, name, _fields.size());
    info.set_data_type(data_type);
    info.addAttribute(); // we are able to produce needed attributes at query time
    _fields.push_back(info);
    _fieldNames[info.name()] = info.id();
    return true;
}

void
IndexEnvironment::set_ranking_assets_repo(std::shared_ptr<const IRankingAssetsRepo> ranking_assets_repo)
{
    _ranking_assets_repo = std::move(ranking_assets_repo);
}

vespalib::eval::ConstantValue::UP
IndexEnvironment::getConstantValue(const vespalib::string& name) const
{
    return _ranking_assets_repo->getConstant(name);
}

vespalib::string
IndexEnvironment::getRankingExpression(const vespalib::string& name) const
{
    return _ranking_assets_repo->getExpression(name);
}

const search::fef::OnnxModel*
IndexEnvironment::getOnnxModel(const vespalib::string& name) const
{
    return _ranking_assets_repo->getOnnxModel(name);
}

}