Search in sources :

Example 1 with Choice

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

the class ChoiceOfSubsectionsTestCase method testExecution.

@Test
public void testExecution() {
    // Create the page template
    Choice page = Choice.createSingleton(importPage("ChoiceOfSubsections.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));
    result.hits().add(createHits("source4", 3));
    new Organizer().organize(page, new DeterministicResolverAssertingMethod().resolve(page, query, result), result);
    // Check execution:
    // Two subsections with one source each
    assertEquals(2, result.hits().size());
    HitGroup section1 = (HitGroup) result.hits().get(0);
    HitGroup section2 = (HitGroup) result.hits().get(1);
    assertEqualHitGroups(createHits("source2", 3), section1);
    assertEqualHitGroups(createHits("source4", 3), section2);
    // Check rendering
    assertRendered(result, "ChoiceOfSubsectionsResult.xml");
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) Query(com.yahoo.search.Query) Organizer(com.yahoo.search.pagetemplates.engine.Organizer) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 2 with Choice

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

the class ChoicesTestCase method testExecution.

@Test
public void testExecution() {
    // Create the page template (second alternative will be chosen)
    List<PageElement> pages = new ArrayList<>();
    pages.add(importPage("AnySource.xml"));
    pages.add(importPage("Choices.xml"));
    Choice page = Choice.createSingletons(pages);
    // Create a federated result
    Query query = new Query();
    Result result = new Result(query);
    result.hits().add(createHits("news", 3));
    result.hits().add(createHits("web", 3));
    result.hits().add(createHits("blog", 3));
    result.hits().add(createHits("images", 3));
    // Resolve
    Resolver resolver = new DeterministicResolver();
    Resolution resolution = resolver.resolve(page, query, result);
    // Execute
    Organizer organizer = new Organizer();
    organizer.organize(page, resolution, result);
    // Check rendering
    assertRendered(result, "ChoicesResult.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) ArrayList(java.util.ArrayList) PageElement(com.yahoo.search.pagetemplates.model.PageElement) Result(com.yahoo.search.Result) Resolution(com.yahoo.search.pagetemplates.engine.Resolution) Test(org.junit.Test)

Example 3 with Choice

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

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

the class ChoiceOfRenderersTestCase method testExecution.

// This test is order dependent. Fix this!!
@Test
public void testExecution() {
    // Create the page template
    Choice page = Choice.createSingleton(importPage("ChoiceOfRenderers.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(Renderer.class).get(0)));
    assertEquals(2, resolution.getResolution((Choice) ((PageTemplate) page.get(0).get(0)).getSection().elements(Renderer.class).get(1)));
    // Execute
    Organizer organizer = new Organizer();
    organizer.organize(page, resolution, result);
    assertEquals(6, result.getConcreteHitCount());
    assertEquals(6, result.getHitCount());
    // Check rendering
    assertRendered(result, "ChoiceOfRenderersResult.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 5 with Choice

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

the class PageWithBlendingTestCase method testExecution.

@Test
public void testExecution() {
    // Create the page template
    Choice page = Choice.createSingleton(importPage("PageWithBlending.xml"));
    // Create a federated result
    Query query = new Query();
    Result result = new Result(query);
    result.hits().add(createHits("news", 2));
    result.hits().add(createHits("htmlSource", 1));
    // 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 rendering
    assertRendered(result, "PageWithBlendingResult.xml", new PageTemplateSet());
}
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) PageTemplateSet(com.yahoo.prelude.templates.PageTemplateSet) Result(com.yahoo.search.Result) Resolution(com.yahoo.search.pagetemplates.engine.Resolution) 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