use of com.yahoo.search.grouping.result.RootGroup in project vespa by vespa-engine.
the class GroupingRequestTestCase method requireThatResultIsFound.
@Test
public void requireThatResultIsFound() {
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(bar);
res.hits().add(new Hit("baz"));
Group grp = req.getResultGroup(res);
assertNotNull(grp);
assertSame(bar, grp);
}
use of com.yahoo.search.grouping.result.RootGroup in project vespa by vespa-engine.
the class GroupingRequestTestCase method requireThatNonGroupResultIsNull.
@Test
public void requireThatNonGroupResultIsNull() {
Query query = new Query();
GroupingRequest req = GroupingRequest.newInstance(query);
Result res = new Result(query);
RootGroup grp = newRootGroup(0);
req.setResultGroup(grp);
res.hits().add(new Hit(grp.getId().toString()));
assertNull(req.getResultGroup(res));
}
use of com.yahoo.search.grouping.result.RootGroup in project vespa by vespa-engine.
the class GroupingRequestTestCase method requireThatParallelRequestsAreSupported.
@Test
public void requireThatParallelRequestsAreSupported() {
Query query = new Query();
Result res = new Result(query);
GroupingRequest reqA = GroupingRequest.newInstance(query);
RootGroup grpA = newRootGroup(0);
reqA.setResultGroup(grpA);
res.hits().add(grpA);
GroupingRequest reqB = GroupingRequest.newInstance(query);
RootGroup grpB = newRootGroup(1);
reqB.setResultGroup(grpB);
res.hits().add(grpB);
Group grp = reqA.getResultGroup(res);
assertNotNull(grp);
assertSame(grpA, grp);
assertNotNull(grp = reqB.getResultGroup(res));
assertSame(grpB, grp);
}
use of com.yahoo.search.grouping.result.RootGroup in project vespa by vespa-engine.
the class ResultBuilder method setRequestId.
/**
* Sets the id of the {@link GroupingRequest} that this builder is creating the result for.
*
* @param requestId The id of the corresponding GroupingRequest.
* @return This, to allow chaining.
*/
public ResultBuilder setRequestId(int requestId) {
root = new RootGroup(requestId, continuation);
rootBuilder = new GroupListBuilder(ResultId.valueOf(requestId), 0, true, true);
return this;
}
use of com.yahoo.search.grouping.result.RootGroup in project vespa by vespa-engine.
the class GroupingExecutor method search.
@Override
public Result search(Query query, Execution execution) {
String error = QueryCanonicalizer.canonicalize(query);
if (error != null) {
return new Result(query, ErrorMessage.createIllegalQuery(error));
}
query.prepare();
// Retrieve grouping requests from query.
List<GroupingRequest> reqList = GroupingRequest.getRequests(query);
if (reqList.isEmpty()) {
return execution.search(query);
}
// Convert requests to Vespa style grouping.
Map<Integer, Grouping> groupingMap = new HashMap<>();
List<RequestContext> requestContextList = new LinkedList<>();
for (GroupingRequest grpRequest : reqList) {
requestContextList.add(convertRequest(query, grpRequest, groupingMap));
}
if (groupingMap.isEmpty()) {
return execution.search(query);
}
// Perform the necessary passes to execute grouping.
Result result = performSearch(query, execution, groupingMap);
// Convert Vespa style results to hits.
HitConverter hitConverter = new HitConverter(this, query);
for (RequestContext context : requestContextList) {
RootGroup group = convertResult(context, groupingMap, hitConverter);
context.request.setResultGroup(group);
result.hits().add(group);
}
return result;
}
Aggregations