Search in sources :

Example 46 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class MapSourcesToSectionsTestCase method testExecution.

@Test
public void testExecution() {
    // Create the page template
    Choice page = Choice.createSingleton(importPage("MapSourcesToSections.xml"));
    // Create a federated result
    Query query = new Query();
    Result result = new Result(query);
    result.hits().add(createHits("source1", 3));
    result.hits().add(createHits("source2", 4));
    result.hits().add(createHits("source3", 5));
    result.hits().add(createHits("source4", 6));
    result.hits().add(createHits("source5", 7));
    // Resolve
    Resolver resolver = new DeterministicResolverAssertingMethod();
    Resolution resolution = resolver.resolve(page, query, result);
    Map<String, List<PageElement>> mapping = resolution.getResolution((MapChoice) ((PageTemplate) page.get(0).get(0)).getSection().elements().get(2));
    assertNotNull(mapping);
    assertEquals("source1", ((Source) mapping.get("box1source").get(0)).getName());
    assertEquals("source2", ((Source) mapping.get("box2source").get(0)).getName());
    assertEquals("source3", ((Source) mapping.get("box3source").get(0)).getName());
    assertEquals("source4", ((Source) mapping.get("box4source").get(0)).getName());
    // Execute
    Organizer organizer = new Organizer();
    organizer.organize(page, resolution, result);
    // Check execution:
    // Two subsections, each containing two sub-subsections with one source each
    assertEquals(2, result.hits().size());
    HitGroup row1 = (HitGroup) result.hits().get(0);
    HitGroup column11 = (HitGroup) row1.get(0);
    HitGroup column12 = (HitGroup) row1.get(1);
    HitGroup row2 = (HitGroup) result.hits().get(1);
    HitGroup column21 = (HitGroup) row2.get(0);
    HitGroup column22 = (HitGroup) row2.get(1);
    assertEqualHitGroups(createHits("source1", 3), column11);
    assertEqualHitGroups(createHits("source2", 4), column12);
    assertEqualHitGroups(createHits("source3", 5), column21);
    assertEqualHitGroups(createHits("source4", 6), column22);
    // Check rendering
    assertRendered(result, "MapSourcesToSectionsResult.xml");
}
Also used : MapChoice(com.yahoo.search.pagetemplates.model.MapChoice) Choice(com.yahoo.search.pagetemplates.model.Choice) Query(com.yahoo.search.Query) Resolver(com.yahoo.search.pagetemplates.engine.Resolver) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) Organizer(com.yahoo.search.pagetemplates.engine.Organizer) PageTemplate(com.yahoo.search.pagetemplates.PageTemplate) List(java.util.List) Result(com.yahoo.search.Result) Resolution(com.yahoo.search.pagetemplates.engine.Resolution) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 47 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class HitCountTestCase method flattenAndTrim.

private HitGroup flattenAndTrim(Result result) {
    HitGroup flattenedHits = new HitGroup();
    result.setQuery(result.getQuery());
    flatten(result.hits(), flattenedHits);
    flattenedHits.trim(result.getQuery().getOffset(), result.getQuery().getHits());
    return flattenedHits;
}
Also used : HitGroup(com.yahoo.search.result.HitGroup)

Example 48 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class ResultBuilderTestCase method testNestedResult.

public void testNestedResult() {
    ResultBuilder r = new ResultBuilder();
    Result res = r.parse("file:src/test/java/com/yahoo/search/federation/vespa/test/nestedhits.xml", new Query("?query=a"));
    assertNull(res.hits().getError());
    assertEquals(3, res.hits().size());
    assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", res.hits().get(0).getField("guid").toString());
    HitGroup g1 = (HitGroup) res.hits().get(1);
    HitGroup g2 = (HitGroup) res.hits().get(2);
    assertEquals(15, g1.size());
    assertEquals("reward_for_thumb", g1.get(1).getField("id").toString());
    assertEquals(10, g2.size());
    HitGroup g3 = (HitGroup) g2.get(3);
    assertEquals("badge", g3.getTypeString());
    assertEquals(2, g3.size());
    assertEquals("badge/Topic Explorer 5", g3.get(0).getField("name").toString());
}
Also used : ResultBuilder(com.yahoo.search.federation.vespa.ResultBuilder) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup)

Aggregations

HitGroup (com.yahoo.search.result.HitGroup)48 Test (org.junit.Test)28 Result (com.yahoo.search.Result)27 Query (com.yahoo.search.Query)24 Hit (com.yahoo.search.result.Hit)21 Execution (com.yahoo.search.searchchain.Execution)11 Searcher (com.yahoo.search.Searcher)8 Organizer (com.yahoo.search.pagetemplates.engine.Organizer)8 Choice (com.yahoo.search.pagetemplates.model.Choice)8 DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)7 DefaultErrorHit (com.yahoo.search.result.DefaultErrorHit)6 Chain (com.yahoo.component.chain.Chain)5 ErrorHit (com.yahoo.search.result.ErrorHit)4 ComponentId (com.yahoo.component.ComponentId)3 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 FederationSearcher (com.yahoo.search.federation.FederationSearcher)3 Resolution (com.yahoo.search.pagetemplates.engine.Resolution)3 Resolver (com.yahoo.search.pagetemplates.engine.Resolver)3 Coverage (com.yahoo.search.result.Coverage)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3