Search in sources :

Example 11 with GroupList

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;
}
Also used : Group(com.yahoo.search.grouping.result.Group) Hit(com.yahoo.search.result.Hit) GroupList(com.yahoo.search.grouping.result.GroupList) ArrayList(java.util.ArrayList)

Example 12 with GroupList

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;
}
Also used : Relevance(com.yahoo.search.result.Relevance) RootGroup(com.yahoo.search.grouping.result.RootGroup) Group(com.yahoo.search.grouping.result.Group) Hit(com.yahoo.search.result.Hit) StringId(com.yahoo.search.grouping.result.StringId) GroupList(com.yahoo.search.grouping.result.GroupList) HitList(com.yahoo.search.grouping.result.HitList)

Example 13 with GroupList

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)"));
}
Also used : Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) MinAggregationResult(com.yahoo.searchlib.aggregation.MinAggregationResult) Grouping(com.yahoo.searchlib.aggregation.Grouping) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) MaxAggregationResult(com.yahoo.searchlib.aggregation.MaxAggregationResult) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) IntegerResultNode(com.yahoo.searchlib.expression.IntegerResultNode) GroupList(com.yahoo.search.grouping.result.GroupList) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) StringResultNode(com.yahoo.searchlib.expression.StringResultNode) Test(org.junit.Test)

Aggregations

GroupList (com.yahoo.search.grouping.result.GroupList)13 Test (org.junit.Test)10 Result (com.yahoo.search.Result)9 Group (com.yahoo.search.grouping.result.Group)9 Query (com.yahoo.search.Query)5 Hit (com.yahoo.search.result.Hit)5 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)4 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)4 Execution (com.yahoo.search.searchchain.Execution)4 Grouping (com.yahoo.searchlib.aggregation.Grouping)4 MaxAggregationResult (com.yahoo.searchlib.aggregation.MaxAggregationResult)4 StringResultNode (com.yahoo.searchlib.expression.StringResultNode)4 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 RootGroup (com.yahoo.search.grouping.result.RootGroup)3 HitGroup (com.yahoo.search.result.HitGroup)3 Relevance (com.yahoo.search.result.Relevance)3 MinAggregationResult (com.yahoo.searchlib.aggregation.MinAggregationResult)3 JSONString (com.yahoo.prelude.hitfield.JSONString)2 Continuation (com.yahoo.search.grouping.Continuation)2 HitList (com.yahoo.search.grouping.result.HitList)2