aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/main/java/com/yahoo/searchlib/aggregation/FS4Hit.java
blob: 5bf161b380fca404951af367b34f70f84c5d6253 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.aggregation;

import com.yahoo.document.GlobalId;
import com.yahoo.vespa.objects.Deserializer;
import com.yahoo.vespa.objects.ObjectVisitor;
import com.yahoo.vespa.objects.Serializer;

/**
 * A single hit from a Vespa content cluster
 *
 * @author havardpe
 */
public class FS4Hit extends Hit {

    public static final int classId = registerClass(0x4000 + 95, FS4Hit.class); // shared with c++
    private int path = 0;
    private GlobalId globalId = new GlobalId(new byte[GlobalId.LENGTH]);
    private int distributionKey = -1;

    /** Constructs an empty result node. */
    public FS4Hit() {
    }

    /**
     * Creates a hit with the given path and document id.
     *
     * @param path     The mangled search node path.
     * @param globalId The local document id.
     * @param rank     The rank of this hit.
     */
    public FS4Hit(int path, GlobalId globalId, double rank) {
        this(path, globalId, rank, -1);
    }

    /**
     * Creates a hit with the given path and document id.
     *
     * @param path     The mangled search node path.
     * @param globalId The local document id.
     * @param rank     The rank of this hit.
     * @param distributionKey The doc stamp.
     */
    public FS4Hit(int path, GlobalId globalId, double rank, int distributionKey) {
        super(rank);
        this.path = path;
        this.globalId = globalId;
        this.distributionKey = distributionKey;
    }

    /** Returns the (mangled) network path back to the search node returning this hit. */
    public int getPath() {
        return path;
    }

    /** Returns the global document id on the search node returning this hit. */
    public GlobalId getGlobalId() {
        return globalId;
    }

    /** Returns the distribution key for the node producing this hit. */
    public int getDistributionKey() {
        return distributionKey;
    }

    @Override
    protected int onGetClassId() {
        return classId;
    }

    @Override
    protected void onSerialize(Serializer buf) {
        super.onSerialize(buf);
        buf.putInt(null, path);
        buf.put(null, globalId.getRawId());
        buf.putInt(null, distributionKey);
    }

    @Override
    protected void onDeserialize(Deserializer buf) {
        super.onDeserialize(buf);
        path = buf.getInt(null);
        globalId = new GlobalId(buf.getBytes(null, GlobalId.LENGTH));
        distributionKey = buf.getInt(null);
    }

    @Override
    public int hashCode() {
        return super.hashCode() + path + globalId.hashCode() + distributionKey;
    }

    @SuppressWarnings("RedundantIfStatement")
    @Override
    public boolean equals(Object obj) {
        if (!super.equals(obj)) {
            return false;
        }
        FS4Hit rhs = (FS4Hit)obj;
        if (path != rhs.path) {
            return false;
        }
        if (!globalId.equals(rhs.globalId)) {
            return false;
        }
        if (distributionKey != rhs.distributionKey) {
            return false;
        }
        return true;
    }

    @Override
    public void visitMembers(ObjectVisitor visitor) {
        super.visitMembers(visitor);
        visitor.visit("path", path);
        visitor.visit("globalId", globalId.toString());
        visitor.visit("distributionKey", distributionKey);
    }

}