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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
// 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>
#include <vespa/searchlib/fef/indexproperties.h>
#include <vespa/vespalib/stllike/hash_set.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;
}
/*
* Ensure that array and map fields are known by the index
* environment, allowing the matches features to be used with the
* sameElement query operator. FieldSearchSpecMap::buildFromConfig()
* propagates the name to field id mapping for the added virtual
* fields.
*/
void
IndexEnvironment::add_virtual_fields()
{
vespalib::hash_set<vespalib::string> vfields;
for (auto& field : _fields) {
vespalib::stringref name(field.name());
auto pos = name.rfind('.');
while (pos != vespalib::string::npos) {
name = name.substr(0, pos);
if (_fieldNames.contains(name)) {
break;
}
vfields.insert(name);
pos = name.rfind('.');
}
}
for (auto& vfield : vfields) {
FieldInfo info(FieldType::VIRTUAL, FieldInfo::CollectionType::ARRAY, vfield, _fields.size());
info.set_data_type(FieldInfo::DataType::COMBINED);
_fields.push_back(info);
_fieldNames[vfield] = info.id();
}
}
void
IndexEnvironment::fixup_fields()
{
for (auto& field : _fields) {
if (indexproperties::IsFilterField::check(_properties, field.name())) {
field.setFilter(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);
}
}
|