Search in sources :

Example 11 with Choice

use of com.yahoo.search.pagetemplates.model.Choice in project vespa by vespa-engine.

the class TwoSectionsFourSourcesTestCase method testExecutionMissingOneSource.

@Test
public void testExecutionMissingOneSource() {
    // Create the page template
    Choice page = Choice.createSingleton(importPage("TwoSectionsFourSources.xml"));
    // Create a federated result
    Query query = new Query();
    Result result = new Result(query);
    result.hits().add(createHits("source1", 3));
    result.hits().add(createHits("source3", 12));
    result.hits().add(createHits("source4", 13));
    new Organizer().organize(page, new DeterministicResolver().resolve(page, query, result), result);
    // Check execution:
    // Two subsections with two sources each, the first grouped the second blended
    assertEquals(2, result.hits().size());
    HitGroup section1 = (HitGroup) result.hits().get(0);
    HitGroup section2 = (HitGroup) result.hits().get(1);
    assertGroupedSource3Source1(section1.asList());
    assertEqualHitGroups(createHits("source4", 10), section2);
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) Query(com.yahoo.search.Query) Organizer(com.yahoo.search.pagetemplates.engine.Organizer) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 12 with Choice

use of com.yahoo.search.pagetemplates.model.Choice in project vespa by vespa-engine.

the class TwoSectionsFourSourcesTestCase method testExecution.

@Test
public void testExecution() {
    // Create the page template
    Choice page = Choice.createSingleton(importPage("TwoSectionsFourSources.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", 12));
    result.hits().add(createHits("source4", 13));
    new Organizer().organize(page, new DeterministicResolver().resolve(page, query, result), result);
    // Check execution:
    // Two subsections with two sources each, the first grouped the second blended
    assertEquals(2, result.hits().size());
    HitGroup section1 = (HitGroup) result.hits().get(0);
    HitGroup section2 = (HitGroup) result.hits().get(1);
    assertGroupedSource3Source1(section1.asList());
    assertBlendedSource4Source2(section2.asList());
    // Check rendering
    assertRendered(result, "TwoSectionsFourSourcesResult.xml");
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) Query(com.yahoo.search.Query) Organizer(com.yahoo.search.pagetemplates.engine.Organizer) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 13 with Choice

use of com.yahoo.search.pagetemplates.model.Choice in project vespa by vespa-engine.

the class PageTemplateSearcher method search.

@Override
public Result search(Query query, Execution execution) {
    // Pre execution: Choose template and sources
    List<PageElement> pages = selectPageTemplates(query);
    // Bypass if no page template chosen
    if (pages.isEmpty())
        return execution.search(query);
    addSources(pages, query);
    // Set the page template list for inspection by other searchers
    query.properties().set(pagePageTemplateListName, pages);
    // Execute
    Result result = execution.search(query);
    // Post execution: Resolve choices and organize the result as dictated by the resolved template
    Choice pageTemplateChoice = Choice.createSingletons(pages);
    Resolution resolution = selectResolver(query).resolve(pageTemplateChoice, query, result);
    organizer.organize(pageTemplateChoice, resolution, result);
    return result;
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) PageElement(com.yahoo.search.pagetemplates.model.PageElement) Result(com.yahoo.search.Result) Resolution(com.yahoo.search.pagetemplates.engine.Resolution)

Example 14 with Choice

use of com.yahoo.search.pagetemplates.model.Choice in project vespa by vespa-engine.

the class AnySourceTestCase method testExecution.

@Test
public void testExecution() {
    // Create the page template
    Choice page = Choice.createSingleton(importPage("AnySource.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", 3));
    result.hits().add(createHits("source3", 3));
    // Resolve (noop here)
    Resolver resolver = new DeterministicResolver();
    Resolution resolution = resolver.resolve(page, query, result);
    // Execute
    Organizer organizer = new Organizer();
    organizer.organize(page, resolution, result);
    // Check execution:
    // all three sources, ordered by relevance, source 3 first in each relevance group
    HitGroup hits = result.hits();
    assertEquals(9, hits.size());
    assertEquals("source3-1", hits.get(0).getId().stringValue());
    assertEquals("source1-1", hits.get(1).getId().stringValue());
    assertEquals("source2-1", hits.get(2).getId().stringValue());
    assertEquals("source3-2", hits.get(3).getId().stringValue());
    assertEquals("source1-2", hits.get(4).getId().stringValue());
    assertEquals("source2-2", hits.get(5).getId().stringValue());
    assertEquals("source3-3", hits.get(6).getId().stringValue());
    assertEquals("source1-3", hits.get(7).getId().stringValue());
    assertEquals("source2-3", hits.get(8).getId().stringValue());
    // Check rendering
    assertRendered(result, "AnySourceResult.xml");
}
Also used : 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) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) Result(com.yahoo.search.Result) Resolution(com.yahoo.search.pagetemplates.engine.Resolution) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 15 with Choice

use of com.yahoo.search.pagetemplates.model.Choice in project vespa by vespa-engine.

the class MapSectionsToSectionsTestCase method testExecution.

@Test
public void testExecution() {
    // Create the page template
    Choice page = Choice.createSingleton(importPage("MapSectionsToSections.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("box1", ((Section) mapping.get("box1holder").get(0)).getId());
    assertEquals("box2", ((Section) mapping.get("box2holder").get(0)).getId());
    assertEquals("box3", ((Section) mapping.get("box3holder").get(0)).getId());
    assertEquals("box4", ((Section) mapping.get("box4holder").get(0)).getId());
    // 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 column21a = (HitGroup) row2.get(0);
    HitGroup column21b = (HitGroup) row2.get(1);
    HitGroup column22 = (HitGroup) row2.get(2);
    assertEqualHitGroups(createHits("source1", 3), column11);
    assertEqualHitGroups(createHits("source2", 4), column12);
    assertEqualHitGroups(createHits("source3", 5), column21a);
    assertEqualHitGroups(createHits("source5", 7), column21b);
    assertEqualHitGroups(createHits("source4", 6), column22);
    // Check rendering
    assertRendered(result, "MapSectionsToSectionsResult.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)

Aggregations

Choice (com.yahoo.search.pagetemplates.model.Choice)19 Result (com.yahoo.search.Result)16 DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)16 Query (com.yahoo.search.Query)15 Organizer (com.yahoo.search.pagetemplates.engine.Organizer)15 Test (org.junit.Test)15 Resolution (com.yahoo.search.pagetemplates.engine.Resolution)13 Resolver (com.yahoo.search.pagetemplates.engine.Resolver)11 HitGroup (com.yahoo.search.result.HitGroup)8 PageTemplateSet (com.yahoo.prelude.templates.PageTemplateSet)4 Section (com.yahoo.search.pagetemplates.model.Section)3 PageTemplate (com.yahoo.search.pagetemplates.PageTemplate)2 MapChoice (com.yahoo.search.pagetemplates.model.MapChoice)2 PageElement (com.yahoo.search.pagetemplates.model.PageElement)2 Source (com.yahoo.search.pagetemplates.model.Source)2 List (java.util.List)2 Renderer (com.yahoo.search.pagetemplates.model.Renderer)1 ArrayList (java.util.ArrayList)1