Search in sources :

Example 6 with GroupingRequest

use of com.yahoo.search.grouping.GroupingRequest 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 GroupingRequest

use of com.yahoo.search.grouping.GroupingRequest 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 GroupingRequest

use of com.yahoo.search.grouping.GroupingRequest 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 GroupingRequest

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

Example 10 with GroupingRequest

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

the class FastSearcherTestCase method testSinglePassGroupingIsForcedWithSingleNodeGroups.

@Test
public void testSinglePassGroupingIsForcedWithSingleNodeGroups() {
    FastSearcher fastSearcher = new FastSearcher(new MockBackend(), new FS4ResourcePool(1), new MockDispatcher(new SearchCluster.Node("host0", 123, 0)), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(100, 1e64), documentdbInfoConfig);
    Query q = new Query("?query=foo");
    GroupingRequest request1 = GroupingRequest.newInstance(q);
    request1.setRootOperation(new AllOperation());
    GroupingRequest request2 = GroupingRequest.newInstance(q);
    AllOperation all = new AllOperation();
    all.addChild(new EachOperation());
    all.addChild(new EachOperation());
    request2.setRootOperation(all);
    assertForceSinglePassIs(false, q);
    fastSearcher.search(q, new Execution(Execution.Context.createContextStub()));
    assertForceSinglePassIs(true, q);
}
Also used : Query(com.yahoo.search.Query) TraceNode(com.yahoo.yolean.trace.TraceNode) EachOperation(com.yahoo.search.grouping.request.EachOperation) Execution(com.yahoo.search.searchchain.Execution) MockBackend(com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) AllOperation(com.yahoo.search.grouping.request.AllOperation) Test(org.junit.Test)

Aggregations

GroupingRequest (com.yahoo.search.grouping.GroupingRequest)22 Query (com.yahoo.search.Query)18 Test (org.junit.Test)17 Grouping (com.yahoo.searchlib.aggregation.Grouping)12 Execution (com.yahoo.search.searchchain.Execution)10 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)9 Group (com.yahoo.search.grouping.result.Group)9 StringResultNode (com.yahoo.searchlib.expression.StringResultNode)9 HitsAggregationResult (com.yahoo.searchlib.aggregation.HitsAggregationResult)8 MaxAggregationResult (com.yahoo.searchlib.aggregation.MaxAggregationResult)8 Result (com.yahoo.search.Result)7 MinAggregationResult (com.yahoo.searchlib.aggregation.MinAggregationResult)7 CountAggregationResult (com.yahoo.searchlib.aggregation.CountAggregationResult)6 FastHit (com.yahoo.prelude.fastsearch.FastHit)4 GroupList (com.yahoo.search.grouping.result.GroupList)4 Hit (com.yahoo.search.result.Hit)4 DocumentId (com.yahoo.document.DocumentId)2 GlobalId (com.yahoo.document.GlobalId)2 MockBackend (com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend)2 AllOperation (com.yahoo.search.grouping.request.AllOperation)2