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

#pragma once

#include "searchiterator.h"
#include <vector>

class MultiSearchRemoveTest;

namespace search::queryeval {

class MultiBitVectorIteratorBase;

/**
 * A virtual intermediate class that serves as the basis for combining searches
 * like and, or any or others that take a list of children.
 **/
class MultiSearch : public SearchIterator
{
    friend class ::MultiSearchRemoveTest;
    friend class ::search::queryeval::MultiBitVectorIteratorBase;
public:
    /**
     * Defines how to represent the children iterators. vespalib::Array usage
     * generates faster and more compact code then using std::vector.
     */
    typedef std::vector<SearchIterator *> Children;
    /**
     * Create a new Multi Search with the given children.
     *
     * @param children the search objects we are and'ing
     *        this object takes ownership of the children.
     **/
    MultiSearch(const Children & children);
    virtual ~MultiSearch();
    const Children & getChildren() const { return _children; }
    virtual bool isAnd() const { return false; }
    virtual bool isAndNot() const { return false; }
    virtual bool isOr() const { return false; }
    virtual bool isRank() const { return false; }
    void insert(size_t index, SearchIterator::UP search);
    virtual bool needUnpack(size_t index) const { (void) index; return true; }
    void initRange(uint32_t beginId, uint32_t endId) override;
protected:
    void doUnpack(uint32_t docid) override;
    void visitMembers(vespalib::ObjectVisitor &visitor) const override;
private:
    SearchIterator::UP remove(size_t index); // friends only
    /**
     * Call back when children are removed / inserted after the Iterator has been constructed.
     * This is to support code that make assumptions that iterators do not move around or disappear.
     * These are invoked after the child has been removed.
     */
    virtual void onRemove(size_t index) { (void) index; }
    virtual void onInsert(size_t index) { (void) index; }

    bool isMultiSearch() const override { return true; }
    Children _children;
};

}