aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/queryeval/test/searchhistory.h
blob: 9d4994e9d364db21224e6044b1e73ccc194a1bdd (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <cstdint>
#include <ostream>
#include <string>
#include <vector>

namespace search::queryeval::test {

/**
 * Seek and unpack history for a search iterator.
 **/
struct SearchHistory {
    struct Entry {
        std::string target;
        std::string op;
        uint32_t    docid;
        Entry(const std::string &t, const std::string &o, uint32_t id)
            : target(t), op(o), docid(id) {}
        Entry(const Entry&);
        Entry(Entry&&) noexcept = default;
        ~Entry() {}
        Entry& operator=(const Entry&);
        Entry& operator=(Entry&&) noexcept = default;
        bool operator==(const Entry &rhs) const {
            return ((target == rhs.target) &&
                    (op == rhs.op) &&
                    (docid == rhs.docid));
        }
    };
    std::vector<Entry> _entries;
    SearchHistory &seek(const std::string &target, uint32_t docid) {
        _entries.push_back(Entry(target, "seek", docid));
        return *this;
    }
    SearchHistory &step(const std::string &target, uint32_t docid) {
        _entries.push_back(Entry(target, "setDocId", docid));
        return *this;
    }
    SearchHistory &unpack(const std::string &target, uint32_t docid) {
        _entries.push_back(Entry(target, "unpack", docid));
        return *this;
    }
    bool operator==(const SearchHistory &rhs) const {
        return (_entries == rhs._entries);
    }
};

std::ostream &operator << (std::ostream &out, const SearchHistory &hist) {
    out << "History:\n";
    for (size_t i = 0; i < hist._entries.size(); ++i) {
        const SearchHistory::Entry &entry = hist._entries[i];
        out << "  " << entry.target << "->" << entry.op << "(" << entry.docid << ")" << std::endl;
    }
    return out;
}

}