use of com.yahoo.search.grouping.result.GroupList in project vespa by vespa-engine.
the class UniqueGroupingSearcher method getAllHitsFromGroupingResult.
/**
* Get all the hits returned by the grouping request. This might be more or less than the user requested.
* This method handles the results from two different types of grouping expression, depending on whether
* sorting was used for the query or not.
*
* @param resultGroups The result group of the dedup grouping request
* @return A (correctly sorted) list of all the hits returned by the grouping expression.
*/
private static List<Hit> getAllHitsFromGroupingResult(GroupList resultGroups) {
List<Hit> hits = new ArrayList<>(resultGroups.size());
for (Hit groupHit : resultGroups) {
Group group = (Group) groupHit;
GroupList sorted = group.getGroupList(LABEL_GROUPS);
if (sorted != null) {
group = (Group) sorted.iterator().next();
}
for (Hit hit : group.getHitList(LABEL_HITS)) {
hits.add(hit);
}
}
return hits;
}
use of com.yahoo.search.grouping.result.GroupList in project vespa by vespa-engine.
the class UniqueGroupingSearcherTestCase method makeSortingHitGroup.
private static Group makeSortingHitGroup(String name) {
Hit hit = new Hit(name);
HitList hits = new HitList(UniqueGroupingSearcher.LABEL_HITS);
hits.add(hit);
Group dedupGroup = new Group(new StringId(name), new Relevance(0));
dedupGroup.add(hits);
GroupList dedupedHits = new GroupList(UniqueGroupingSearcher.LABEL_GROUPS);
dedupedHits.add(dedupGroup);
Group ein = new Group(new StringId(name), new Relevance(0));
ein.add(dedupedHits);
return ein;
}
use of com.yahoo.search.grouping.result.GroupList in project vespa by vespa-engine.
the class GroupingExecutorTestCase method requireThatPassResultsAreMerged.
@Test
public void requireThatPassResultsAreMerged() {
Query query = newQuery();
GroupingRequest req = GroupingRequest.newInstance(query);
req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(output(min(bar), max(bar))))"));
Grouping grpA = new Grouping(0);
grpA.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("uniqueA")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(6)).setTag(4))).addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("common")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(9)).setTag(4))));
Grouping grpB = new Grouping(0);
grpB.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("uniqueB")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(9)).setTag(4))).addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("common")).addAggregationResult(new MinAggregationResult().setMin(new IntegerResultNode(6)).setTag(3))));
Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grpA), null), new GroupingListHit(Arrays.asList(grpB), null))));
Group grp = req.getResultGroup(exec.search(query));
assertEquals(1, grp.size());
Hit hit = grp.get(0);
assertTrue(hit instanceof GroupList);
GroupList lst = (GroupList) hit;
assertEquals(3, lst.size());
assertNotNull(hit = lst.get("group:string:uniqueA"));
assertEquals(6L, hit.getField("max(bar)"));
assertNotNull(hit = lst.get("group:string:uniqueB"));
assertEquals(9L, hit.getField("max(bar)"));
assertNotNull(hit = lst.get("group:string:common"));
assertEquals(6L, hit.getField("min(bar)"));
assertEquals(9L, hit.getField("max(bar)"));
}
Aggregations