aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/queryeval/fake_searchable.h
blob: 822cf439ad637503fd92e79d5694d9f44b31668d (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
// Copyright 2016 Yahoo Inc. 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 <string>
#include <map>

namespace search {
namespace queryeval {

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

    vespalib::string _tag;
    Map         _map;

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;
    }

    /**
     * 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;
    Blueprint::UP createBlueprint(const IRequestContext & requestContext,
                                  const FieldSpec &field,
                                  const search::query::Node &term) override;
    ~FakeSearchable();
};

} // namespace search::queryeval
} // namespace search