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

#pragma once

#include "searchable.h"
#include "fake_result.h"
#include <vespa/vespalib/stllike/string.h>
#include <map>

namespace search::queryeval {

/**
 * A fake Searchable implementation.
 **/
class FakeSearchable : public Searchable
{
private:
    using Key = std::pair<vespalib::string, vespalib::string>;
    using Map = std::map<Key, FakeResult>;

    vespalib::string _tag;
    Map              _map;
    bool             _is_attr;

public:
    /**
     * Create an initially empty fake searchable.
     **/
    FakeSearchable();

    /**
     * Tag this searchable with a string value that will be visible
     * when dumping search iterators created from it.
     *
     * @return this object for chaining
     * @param t tag
     **/
    FakeSearchable &tag(const vespalib::string &t) {
        _tag = t;
        return *this;
    }

    /**
     * Is this searchable searching attributes? Setting this to true
     * will result in blueprints and search iterators exposing a
     * mocked attribute search context interface.
     **/
    FakeSearchable &is_attr(bool value) {
        _is_attr = value;
        return *this;
    }

    /**
     * Add a fake result to be returned for lookup on the given field
     * and term combination.
     *
     * @return this object for chaining
     * @param field field name
     * @param term search term in string form
     * @param result the fake result
     **/
    FakeSearchable &addResult(const vespalib::string &field,
                              const vespalib::string &term,
                              const FakeResult &result);

    using Searchable::createBlueprint;
    std::unique_ptr<queryeval::Blueprint>
    createBlueprint(const IRequestContext & requestContext,
                    const FieldSpec &field,
                    const search::query::Node &term) override;
    ~FakeSearchable() override;
};

}