Search in sources :

Example 11 with Group

use of com.yahoo.search.grouping.result.Group in project vespa by vespa-engine.

the class JsonRendererTestCase method testGrouping.

@Test
public void testGrouping() throws InterruptedException, ExecutionException, IOException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"children\": [\n" + "                    {\n" + "                        \"children\": [\n" + "                            {\n" + "                                \"fields\": {\n" + "                                    \"count()\": 7\n" + "                                },\n" + "                                \"value\": \"Jones\",\n" + "                                \"id\": \"group:string:Jones\",\n" + "                                \"relevance\": 1.0\n" + "                            }\n" + "                        ],\n" + "                        \"continuation\": {\n" + "                            \"next\": \"CCCC\",\n" + "                            \"prev\": \"BBBB\"\n" + "                        },\n" + "                        \"id\": \"grouplist:customer\",\n" + "                        \"label\": \"customer\",\n" + "                        \"relevance\": 1.0\n" + "                    }\n" + "                ],\n" + "                \"continuation\": {\n" + "                    \"this\": \"AAAA\"\n" + "                },\n" + "                \"id\": \"group:root:0\",\n" + "                \"relevance\": 1.0\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 1\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Result r = newEmptyResult();
    RootGroup rg = new RootGroup(0, new Continuation() {

        @Override
        public String toString() {
            return "AAAA";
        }
    });
    GroupList gl = new GroupList("customer");
    gl.continuations().put("prev", new Continuation() {

        @Override
        public String toString() {
            return "BBBB";
        }
    });
    gl.continuations().put("next", new Continuation() {

        @Override
        public String toString() {
            return "CCCC";
        }
    });
    Group g = new Group(new StringId("Jones"), new Relevance(1.0));
    g.setField("count()", Integer.valueOf(7));
    gl.add(g);
    rg.add(gl);
    r.hits().add(rg);
    r.setTotalHitCount(1L);
    String summary = render(r);
    assertEqualJson(expected, summary);
}
Also used : Relevance(com.yahoo.search.result.Relevance) Group(com.yahoo.search.grouping.result.Group) RootGroup(com.yahoo.search.grouping.result.RootGroup) HitGroup(com.yahoo.search.result.HitGroup) Continuation(com.yahoo.search.grouping.Continuation) GroupList(com.yahoo.search.grouping.result.GroupList) StringId(com.yahoo.search.grouping.result.StringId) JSONString(com.yahoo.prelude.hitfield.JSONString) RootGroup(com.yahoo.search.grouping.result.RootGroup) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 12 with Group

use of com.yahoo.search.grouping.result.Group in project vespa by vespa-engine.

the class JsonRendererTestCase method testGroupingWithBucket.

@Test
public void testGroupingWithBucket() throws InterruptedException, ExecutionException, IOException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"children\": [\n" + "                    {\n" + "                        \"children\": [\n" + "                            {\n" + "                                \"fields\": {\n" + "                                    \"something()\": 7\n" + "                                },\n" + "                                \"limits\": {\n" + "                                    \"from\": \"1.0\",\n" + "                                    \"to\": \"2.0\"\n" + "                                },\n" + "                                \"id\": \"group:double_bucket:1.0:2.0\",\n" + "                                \"relevance\": 1.0\n" + "                            }\n" + "                        ],\n" + "                        \"id\": \"grouplist:customer\",\n" + "                        \"label\": \"customer\",\n" + "                        \"relevance\": 1.0\n" + "                    }\n" + "                ],\n" + "                \"continuation\": {\n" + "                    \"this\": \"AAAA\"\n" + "                },\n" + "                \"id\": \"group:root:0\",\n" + "                \"relevance\": 1.0\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 1\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Result r = newEmptyResult();
    RootGroup rg = new RootGroup(0, new Continuation() {

        @Override
        public String toString() {
            return "AAAA";
        }
    });
    GroupList gl = new GroupList("customer");
    Group g = new Group(new DoubleBucketId(1.0, 2.0), new Relevance(1.0));
    g.setField("something()", Integer.valueOf(7));
    gl.add(g);
    rg.add(gl);
    r.hits().add(rg);
    r.setTotalHitCount(1L);
    String summary = render(r);
    assertEqualJson(expected, summary);
}
Also used : Relevance(com.yahoo.search.result.Relevance) Group(com.yahoo.search.grouping.result.Group) RootGroup(com.yahoo.search.grouping.result.RootGroup) HitGroup(com.yahoo.search.result.HitGroup) Continuation(com.yahoo.search.grouping.Continuation) GroupList(com.yahoo.search.grouping.result.GroupList) JSONString(com.yahoo.prelude.hitfield.JSONString) RootGroup(com.yahoo.search.grouping.result.RootGroup) DoubleBucketId(com.yahoo.search.grouping.result.DoubleBucketId) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 13 with Group

use of com.yahoo.search.grouping.result.Group 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 14 with Group

use of com.yahoo.search.grouping.result.Group in project vespa by vespa-engine.

the class UniqueGroupingSearcherTestCase method makeHitGroup.

private static Group makeHitGroup(String name) {
    Group ein = new Group(new StringId(name), new Relevance(0));
    HitList hits = new HitList(UniqueGroupingSearcher.LABEL_HITS);
    hits.add(new Hit(name));
    ein.add(hits);
    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) HitList(com.yahoo.search.grouping.result.HitList)

Example 15 with Group

use of com.yahoo.search.grouping.result.Group 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)

Aggregations

Group (com.yahoo.search.grouping.result.Group)17 Test (org.junit.Test)13 Query (com.yahoo.search.Query)11 Result (com.yahoo.search.Result)10 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)9 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)9 GroupList (com.yahoo.search.grouping.result.GroupList)9 Grouping (com.yahoo.searchlib.aggregation.Grouping)9 StringResultNode (com.yahoo.searchlib.expression.StringResultNode)9 Hit (com.yahoo.search.result.Hit)8 Execution (com.yahoo.search.searchchain.Execution)8 HitsAggregationResult (com.yahoo.searchlib.aggregation.HitsAggregationResult)7 MaxAggregationResult (com.yahoo.searchlib.aggregation.MaxAggregationResult)7 RootGroup (com.yahoo.search.grouping.result.RootGroup)6 MinAggregationResult (com.yahoo.searchlib.aggregation.MinAggregationResult)6 CountAggregationResult (com.yahoo.searchlib.aggregation.CountAggregationResult)5 FastHit (com.yahoo.prelude.fastsearch.FastHit)4 Relevance (com.yahoo.search.result.Relevance)4 HitList (com.yahoo.search.grouping.result.HitList)3 StringId (com.yahoo.search.grouping.result.StringId)3