aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/query/streaming/hit_iterator_pack.cpp
blob: ab32cd32e29b5413c0ff8757e6b6c3384d325e49 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "hit_iterator_pack.h"

namespace search::streaming {


HitIteratorPack::HitIteratorPack(const QueryNodeList& children)
    : _iterators(),
      _field_element(std::make_pair(0, 0))
{
    auto num_children = children.size();
    _iterators.reserve(num_children);
    for (auto& child : children) {
        auto& curr = dynamic_cast<const QueryTerm&>(*child);
        _iterators.emplace_back(curr.getHitList());
    }
}

HitIteratorPack::HitIteratorPack(const std::vector<std::unique_ptr<QueryTerm>>& children)
    : _iterators(),
      _field_element(std::make_pair(0, 0))
{
    auto num_children = children.size();
    _iterators.reserve(num_children);
    for (auto& child : children) {
        _iterators.emplace_back(child->getHitList());
    }
}

HitIteratorPack::~HitIteratorPack() = default;

bool
HitIteratorPack::all_valid() const noexcept
{
    if (_iterators.empty()) {
        return false;
    }
    for (auto& it : _iterators) {
        if (!it.valid()) {
            return false;
        }
    }
    return true;
}

bool
HitIteratorPack::seek_to_matching_field_element() noexcept
{
    bool retry = true;
    while (retry) {
        retry = false;
        for (auto& it : _iterators) {
            if (!it.seek_to_field_element(_field_element)) {
                return false;
            }
            auto ife = it.get_field_element();
            if (_field_element < ife) {
                _field_element = ife;
                retry = true;
                break;
            }
        }
    }
    return true;
}

}