Search in sources :

Example 1 with GroupingRequest

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

the class FastSearcherTestCase method testSinglePassGroupingIsNotForcedWithSingleNodeGroups.

@Test
public void testSinglePassGroupingIsNotForcedWithSingleNodeGroups() {
    MockDispatcher dispatcher = new MockDispatcher(ImmutableList.of(new SearchCluster.Node("host0", 123, 0), new SearchCluster.Node("host1", 123, 0)));
    FastSearcher fastSearcher = new FastSearcher(new MockBackend(), new FS4ResourcePool(1), dispatcher, 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(false, 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)

Example 2 with GroupingRequest

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

the class GroupingExecutorTestCase method requireThatHitsAreFilledWithCorrectSummary.

@Test
public void requireThatHitsAreFilledWithCorrectSummary() {
    Query query = newQuery();
    GroupingRequest req = GroupingRequest.newInstance(query);
    req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(each(output(summary(bar))) as(bar) " + "                    each(output(summary(baz))) as(baz)))"));
    Grouping pass0A = new Grouping(0);
    pass0A.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "bar"))));
    Grouping pass0B = new Grouping(1);
    pass0B.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "baz"))));
    GlobalId gid1 = new GlobalId((new DocumentId("doc:test:1")).getGlobalId());
    GlobalId gid2 = new GlobalId((new DocumentId("doc:test:2")).getGlobalId());
    Grouping pass1A = new Grouping(0);
    pass1A.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(1, gid1, 3)))));
    Grouping pass1B = new Grouping(1);
    pass1B.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "baz").addHit(new com.yahoo.searchlib.aggregation.FS4Hit(4, gid2, 6)))));
    SummaryMapper sm = new SummaryMapper();
    Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(pass0A, pass0B), null), new GroupingListHit(Arrays.asList(pass1A, pass1B), null))), sm);
    exec.fill(exec.search(query), "default");
    assertEquals(2, sm.hitsBySummary.size());
    List<Hit> lst = sm.hitsBySummary.get("bar");
    assertNotNull(lst);
    assertEquals(1, lst.size());
    Hit hit = lst.get(0);
    assertTrue(hit instanceof FastHit);
    assertEquals(1, ((FastHit) hit).getPartId());
    assertEquals(gid1, ((FastHit) hit).getGlobalId());
    assertNotNull(lst = sm.hitsBySummary.get("baz"));
    assertNotNull(lst);
    assertEquals(1, lst.size());
    hit = lst.get(0);
    assertTrue(hit instanceof FastHit);
    assertEquals(4, ((FastHit) hit).getPartId());
    assertEquals(gid2, ((FastHit) hit).getGlobalId());
}
Also used : Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) DocumentId(com.yahoo.document.DocumentId) Grouping(com.yahoo.searchlib.aggregation.Grouping) GlobalId(com.yahoo.document.GlobalId) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) 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) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) StringResultNode(com.yahoo.searchlib.expression.StringResultNode) Test(org.junit.Test)

Example 3 with GroupingRequest

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

the class GroupingExecutorTestCase method requireThatHitsAreAttachedToCorrectQuery.

@Test
public void requireThatHitsAreAttachedToCorrectQuery() {
    Query queryA = newQuery();
    GroupingRequest req = GroupingRequest.newInstance(queryA);
    req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(each(output(summary(bar)))))"));
    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 HitsAggregationResult(1, "bar"))));
    GroupingListHit pass0 = new GroupingListHit(Arrays.asList(grp), null);
    GlobalId gid = new GlobalId((new DocumentId("doc:test:1")).getGlobalId());
    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 HitsAggregationResult(1, "bar").addHit(new com.yahoo.searchlib.aggregation.FS4Hit(4, gid, 6)))));
    GroupingListHit pass1 = new GroupingListHit(Arrays.asList(grp), null);
    Query queryB = newQuery();
    /**
     * required by {@link GroupingListHit#getSearchQuery()}
     */
    pass1.setQuery(queryB);
    QueryMapper qm = new QueryMapper();
    Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(pass0, pass1)), qm);
    exec.fill(exec.search(queryA));
    assertEquals(1, qm.hitsByQuery.size());
    assertTrue(qm.hitsByQuery.containsKey(queryB));
}
Also used : Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) DocumentId(com.yahoo.document.DocumentId) Grouping(com.yahoo.searchlib.aggregation.Grouping) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) GlobalId(com.yahoo.document.GlobalId) 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 4 with GroupingRequest

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

the class GroupingExecutorTestCase method requireThatHitsAreFilled.

@Test
public void requireThatHitsAreFilled() {
    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 FillRequestThrower());
    Result res = exec.search(query);
    // Fill with summary specified in grouping
    try {
        exec.fill(res);
        fail();
    } catch (FillRequestException e) {
        assertEquals("bar", e.summaryClass);
    }
    // Fill again, with another summary
    try {
        exec.fill(res, "otherSummary");
        fail();
    } catch (FillRequestException e) {
        assertEquals("otherSummary", e.summaryClass);
    }
}
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 5 with GroupingRequest

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

the class GroupingExecutorTestCase method requireThatErrorsAreHandled.

@Test
public void requireThatErrorsAreHandled() {
    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()))));
    ErrorProvider err = new ErrorProvider(1);
    Execution exec = newExecution(new GroupingExecutor(), err, new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grp0), null), new GroupingListHit(Arrays.asList(grp1), null))));
    Result res = exec.search(query);
    assertTrue(res.hits().getError() != null);
    assertEquals(Error.TIMEOUT.code, res.hits().getError().getCode());
    assertFalse(err.continuedOnFail);
    err = new ErrorProvider(0);
    exec = newExecution(new GroupingExecutor(), err, new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grp0), null), new GroupingListHit(Arrays.asList(grp1), null))));
    res = exec.search(query);
    assertTrue(res.hits().getError() != null);
    assertEquals(Error.TIMEOUT.code, res.hits().getError().getCode());
    assertFalse(err.continuedOnFail);
}
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)

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