blob: 2a1e3199d7d34d7c1cf23cdfb480b87da3abacf9 (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.grouping.result;
import com.yahoo.search.result.Hit;
import com.yahoo.search.result.HitGroup;
import com.yahoo.search.result.Relevance;
/**
* This class represents a single group in the grouping result model. A group may contain any number of results (stored
* as fields, use {@link #getField(String)} to access), {@link GroupList} and {@link HitList}. Use the {@link
* com.yahoo.search.grouping.GroupingRequest#getResultGroup(com.yahoo.search.Result)} to retrieve an instance of this.
*
* @author Simon Thoresen Hult
*/
public class Group extends HitGroup {
private static final long serialVersionUID = 2122928012157537800L;
private final GroupId groupId;
/**
* Creates a new instance of this class.
*
* @param groupId The id to assign to this group.
* @param rel The relevance of this group.
*/
public Group(GroupId groupId, Relevance rel) {
super(groupId.toString(), rel);
this.groupId = groupId;
}
/**
* Returns the id of this group. This is a model of the otherwise flattened {@link #getId() hit id}.
*
* @return The group id.
*/
public GroupId getGroupId() {
return groupId;
}
/**
* Returns the {@link HitList} with the given label. The label is the one given to the {@link
* com.yahoo.search.grouping.request.EachOperation} that generated the list. This method returns null if no such
* list was found.
*
* @param label The label of the list to return.
* @return The requested list, or null.
*/
public HitList getHitList(String label) {
for (Hit hit : this) {
if (!(hit instanceof HitList)) {
continue;
}
HitList lst = (HitList)hit;
if (!label.equals(lst.getLabel())) {
continue;
}
return lst;
}
return null;
}
/**
* Returns the {@link GroupList} with the given label. The label is the one given to the {@link
* com.yahoo.search.grouping.request.EachOperation} that generated the list. This method returns null if no such
* list was found.
*
* @param label The label of the list to return.
* @return The requested list, or null.
*/
public GroupList getGroupList(String label) {
for (Hit hit : this) {
if (!(hit instanceof GroupList)) {
continue;
}
GroupList lst = (GroupList)hit;
if (!label.equals(lst.getLabel())) {
continue;
}
return lst;
}
return null;
}
}
|