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

#pragma once

#include "orsearch.h"
#include <vespa/vespalib/objects/visit.h>

namespace search::queryeval {

/**
 * A simple implementation of the Or search operation.
 **/
template <bool strict, typename Unpack>
class OrLikeSearch : public OrSearch
{
protected:
    void doSeek(uint32_t docid) override {
        const Children & children(getChildren());
        for (uint32_t i = 0; i < children.size(); ++i) {
            if (children[i]->seek(docid)) {
                setDocId(docid);
                return;
            }
        }
        if (strict) {
            uint32_t minNextId = children[0]->getDocId();
            for (uint32_t i = 1; i < children.size(); ++i) {
                if (children[i]->getDocId() < minNextId) {
                    minNextId = children[i]->getDocId();
                }
            }
            setDocId(minNextId);
        }
    }
    Trinary is_strict() const override { return strict ? Trinary::True : Trinary::False; }
    void visitMembers(vespalib::ObjectVisitor &visitor) const override {
        MultiSearch::visitMembers(visitor);
        visit(visitor, "strict", strict);
    }

public:
    /**
     * Create a new Or Search with the given children.  A strict Or
     * can assume that all children below are also strict. A
     * non-strict Or has no strictness assumptions about its children.
     *
     * @param children the search objects we are or'ing
     **/
    OrLikeSearch(Children children, const Unpack & unpacker)
      : OrSearch(std::move(children)),
        _unpacker(unpacker)
    { }
private:
    void onRemove(size_t index) override {
        _unpacker.onRemove(index);
    }
    void onInsert(size_t index) override {
        _unpacker.onInsert(index);
    }
    void doUnpack(uint32_t docid) override {
        _unpacker.unpack(docid, *this);
    }
    bool needUnpack(size_t index) const override {
        return _unpacker.needUnpack(index);
    }
    Unpack _unpacker;
};


}