Search in sources :

Example 11 with DeterministicResolver

use of com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver 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 12 with DeterministicResolver

use of com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver 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 13 with DeterministicResolver

use of com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver 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 14 with DeterministicResolver

use of com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver 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)

Aggregations

DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)14 Choice (com.yahoo.search.pagetemplates.model.Choice)14 Query (com.yahoo.search.Query)12 Result (com.yahoo.search.Result)12 Organizer (com.yahoo.search.pagetemplates.engine.Organizer)12 Test (org.junit.Test)12 Resolution (com.yahoo.search.pagetemplates.engine.Resolution)10 Resolver (com.yahoo.search.pagetemplates.engine.Resolver)9 HitGroup (com.yahoo.search.result.HitGroup)5 PageTemplateSet (com.yahoo.prelude.templates.PageTemplateSet)4 Section (com.yahoo.search.pagetemplates.model.Section)2 PageElement (com.yahoo.search.pagetemplates.model.PageElement)1 Renderer (com.yahoo.search.pagetemplates.model.Renderer)1 Source (com.yahoo.search.pagetemplates.model.Source)1 ArrayList (java.util.ArrayList)1