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());
}
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());
}
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)"));
}
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;
}
Aggregations