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

#include "leafspec.h"
#include "trackedsearch.h"
#include <vespa/searchlib/fef/matchdatalayout.h>
#include <vespa/searchlib/queryeval/fake_search.h>
#include <vespa/searchlib/queryeval/searchiterator.h>
#include <vespa/searchlib/queryeval/wand/wand_parts.h>
#include <vector>

namespace search::queryeval::test {

/**
 * Defines the overall behavior of a wand like search with tracked children.
 * This struct also owns the search iterator history.
 **/
class WandSpec
{
private:
    std::vector<LeafSpec>             _leafs;
    fef::MatchDataLayout              _layout;
    std::vector<fef::TermFieldHandle> _handles;
    SearchHistory                     _history;

public:
    WandSpec() : _leafs(), _layout(), _handles(), _history() {}
    ~WandSpec() {}
    WandSpec &leaf(LeafSpec && l) {
        _leafs.emplace_back(std::move(l));
        _handles.push_back(_layout.allocTermField(0));
        return *this;
    }
    wand::Terms getTerms(fef::MatchData *matchData = NULL) {
        wand::Terms terms;
        for (size_t i = 0; i < _leafs.size(); ++i) {
            fef::TermFieldMatchData *tfmd = (matchData != NULL ? matchData->resolveTermField(_handles[i]) : NULL);
            terms.push_back(wand::Term(_leafs[i].create(_history, tfmd).release(),
                                       _leafs[i].weight,
                                       _leafs[i].result.inspect().size(),
                                       tfmd));
        }
        return terms;
    }
    SearchHistory &getHistory() { return _history; }
    fef::MatchData::UP createMatchData() const { return _layout.createMatchData(); }
};

}