Search in sources :

Example 16 with Choice

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

the class PageTemplateXMLReadingTestCase method assertCorrectIncluder.

protected void assertCorrectIncluder(PageTemplate page) {
    assertNotNull("'includer' was read", page);
    Resolution resolution = new DeterministicResolver().resolve(Choice.createSingleton(page), null, null);
    Section case1 = (Section) page.getSection().elements(Section.class).get(0);
    assertCorrectHeader((Section) case1.elements(Section.class).get(0));
    assertCorrectFooter((Section) case1.elements(Section.class).get(1));
    Section case2 = (Section) page.getSection().elements(Section.class).get(1);
    assertCorrectHeader((Section) ((Choice) case2.elements(Section.class).get(0)).get(0).get(0));
    assertCorrectFooter((Section) ((Choice) case2.elements(Section.class).get(0)).get(1).get(0));
    assertEquals(1, resolution.getResolution((Choice) case2.elements(Section.class).get(0)));
    Section case3 = (Section) page.getSection().elements(Section.class).get(2);
    assertCorrectHeader((Section) ((Choice) case3.elements(Section.class).get(0)).get(0).get(0));
    assertCorrectFooter((Section) ((Choice) case3.elements(Section.class).get(0)).get(1).get(0));
    assertEquals(1, resolution.getResolution((Choice) case3.elements(Section.class).get(0)));
    Section case4 = (Section) page.getSection().elements(Section.class).get(3);
    assertEquals("first", ((Section) ((Choice) case4.elements(Section.class).get(0)).get(0).get(0)).getId());
    assertCorrectHeader((Section) ((Choice) case4.elements(Section.class).get(0)).get(1).get(0));
    assertEquals("middle", ((Section) ((Choice) case4.elements(Section.class).get(0)).get(2).get(0)).getId());
    assertCorrectFooter((Section) ((Choice) case4.elements(Section.class).get(0)).get(3).get(0));
    assertEquals("last", ((Section) ((Choice) case4.elements(Section.class).get(0)).get(4).get(0)).getId());
    assertEquals(4, resolution.getResolution((Choice) case4.elements(Section.class).get(0)));
    Section case5 = (Section) page.getSection().elements(Section.class).get(4);
    assertEquals(2, ((Choice) case5.elements(Section.class).get(0)).alternatives().size());
    assertCorrectHeader((Section) ((Choice) case5.elements(Section.class).get(0)).get(0).get(0));
    assertEquals("second", ((Section) ((Choice) case5.elements(Section.class).get(0)).get(1).get(0)).getId());
    assertEquals(1, resolution.getResolution((Choice) case5.elements(Section.class).get(0)));
    // This case - a choice inside a choice - makes little sense. It is included as a reminder -
    // what we really want is to be able to include some additional alternatives of a choice,
    // but without any magic. That requires allowing alternative as a top-level tag, or something
    Section case6 = (Section) page.getSection().elements(Section.class).get(5);
    Choice includerChoice = (Choice) case6.elements().get(0);
    Choice includedChoice = (Choice) includerChoice.alternatives().get(0).get(0);
    assertCorrectFooter((Section) includedChoice.alternatives().get(0).get(0));
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) Section(com.yahoo.search.pagetemplates.model.Section) Resolution(com.yahoo.search.pagetemplates.engine.Resolution)

Example 17 with Choice

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

the class PageTemplateXMLReadingTestCase method assertCorrectRichSerp.

protected void assertCorrectRichSerp(PageTemplate page) {
    assertNotNull("'rich serp' was read", page);
    Section rootSection = page.getSection();
    assertNotNull(rootSection);
    assertEquals("mainAndRight", rootSection.getLayout().getName());
    Section main = (Section) rootSection.elements(Section.class).get(0);
    assertEquals("row", main.getLayout().getName());
    assertEquals("main", main.getRegion());
    Section leftMain = (Section) main.elements(Section.class).get(0);
    assertEquals("column", leftMain.getLayout().getName());
    Section imageBar = (Section) leftMain.elements(Section.class).get(0);
    assertEquals("row", imageBar.getLayout().getName());
    assertEquals(5, imageBar.getMax());
    assertEquals("annealing", ((Choice) imageBar.elements(Source.class).get(0)).getMethod().toString());
    assertEquals("images", ((Source) ((Choice) imageBar.elements(Source.class).get(0)).alternatives().get(0).get(0)).getName());
    assertEquals("flickr", ((Source) ((Choice) imageBar.elements(Source.class).get(0)).alternatives().get(1).get(0)).getName());
    Section richElement = (Section) leftMain.elements(Section.class).get(1);
    assertEquals(1, richElement.getMax());
    assertEquals("[source 'local', source 'map', source 'video', source 'ticker', source 'weather']", richElement.elements(Source.class).toString());
    Section webResults = (Section) leftMain.elements(Section.class).get(2);
    assertEquals("-[rank]", webResults.getOrder().toString());
    assertEquals(10, webResults.getMax());
    assertEquals("[source 'web', source 'news']", webResults.elements(Source.class).toString());
    Section rightMain = (Section) main.elements(Section.class).get(1);
    assertEquals("column", rightMain.getLayout().getName());
    assertEquals("+[source]", rightMain.getOrder().toString());
    assertEquals("[source 'answers', source 'blogs', source 'twitter']", rightMain.elements(Source.class).toString());
    Section right = (Section) rootSection.elements(Section.class).get(1);
    assertEquals("column", right.getLayout().getName());
    assertEquals("right", right.getRegion());
    assertEquals("ads", ((Source) right.elements(Source.class).get(0)).getName());
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) Section(com.yahoo.search.pagetemplates.model.Section) Source(com.yahoo.search.pagetemplates.model.Source)

Example 18 with Choice

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

the class ChoiceOfTwoSourcesTestCase method testExecution.

@Test
public void testExecution() {
    // Create the page template
    Choice page = Choice.createSingleton(importPage("ChoiceOfTwoSources.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
    Resolver resolver = new DeterministicResolver();
    Resolution resolution = resolver.resolve(page, query, result);
    assertEquals(1, resolution.getResolution((Choice) ((PageTemplate) page.get(0).get(0)).getSection().elements(Source.class).get(0)));
    // Execute
    Organizer organizer = new Organizer();
    organizer.organize(page, resolution, result);
    // Check execution:
    // No subsections: Last choice (source2) used
    assertEqualHitGroups(createHits("source2", 3), result.hits());
    // Check rendering
    assertRendered(result, "ChoiceOfTwoSourcesResult.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) Test(org.junit.Test)

Example 19 with Choice

use of com.yahoo.search.pagetemplates.model.Choice 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)

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