aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/engine/searchreply.h
blob: 2a0cb59f5aca150872d0489954d92a31e9078fc7 (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
75
76
77
78
79
80
81
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "searchrequest.h"
#include <vespa/document/base/globalid.h>
#include <vespa/searchlib/common/hitrank.h>
#include <vespa/searchlib/common/unique_issues.h>
#include <vespa/vespalib/util/array.h>
#include <vespa/vespalib/util/featureset.h>
#include <vector>

namespace search::engine {

class Coverage {
public:
    Coverage() noexcept : Coverage(0) { }
    explicit Coverage(uint64_t active) noexcept : Coverage(active, active) { }
    Coverage(uint64_t active, uint64_t covered) noexcept
        : _covered(covered), _active(active), _targetActive(active),
          _degradeReason(0)
    { }
    uint64_t getCovered() const { return _covered; }
    uint64_t getActive() const { return _active; }
    uint64_t getTargetActive() const { return _targetActive; }

    bool wasDegradedByMatchPhase() const { return ((_degradeReason & MATCH_PHASE) != 0); }
    bool wasDegradedByTimeout() const { return ((_degradeReason & TIMEOUT) != 0); }

    Coverage & setCovered(uint64_t v) { _covered = v; return *this; }
    Coverage & setActive(uint64_t v) { _active = v; return *this; }
    Coverage & setTargetActive(uint64_t v) { _targetActive = v; return *this; }

    Coverage & degradeMatchPhase() { _degradeReason |= MATCH_PHASE; return *this; }
    Coverage & degradeTimeout() { _degradeReason |= TIMEOUT; return *this; }
    enum DegradeReason {MATCH_PHASE=0x01, TIMEOUT=0x02};
private:
    uint64_t _covered;
    uint64_t _active;
    uint64_t _targetActive;
    uint32_t _degradeReason;
};

class SearchReply
{
public:
    using FeatureValues = vespalib::FeatureValues;
    using UP = std::unique_ptr<SearchReply>;

    class Hit
    {
    public:
        Hit() noexcept : gid(), metric(0) {}
        document::GlobalId gid;
        search::HitRank    metric;
    };

private:
    uint32_t              _distributionKey;
public:
    uint64_t              totalHitCount;
    std::vector<uint32_t> sortIndex;
    std::vector<char>     sortData;
    vespalib::Array<char> groupResult;
    Coverage              coverage;
    std::vector<Hit>      hits;
    FeatureValues         match_features;
    PropertiesMap         propertiesMap;

    SearchRequest::UP     request;
    UniqueIssues::UP      my_issues;

    SearchReply();
    ~SearchReply();
    SearchReply(const SearchReply &rhs); // for test only

    void setDistributionKey(uint32_t key) { _distributionKey = key; }
    uint32_t getDistributionKey() const { return _distributionKey; }
};

}