aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/queryeval/iterator_pack.h
blob: ce0c47f088267b882a454eae9a8b613037f94d59 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "searchiterator.h"
#include <vespa/searchlib/fef/termfieldmatchdata.h>

namespace search::fef { class MatchData; }

namespace search::queryeval {

class SearchIteratorPack
{
private:
    using MatchDataUP = std::unique_ptr<fef::MatchData>;
    std::vector<SearchIterator::UP>        _children;
    std::vector<fef::TermFieldMatchData*>  _childMatch;
    MatchDataUP                            _md;

public:
    SearchIteratorPack();
    ~SearchIteratorPack();
    SearchIteratorPack(SearchIteratorPack &&rhs) noexcept;
    SearchIteratorPack &operator=(SearchIteratorPack &&rhs) noexcept;

    // TODO: use MultiSearch::Children to pass ownership
    SearchIteratorPack(const std::vector<SearchIterator*> &children,
                       const std::vector<fef::TermFieldMatchData*> &childMatch,
                       MatchDataUP md);

    // TODO: use MultiSearch::Children to pass ownership
    SearchIteratorPack(const std::vector<SearchIterator*> &children, MatchDataUP md);

    uint32_t get_docid(uint16_t ref) const {
        return _children[ref]->getDocId();
    }

    uint32_t seek(uint16_t ref, uint32_t docid) {
        _children[ref]->seek(docid);
        return _children[ref]->getDocId();
    }

    int32_t get_weight(uint16_t ref, uint32_t docid) {
        _children[ref]->doUnpack(docid);
        return _childMatch[ref]->getWeight();
    }

    void unpack(uint16_t ref, uint32_t docid) {
        _children[ref]->doUnpack(docid);
    }

    uint16_t size() const { return _children.size(); }
    void initRange(uint32_t begin, uint32_t end) {
        for (auto & child: _children) {
            child->initRange(begin, end);
        }
    }
    std::unique_ptr<BitVector> get_hits(uint32_t begin_id, uint32_t end_id) const;
    void or_hits_into(BitVector &result, uint32_t begin_id) const;
};

}