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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "rangequerylocator.h"
#include <vespa/searchlib/queryeval/intermediate_blueprints.h>
using namespace search::queryeval;
namespace proton::matching {
RangeLimitMetaInfo::RangeLimitMetaInfo()
: _valid(false),
_estimate(0),
_low(),
_high()
{}
RangeLimitMetaInfo::RangeLimitMetaInfo(vespalib::stringref low_, vespalib::stringref high_, size_t estimate_)
: _valid(true),
_estimate(estimate_),
_low(low_),
_high(high_)
{}
RangeLimitMetaInfo::~RangeLimitMetaInfo() = default;
namespace {
RangeLimitMetaInfo
locateFirst(uint32_t field_id, const Blueprint & blueprint) {
if (blueprint.isIntermediate()) {
const auto & intermediate = static_cast<const IntermediateBlueprint &>(blueprint);
if (intermediate.isAndNot()) {
return locateFirst(field_id, intermediate.getChild(0));
} else if (intermediate.isRank()) {
return locateFirst(field_id, intermediate.getChild(0));
} else if (intermediate.isAnd()) {
for (size_t i(0); i < intermediate.childCnt(); i++) {
RangeLimitMetaInfo childMeta = locateFirst(field_id, intermediate.getChild(i));
if (childMeta.valid()) {
return childMeta;
}
}
}
} else {
const Blueprint::State & state = blueprint.getState();
if (state.isTermLike() && (state.numFields() == 1) && (state.field(0).getFieldId() == field_id)) {
const LeafBlueprint &leaf = static_cast<const LeafBlueprint &>(blueprint);
vespalib::string from, too;
if (leaf.getRange(from, too)) {
return {from, too, state.estimate().estHits};
}
}
}
return {};
}
}
RangeLimitMetaInfo
LocateRangeItemFromQuery::locate() const {
return locateFirst(_field_id, _blueprint);
}
}
|