Search in sources :

Example 6 with GroupList

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

the class GroupingExecutorTestCase method requireThatUnexpectedGroupingResultsAreIgnored.

@Test
public void requireThatUnexpectedGroupingResultsAreIgnored() {
    Query query = newQuery();
    GroupingRequest req = GroupingRequest.newInstance(query);
    req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(output(max(bar))))"));
    Grouping grpExpected = new Grouping(0);
    grpExpected.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("expected")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(69)).setTag(3))));
    Grouping grpUnexpected = new Grouping(1);
    grpUnexpected.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("unexpected")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(96)).setTag(3))));
    Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grpExpected), null), new GroupingListHit(Arrays.asList(grpUnexpected), 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(1, lst.size());
    assertNotNull(hit = lst.get("group:string:expected"));
    assertEquals(69L, hit.getField("max(bar)"));
    assertNull(lst.get("group:string:unexpected"));
}
Also used : Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) 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)

Example 7 with GroupList

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

the class GroupingExecutorTestCase method requireThatGroupRelevanceCanBeSynthesized.

@Test
public void requireThatGroupRelevanceCanBeSynthesized() {
    Query query = newQuery();
    GroupingRequest req = GroupingRequest.newInstance(query);
    req.setRootOperation(GroupingOperation.fromString("all(group(foo) order(count()) each(output(count())))"));
    Grouping grp = new Grouping(0);
    grp.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new CountAggregationResult(1)).addOrderBy(new AggregationRefNode(0), true)).addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("bar")).addAggregationResult(new CountAggregationResult(2)).addOrderBy(new AggregationRefNode(0), true)));
    Result res = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grp), null), new GroupingListHit(Arrays.asList(grp), null)))).search(query);
    GroupList groupList = (GroupList) req.getResultGroup(res).get(0);
    assertEquals(1.0, groupList.get(0).getRelevance().getScore(), 1E-6);
    assertEquals(0.5, groupList.get(1).getRelevance().getScore(), 1E-6);
}
Also used : Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) Grouping(com.yahoo.searchlib.aggregation.Grouping) AggregationRefNode(com.yahoo.searchlib.expression.AggregationRefNode) Result(com.yahoo.search.Result) HitsAggregationResult(com.yahoo.searchlib.aggregation.HitsAggregationResult) CountAggregationResult(com.yahoo.searchlib.aggregation.CountAggregationResult) MinAggregationResult(com.yahoo.searchlib.aggregation.MinAggregationResult) MaxAggregationResult(com.yahoo.searchlib.aggregation.MaxAggregationResult) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) GroupList(com.yahoo.search.grouping.result.GroupList) CountAggregationResult(com.yahoo.searchlib.aggregation.CountAggregationResult) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) StringResultNode(com.yahoo.searchlib.expression.StringResultNode) Test(org.junit.Test)

Example 8 with GroupList

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

the class GroupingExecutorTestCase method requireThatDefaultSummaryNameFillsHitsWithNull.

@Test
public void requireThatDefaultSummaryNameFillsHitsWithNull() {
    Query query = newQuery();
    GroupingRequest req = GroupingRequest.newInstance(query);
    req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(each(output(summary()))) as(foo))"));
    Grouping pass0 = new Grouping(0);
    pass0.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, ExpressionConverter.DEFAULT_SUMMARY_NAME))));
    Grouping pass1 = new Grouping(0);
    pass1.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, ExpressionConverter.DEFAULT_SUMMARY_NAME).addHit(new com.yahoo.searchlib.aggregation.FS4Hit()))));
    Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(pass0), null), new GroupingListHit(Arrays.asList(pass1), null))));
    Result res = exec.search(query);
    exec.fill(res);
    Hit hit = ((HitList) ((Group) ((GroupList) req.getResultGroup(res).get(0)).get(0)).get(0)).get(0);
    assertTrue(hit instanceof FastHit);
    assertTrue(hit.isFilled(null));
}
Also used : Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) HitList(com.yahoo.search.grouping.result.HitList) Grouping(com.yahoo.searchlib.aggregation.Grouping) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) Result(com.yahoo.search.Result) HitsAggregationResult(com.yahoo.searchlib.aggregation.HitsAggregationResult) CountAggregationResult(com.yahoo.searchlib.aggregation.CountAggregationResult) MinAggregationResult(com.yahoo.searchlib.aggregation.MinAggregationResult) MaxAggregationResult(com.yahoo.searchlib.aggregation.MaxAggregationResult) HitsAggregationResult(com.yahoo.searchlib.aggregation.HitsAggregationResult) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) FastHit(com.yahoo.prelude.fastsearch.FastHit) GroupList(com.yahoo.search.grouping.result.GroupList) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) StringResultNode(com.yahoo.searchlib.expression.StringResultNode) Test(org.junit.Test)

Example 9 with GroupList

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

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

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