blob: 511778501554b80551c38a0d64ac6cc03ec2771d (
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
89
90
91
92
93
94
95
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "intermediate_blueprint_factory.h"
#include <vespa/searchlib/queryeval/intermediate_blueprints.h>
#include <vespa/searchlib/attribute/singlenumericattribute.h>
#include <iomanip>
#include <sstream>
namespace search::queryeval::test {
char
IntermediateBlueprintFactory::child_name(void* blueprint) const
{
auto itr = _child_names.find(blueprint);
if (itr != _child_names.end()) {
return itr->second;
}
return '?';
}
IntermediateBlueprintFactory::IntermediateBlueprintFactory(vespalib::stringref name)
: _name(name),
_children(),
_child_names()
{
}
IntermediateBlueprintFactory::~IntermediateBlueprintFactory() = default;
std::unique_ptr<Blueprint>
IntermediateBlueprintFactory::make_blueprint()
{
auto res = make_self();
_child_names.clear();
char name = 'A';
uint32_t source = 1;
for (const auto& factory : _children) {
auto child = factory->make_blueprint();
_child_names[child.get()] = name++;
child->setSourceId(source++); // ignored by non-source-blender blueprints
res->addChild(std::move(child));
}
return res;
}
vespalib::string
IntermediateBlueprintFactory::get_name(Blueprint& blueprint) const
{
auto* intermediate = blueprint.asIntermediate();
if (intermediate != nullptr) {
std::ostringstream oss;
bool first = true;
oss << _name << "[";
for (size_t i = 0; i < intermediate->childCnt(); ++i) {
auto* child = &intermediate->getChild(i);
oss << (first ? "" : ",") << child_name(child) << ".";
if (child->strict()) {
oss << "s(" << std::setw(6) << std::setprecision(3) << child->strict_cost() << ")";
} else {
oss << "n(" << std::setw(6) << std::setprecision(3) << child->cost() << ")";
}
first = false;
}
oss << "]";
return oss.str();
}
return get_class_name(blueprint);
}
//-----------------------------------------------------------------------------
AndBlueprintFactory::AndBlueprintFactory()
: IntermediateBlueprintFactory("AND")
{}
std::unique_ptr<IntermediateBlueprint>
AndBlueprintFactory::make_self() const
{
return std::make_unique<AndBlueprint>();
}
//-----------------------------------------------------------------------------
SourceBlenderBlueprintFactory::SourceBlenderBlueprintFactory()
: IntermediateBlueprintFactory("SB"),
_selector(250, "my_source_blender", 1000)
{}
std::unique_ptr<IntermediateBlueprint>
SourceBlenderBlueprintFactory::make_self() const
{
return std::make_unique<SourceBlenderBlueprint>(_selector);
}
}
|