Search in sources :

Example 6 with RootGroup

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

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

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

the class GroupingRequestTestCase method requireThatRemovedResultIsNull.

@Test
public void requireThatRemovedResultIsNull() {
    Query query = new Query();
    GroupingRequest req = GroupingRequest.newInstance(query);
    Result res = new Result(query);
    res.hits().add(new Hit("foo"));
    RootGroup bar = newRootGroup(0);
    req.setResultGroup(bar);
    res.hits().add(new Hit("baz"));
    assertNull(req.getResultGroup(res));
}
Also used : Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) RootGroup(com.yahoo.search.grouping.result.RootGroup) Result(com.yahoo.search.Result) Test(org.junit.Test)

Aggregations

RootGroup (com.yahoo.search.grouping.result.RootGroup)8 Result (com.yahoo.search.Result)7 Test (org.junit.Test)6 Query (com.yahoo.search.Query)4 Group (com.yahoo.search.grouping.result.Group)4 Hit (com.yahoo.search.result.Hit)3 JSONString (com.yahoo.prelude.hitfield.JSONString)2 Continuation (com.yahoo.search.grouping.Continuation)2 GroupList (com.yahoo.search.grouping.result.GroupList)2 HitGroup (com.yahoo.search.result.HitGroup)2 Relevance (com.yahoo.search.result.Relevance)2 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)1 DoubleBucketId (com.yahoo.search.grouping.result.DoubleBucketId)1 StringId (com.yahoo.search.grouping.result.StringId)1 Grouping (com.yahoo.searchlib.aggregation.Grouping)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1