aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp
blob: bdd64f4c938cce9e64901e32abed5600895d1434 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "equiv_blueprint.h"
#include "equivsearch.h"
#include <vespa/vespalib/objects/visit.hpp>

namespace search {
namespace queryeval {

EquivBlueprint::EquivBlueprint(const FieldSpecBaseList &fields,
                               fef::MatchDataLayout subtree_mdl)
    : ComplexLeafBlueprint(fields),
      _fields(fields),
      _estimate(),
      _layout(subtree_mdl),
      _terms(),
      _exactness()
{
}

EquivBlueprint::~EquivBlueprint()
{
}

SearchIterator::UP
EquivBlueprint::createLeafSearch(const search::fef::TermFieldMatchDataArray &outputs,
                                 bool strict) const
{
    fef::MatchData::UP md = _layout.createMatchData();
    MultiSearch::Children children(_terms.size());
    search::fef::TermMatchDataMerger::Inputs childMatch;
    for (size_t i = 0; i < _terms.size(); ++i) {
        const State &childState = _terms[i]->getState();
        for (size_t j = 0; j < childState.numFields(); ++j) {
            childMatch.emplace_back(childState.field(j).resolve(*md), _exactness[i]);
        }
        children[i] = _terms[i]->createSearch(*md, strict).release();
    }
    return SearchIterator::UP(EquivSearch::create(children, std::move(md), childMatch, outputs, strict));
}

void
EquivBlueprint::visitMembers(vespalib::ObjectVisitor &visitor) const
{
    LeafBlueprint::visitMembers(visitor);
    visit(visitor, "terms", _terms);
}

void
EquivBlueprint::fetchPostings(bool strict)
{
    for (size_t i = 0; i < _terms.size(); ++i) {
        _terms[i]->fetchPostings(strict);
    }
}

EquivBlueprint&
EquivBlueprint::addTerm(Blueprint::UP term, double exactness)
{
    const State &childState = term->getState();

    HitEstimate childEst = childState.estimate();
    if (_terms.empty() || _estimate < childEst  ) {
        _estimate = childEst;
    }
    setEstimate(_estimate);
    _terms.push_back(std::move(term));
    _exactness.push_back(exactness);
    return *this;
}


} // namespace queryeval
} // namespace search