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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "simple_phrase_blueprint.h"
#include "simple_phrase_search.h"
#include <vespa/searchlib/fef/termfieldmatchdata.h>
#include <vespa/vespalib/objects/visit.hpp>
#include <algorithm>
#include <map>
namespace search {
namespace queryeval {
SimplePhraseBlueprint::SimplePhraseBlueprint(const FieldSpec &field, const IRequestContext & requestContext)
: ComplexLeafBlueprint(field),
_doom(requestContext.getSoftDoom()),
_field(field),
_estimate(),
_layout(),
_terms()
{
}
SimplePhraseBlueprint::~SimplePhraseBlueprint()
{
while (!_terms.empty()) {
delete _terms.back();
_terms.pop_back();
}
}
FieldSpec
SimplePhraseBlueprint::getNextChildField(const FieldSpec &outer)
{
return FieldSpec(outer.getName(), outer.getFieldId(), _layout.allocTermField(outer.getFieldId()), false);
}
void
SimplePhraseBlueprint::addTerm(Blueprint::UP term)
{
const State &childState = term->getState();
assert(childState.numFields() == 1);
const FieldSpecBase &childField = childState.field(0);
assert(childField.getFieldId() == _field.getFieldId());
(void) childField;
HitEstimate childEst = childState.estimate();
if (_terms.empty() || childEst < _estimate) {
_estimate = childEst;
}
setEstimate(_estimate);
_terms.push_back(term.get());
term.release();
}
SearchIterator::UP
SimplePhraseBlueprint::createLeafSearch(const search::fef::TermFieldMatchDataArray &tfmda,
bool strict) const
{
assert(tfmda.size() == 1);
fef::MatchData::UP md = _layout.createMatchData();
search::fef::TermFieldMatchDataArray childMatch;
SimplePhraseSearch::Children children(_terms.size());
std::multimap<uint32_t, uint32_t> order_map;
for (size_t i = 0; i < _terms.size(); ++i) {
const State &childState = _terms[i]->getState();
assert(childState.numFields() == 1);
childMatch.add(childState.field(0).resolve(*md));
children[i] = _terms[i]->createSearch(*md, strict).release();
order_map.insert(std::make_pair(childState.estimate().estHits, i));
}
std::vector<uint32_t> eval_order;
for (std::multimap<uint32_t, uint32_t>::iterator
it = order_map.begin(); it != order_map.end(); ++it) {
eval_order.push_back(it->second);
}
SimplePhraseSearch * phrase = new SimplePhraseSearch(children, std::move(md), childMatch,
eval_order, *tfmda[0], strict);
phrase->setDoom(& _doom);
return SearchIterator::UP(phrase);
}
void
SimplePhraseBlueprint::fetchPostings(bool strict)
{
for (size_t i = 0; i < _terms.size(); ++i) {
_terms[i]->fetchPostings(strict);
}
}
void
SimplePhraseBlueprint::visitMembers(vespalib::ObjectVisitor &visitor) const
{
LeafBlueprint::visitMembers(visitor);
visit(visitor, "terms", _terms);
}
} // namespace search::queryeval
} // namespace search
|