aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/matching/fakesearchcontext.h
blob: 3a9953ff9f9e390da04aa21162e4ad7bae69a9e5 (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
71
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "isearchcontext.h"
#include <vespa/searchcorespi/index/fakeindexsearchable.h>
#include <vespa/searchcorespi/index/indexcollection.h>
#include <vespa/searchlib/attribute/fixedsourceselector.h>
#include <vespa/vespalib/util/doom.h>
#include <algorithm>
#include <map>
#include <vector>

namespace vespalib { class TestClock; }
namespace proton::matching {

using searchcorespi::FakeIndexSearchable;
using searchcorespi::IndexSearchable;
using searchcorespi::IndexCollection;

class FakeSearchContext : public ISearchContext
{
public:
    using FakeSearchable = search::queryeval::FakeSearchable;

private:
    std::unique_ptr<vespalib::TestClock>   _clock;
    vespalib::Doom                         _doom;
    search::queryeval::ISourceSelector::SP _selector;
    IndexCollection::SP                    _indexes;
    FakeSearchable                         _attrSearchable;
    uint32_t                               _docIdLimit;

public:
    FakeSearchContext(size_t initialNumDocs=0);
    ~FakeSearchContext();

    FakeSearchContext &addIdx(uint32_t id) {
        _indexes->append(id, std::make_shared<FakeIndexSearchable>());
        return *this;
    }

    FakeSearchContext &setLimit(uint32_t limit) {
        _docIdLimit = limit;
        return *this;
    }

    FakeSearchable &attr() { return _attrSearchable; }

    FakeIndexSearchable &idx(uint32_t i) {
        return static_cast<FakeIndexSearchable &>(_indexes->getSearchable(i));
    }

    search::queryeval::ISourceSelector &selector() { return *_selector; }

    // Implements ISearchContext
    IndexSearchable &getIndexes() override {
        return *_indexes;
    }

    search::queryeval::Searchable &getAttributes() override {
        return _attrSearchable;
    }

    uint32_t getDocIdLimit() override {
        return _docIdLimit;
    }
    virtual const vespalib::Doom & getDoom() const { return _doom; }
};

}