Search in sources :

Example 6 with PageTemplate

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

the class PageTemplateXMLReader method readInclude.

/**
 * Reads the direct descendant elements of an include
 */
private List<PageElement> readInclude(Element element) {
    PageTemplate included = registry.getComponent(element.getAttribute("idref"));
    if (included == null)
        throw new IllegalArgumentException("Could not find page template '" + element.getAttribute("idref"));
    readPageContent(pageElementsByPageId.get(included.getId()), included);
    return included.getSection().elements(Section.class);
}
Also used : PageTemplate(com.yahoo.search.pagetemplates.PageTemplate)

Example 7 with PageTemplate

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

the class Organizer method organize.

/**
 * Organizes the given result
 *
 * @param templateChoice a choice between singleton lists of PageTemplates
 * @param resolution the resolution of (at least) the template choice and all choices contained in that template
 * @param result the result to organize
 */
public void organize(Choice templateChoice, Resolution resolution, Result result) {
    PageTemplate template = (PageTemplate) templateChoice.get(resolution.getResolution(templateChoice)).get(0);
    SectionHitGroup sectionGroup = toGroup(template.getSection(), resolution, result);
    ErrorHit errors = result.hits().getErrorHit();
    // transfer state from existing hit
    sectionGroup.setQuery(result.hits().getQuery());
    if (errors != null && errors instanceof DefaultErrorHit)
        sectionGroup.add((DefaultErrorHit) errors);
    for (Iterator<Map.Entry<String, Object>> it = result.hits().fieldIterator(); it.hasNext(); ) {
        Map.Entry<String, Object> field = it.next();
        sectionGroup.setField(field.getKey(), field.getValue());
    }
    result.setHits(sectionGroup);
}
Also used : PageTemplate(com.yahoo.search.pagetemplates.PageTemplate) Map(java.util.Map) SectionHitGroup(com.yahoo.search.pagetemplates.result.SectionHitGroup)

Example 8 with PageTemplate

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

Example 9 with PageTemplate

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

the class SourceParametersTestCase method testSourceParametersWithSourcesDeterminedByParameter.

public void testSourceParametersWithSourcesDeterminedByParameter() {
    // Create the page template
    PageTemplateRegistry pageTemplateRegistry = new PageTemplateRegistry();
    PageTemplate page = importPage("SourceParameters.xml");
    pageTemplateRegistry.register(page);
    PageTemplateSearcher s = new PageTemplateSearcher(pageTemplateRegistry);
    Query query = new Query("?query=foo&page.id=SourceParameters&model.sources=source1,source3&page.resolver=native.deterministic");
    new Execution(s, Execution.Context.createContextStub()).search(query);
    assertEquals("source1p1Value", query.properties().get("source.source1.p1"));
    assertEquals("source1p1Value", query.properties().get("source.source1.p1"));
    assertEquals("source3p1Value", query.properties().get("source.source3.p1"));
    assertEquals("We get the correct number of parameters", 3, query.properties().listProperties("source").size());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) PageTemplateSearcher(com.yahoo.search.pagetemplates.PageTemplateSearcher) Query(com.yahoo.search.Query) PageTemplate(com.yahoo.search.pagetemplates.PageTemplate) PageTemplateRegistry(com.yahoo.search.pagetemplates.PageTemplateRegistry)

Example 10 with PageTemplate

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

the class SourceParametersTestCase method importPage.

protected PageTemplate importPage(String name) {
    PageTemplate template = new PageTemplateXMLReader().readFile(root + name);
    assertNotNull("Could look up read template '" + name + "'", template);
    return template;
}
Also used : PageTemplate(com.yahoo.search.pagetemplates.PageTemplate) PageTemplateXMLReader(com.yahoo.search.pagetemplates.config.PageTemplateXMLReader)

Aggregations

PageTemplate (com.yahoo.search.pagetemplates.PageTemplate)12 Query (com.yahoo.search.Query)4 ComponentId (com.yahoo.component.ComponentId)3 PageTemplateRegistry (com.yahoo.search.pagetemplates.PageTemplateRegistry)3 Result (com.yahoo.search.Result)2 PageTemplateSearcher (com.yahoo.search.pagetemplates.PageTemplateSearcher)2 PageTemplateXMLReader (com.yahoo.search.pagetemplates.config.PageTemplateXMLReader)2 Organizer (com.yahoo.search.pagetemplates.engine.Organizer)2 Resolution (com.yahoo.search.pagetemplates.engine.Resolution)2 Resolver (com.yahoo.search.pagetemplates.engine.Resolver)2 DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)2 Choice (com.yahoo.search.pagetemplates.model.Choice)2 MapChoice (com.yahoo.search.pagetemplates.model.MapChoice)2 HitGroup (com.yahoo.search.result.HitGroup)2 Execution (com.yahoo.search.searchchain.Execution)2 List (java.util.List)2 Test (org.junit.Test)2 Element (org.w3c.dom.Element)2 NamedReader (com.yahoo.io.reader.NamedReader)1 com.yahoo.search.intent.model (com.yahoo.search.intent.model)1