Search in sources :

Example 1 with RootGroup

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);
}
Also used : RootGroup(com.yahoo.search.grouping.result.RootGroup) Group(com.yahoo.search.grouping.result.Group) 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)

Example 2 with RootGroup

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));
}
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)

Example 3 with RootGroup

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);
}
Also used : RootGroup(com.yahoo.search.grouping.result.RootGroup) Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) RootGroup(com.yahoo.search.grouping.result.RootGroup) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 4 with RootGroup

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;
}
Also used : RootGroup(com.yahoo.search.grouping.result.RootGroup)

Example 5 with RootGroup

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;
}
Also used : HashMap(java.util.HashMap) Grouping(com.yahoo.searchlib.aggregation.Grouping) RootGroup(com.yahoo.search.grouping.result.RootGroup) LinkedList(java.util.LinkedList) Result(com.yahoo.search.Result) GroupingRequest(com.yahoo.search.grouping.GroupingRequest)

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