Search in sources :

Example 21 with Grouping

use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.

the class GroupingExecutorTestCase method requireThatPassRequestsSingleLevel.

@Test
public void requireThatPassRequestsSingleLevel() {
    Query query = newQuery();
    GroupingRequest req = GroupingRequest.newInstance(query);
    req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(output(max(bar))))"));
    GroupingCollector clt = new GroupingCollector();
    newExecution(new GroupingExecutor(), clt).search(query);
    assertEquals(2, clt.lst.size());
    Grouping grp = clt.lst.get(0);
    assertEquals(0, grp.getFirstLevel());
    assertEquals(0, grp.getLastLevel());
    grp = clt.lst.get(1);
    assertEquals(1, grp.getFirstLevel());
    assertEquals(1, grp.getLastLevel());
}
Also used : Query(com.yahoo.search.Query) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) Grouping(com.yahoo.searchlib.aggregation.Grouping) Test(org.junit.Test)

Example 22 with Grouping

use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.

the class GroupingExecutorTestCase method requireThatUnfilledHitsRenderError.

@Test
public void requireThatUnfilledHitsRenderError() throws IOException {
    Query query = newQuery();
    GroupingRequest req = GroupingRequest.newInstance(query);
    req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(each(output(summary(bar)))))"));
    Grouping grp0 = new Grouping(0);
    grp0.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "bar"))));
    Grouping grp1 = new Grouping(0);
    grp1.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "bar").addHit(new com.yahoo.searchlib.aggregation.FS4Hit()))));
    Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grp0), null), new GroupingListHit(Arrays.asList(grp1), null))), new FillErrorProvider());
    Result res = exec.search(query);
    exec.fill(res);
    assertNotNull(res.hits().getError());
}
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) 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) Execution(com.yahoo.search.searchchain.Execution) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) StringResultNode(com.yahoo.searchlib.expression.StringResultNode) Test(org.junit.Test)

Example 23 with Grouping

use of com.yahoo.searchlib.aggregation.Grouping 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)

Example 24 with Grouping

use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.

the class VdsVisitorTestCase method buildQuery.

private Query buildQuery(QueryArguments qa) throws Exception {
    StringBuilder queryString = new StringBuilder();
    queryString.append("/?query=").append(qa.query);
    if (qa.timeout != 5) {
        queryString.append("&timeout=").append(qa.timeout);
    }
    if (qa.offset != 0) {
        queryString.append("&offset=").append(qa.offset);
    }
    if (qa.hits != 10) {
        queryString.append("&hits=").append(qa.hits);
    }
    if (qa.traceLevel != 0) {
        queryString.append("&tracelevel=").append(qa.traceLevel);
    }
    if (qa.summary != null) {
        queryString.append("&summary=").append(qa.summary);
    }
    if (qa.profile != null) {
        queryString.append("&ranking.profile=").append(qa.profile);
    }
    if (qa.location != null) {
        queryString.append("&location=").append(qa.location);
    }
    if (qa.sortSpec != null) {
        queryString.append("&sorting=").append(URLEncoder.encode(qa.sortSpec, "UTF-8"));
    }
    if (qa.rankProperties != null) {
        queryString.append("&").append(qa.rankProperties);
    }
    if (qa.userId != null) {
        queryString.append("&streaming.userid=").append(qa.userId);
    }
    if (qa.groupName != null) {
        queryString.append("&streaming.groupname=").append(qa.groupName);
    }
    if (qa.selection != null) {
        queryString.append("&streaming.selection=").append(URLEncoder.encode(qa.selection, "UTF-8"));
    }
    if (qa.headersOnly) {
        queryString.append("&streaming.headersonly=").append(qa.headersOnly);
    }
    if (qa.from != 0) {
        queryString.append("&streaming.fromtimestamp=").append(qa.from);
    }
    if (qa.to != 0) {
        queryString.append("&streaming.totimestamp=").append(qa.to);
    }
    if (qa.loadTypeName != null) {
        queryString.append("&streaming.loadtype=").append(qa.loadTypeName);
    }
    if (qa.priority != null) {
        queryString.append("&streaming.priority=").append(qa.priority);
    }
    if (qa.ordering != null) {
        queryString.append("&streaming.ordering=").append(URLEncoder.encode(qa.ordering, "UTF-8"));
    }
    if (qa.maxBucketsPerVisitor != 0) {
        queryString.append("&streaming.maxbucketspervisitor=").append(qa.maxBucketsPerVisitor);
    }
    // System.out.println("query string="+queryString.toString());
    Query query = new Query(queryString.toString());
    if (qa.defineGrouping) {
        List<Grouping> groupingList = new ArrayList<>();
        groupingList.add(new Grouping());
        query.properties().set(GroupingExecutor.class.getName() + ".GroupingList", groupingList);
    }
    return query;
}
Also used : Query(com.yahoo.search.Query) ArrayList(java.util.ArrayList) Grouping(com.yahoo.searchlib.aggregation.Grouping)

Aggregations

Grouping (com.yahoo.searchlib.aggregation.Grouping)24 Query (com.yahoo.search.Query)12 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)12 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)11 Test (org.junit.Test)11 Group (com.yahoo.search.grouping.result.Group)9 StringResultNode (com.yahoo.searchlib.expression.StringResultNode)9 Result (com.yahoo.search.Result)8 Execution (com.yahoo.search.searchchain.Execution)8 HitsAggregationResult (com.yahoo.searchlib.aggregation.HitsAggregationResult)7 MaxAggregationResult (com.yahoo.searchlib.aggregation.MaxAggregationResult)7 MinAggregationResult (com.yahoo.searchlib.aggregation.MinAggregationResult)6 FastHit (com.yahoo.prelude.fastsearch.FastHit)5 Hit (com.yahoo.search.result.Hit)5 CountAggregationResult (com.yahoo.searchlib.aggregation.CountAggregationResult)5 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)4 GroupList (com.yahoo.search.grouping.result.GroupList)4 BufferSerializer (com.yahoo.vespa.objects.BufferSerializer)4 DocumentId (com.yahoo.document.DocumentId)2 GlobalId (com.yahoo.document.GlobalId)2