Search in sources :

Example 1 with Renderer

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

the class PageTemplateXMLReadingTestCase method assertCorrectRicherSerp.

protected void assertCorrectRicherSerp(PageTemplate page) {
    assertNotNull("'richer serp' was read", page);
    // Check resolution as we go
    Resolver resolver = new DeterministicResolver();
    Resolution resolution = resolver.resolve(Choice.createSingleton(page), null, null);
    Section root = page.getSection();
    assertNotNull(root);
    assertEquals("column", root.getLayout().getName());
    assertEquals("Sections was correctly imported and combined with the section in this", 4, root.elements(Section.class).size());
    assertCorrectHeader((Section) root.elements(Section.class).get(0));
    Section body = (Section) root.elements(Section.class).get(1);
    assertEquals("mainAndRight", body.getLayout().getName());
    Section main = (Section) body.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());
    assertEquals(1, resolution.getResolution((Choice) leftMain.elements(Section.class).get(0)));
    Section imageBar = (Section) ((Choice) leftMain.elements(Section.class).get(0)).alternatives().get(0).get(0);
    assertEquals("row", imageBar.getLayout().getName());
    assertEquals(5, imageBar.getMax());
    assertEquals(2, ((Choice) imageBar.elements(Source.class).get(0)).alternatives().size());
    assertEquals("images", ((Source) ((Choice) imageBar.elements(Source.class).get(0)).alternatives().get(0).get(0)).getName());
    assertEquals(1, resolution.getResolution((Choice) imageBar.elements(Source.class).get(0)));
    assertEquals(1, resolution.getResolution((Choice) imageBar.elements(Renderer.class).get(0)));
    Source flickrSource = (Source) ((Choice) imageBar.elements(Source.class).get(0)).alternatives().get(1).get(0);
    assertEquals("flickr", flickrSource.getName());
    assertEquals(1, flickrSource.renderers().size());
    assertEquals("mouseOverImage", ((Renderer) flickrSource.renderers().get(0)).getName());
    Source twitpicSource = (Source) ((Choice) imageBar.elements(Source.class).get(0)).alternatives().get(1).get(1);
    assertEquals("twitpic", twitpicSource.getName());
    assertEquals(1, twitpicSource.parameters().size());
    assertEquals("origin=twitter", twitpicSource.parameters().get("filter"));
    assertEquals(2, ((Choice) twitpicSource.renderers().get(0)).alternatives().size());
    assertEquals(1, resolution.getResolution((Choice) twitpicSource.renderers().get(0)));
    Renderer mouseOverImageRenderer = (Renderer) ((Choice) twitpicSource.renderers().get(0)).alternatives().get(0).get(0);
    assertEquals("mouseOverImage", mouseOverImageRenderer.getName());
    assertEquals(2, mouseOverImageRenderer.parameters().size());
    assertEquals("5", mouseOverImageRenderer.parameters().get("hovertime"));
    assertEquals("#ff00ff", mouseOverImageRenderer.parameters().get("borderColor"));
    assertEquals("regularImage", ((Renderer) ((Choice) twitpicSource.renderers().get(0)).alternatives().get(1).get(0)).getName());
    assertEquals(2, ((Choice) imageBar.elements(Renderer.class).get(0)).alternatives().size());
    assertEquals("regularImageBox", ((Renderer) ((Choice) imageBar.elements(Renderer.class).get(0)).alternatives().get(0).get(0)).getName());
    assertEquals("newImageBox", ((Renderer) ((Choice) imageBar.elements(Renderer.class).get(0)).alternatives().get(1).get(0)).getName());
    Section richElement = (Section) ((Choice) leftMain.elements(Section.class).get(0)).get(0).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) ((Choice) leftMain.elements(Section.class).get(0)).get(1).get(0);
    assertEquals("+[source]", 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) body.elements(Section.class).get(1);
    assertEquals("column", right.getLayout().getName());
    assertEquals("right", right.getRegion());
    assertEquals("ads", ((Source) right.elements(Source.class).get(0)).getName());
    assertEquals("newAdBox", ((Renderer) right.elements(Renderer.class).get(0)).getName());
    assertEquals("-[rank] +clickProbability", right.getOrder().toString());
    assertCorrectFooter((Section) root.elements(Section.class).get(2));
    assertEquals("extraFooter", ((Section) root.elements(Section.class).get(3)).getId());
    // Check getSources()
    assertCorrectSources("ads answers blogs flickr global images local map news notifications " + "popularSearches ticker topArticles twitpic twitter video weather web", page);
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) Resolver(com.yahoo.search.pagetemplates.engine.Resolver) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) Renderer(com.yahoo.search.pagetemplates.model.Renderer) Section(com.yahoo.search.pagetemplates.model.Section) Source(com.yahoo.search.pagetemplates.model.Source) Resolution(com.yahoo.search.pagetemplates.engine.Resolution)

Example 2 with Renderer

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

the class TiledTemplateSet method renderSectionContent.

protected void renderSectionContent(HitGroup hit, XMLWriter writer) throws IOException {
    if (hit instanceof SectionHitGroup) {
        // render additional information
        SectionHitGroup sectionGroup = (SectionHitGroup) hit;
        for (Source source : sectionGroup.sources()) {
            writer.openTag("source").attribute("url", source.getUrl());
            renderParameters(source.parameters(), writer);
            writer.closeTag();
        }
        for (Renderer renderer : sectionGroup.renderers()) {
            writer.openTag("renderer").attribute("for", renderer.getRendererFor()).attribute("name", renderer.getName());
            renderParameters(renderer.parameters(), writer);
            writer.closeTag();
        }
    }
}
Also used : Renderer(com.yahoo.search.pagetemplates.model.Renderer) Source(com.yahoo.search.pagetemplates.model.Source) SectionHitGroup(com.yahoo.search.pagetemplates.result.SectionHitGroup)

Aggregations

Renderer (com.yahoo.search.pagetemplates.model.Renderer)2 Source (com.yahoo.search.pagetemplates.model.Source)2 Resolution (com.yahoo.search.pagetemplates.engine.Resolution)1 Resolver (com.yahoo.search.pagetemplates.engine.Resolver)1 DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)1 Choice (com.yahoo.search.pagetemplates.model.Choice)1 Section (com.yahoo.search.pagetemplates.model.Section)1 SectionHitGroup (com.yahoo.search.pagetemplates.result.SectionHitGroup)1