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

#pragma once

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

namespace search::queryeval {

/**
 * Wraps an iterator for use as a filter search.
 * Owns TermFieldMatchData the wrapped iterator
 * can wire to, and write to if necessary.
 **/
class FilterWrapper : public SearchIterator {
private:
    std::vector<fef::TermFieldMatchData> _unused_md;
    fef::TermFieldMatchDataArray _tfmda;
    std::unique_ptr<SearchIterator> _wrapped_search;
public:
    FilterWrapper(size_t num_fields)
      : _unused_md(num_fields),
        _tfmda(),
        _wrapped_search()
    {
        for (size_t i = 0; i < num_fields; ++i) {
            _tfmda.add(&_unused_md[i]);
        }
    }
    const fef::TermFieldMatchDataArray& tfmda() const { return _tfmda; }
    void wrap(std::unique_ptr<SearchIterator> wrapped) {
        _wrapped_search = std::move(wrapped);
    }
    void wrap(SearchIterator *wrapped) {
        _wrapped_search.reset(wrapped);
    }
    void doSeek(uint32_t docid) override {
        _wrapped_search->seek(docid);          // use outer seek for most robustness
        setDocId(_wrapped_search->getDocId()); // propagate current iterator docid
    }
    void doUnpack(uint32_t) override {}
    void initRange(uint32_t begin_id, uint32_t end_id) override {
        SearchIterator::initRange(begin_id, end_id);
        _wrapped_search->initRange(begin_id, end_id);
        setDocId(_wrapped_search->getDocId());
    }
    void or_hits_into(BitVector &result, uint32_t begin_id) override {
        _wrapped_search->or_hits_into(result, begin_id);
    }
    void and_hits_into(BitVector &result, uint32_t begin_id) override {
        _wrapped_search->and_hits_into(result, begin_id);
    }
    BitVector::UP get_hits(uint32_t begin_id) override {
        return _wrapped_search->get_hits(begin_id);
    }
    Trinary is_strict() const override {
        return _wrapped_search->is_strict();
    }
};

} // namespace