Search in sources :

Example 1 with PageTemplate

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

the class ExecutionAbstractTestCase method importPage.

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

Example 2 with PageTemplate

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

the class PageTemplateSearcherTestCase method createPageTemplateRegistry.

private PageTemplateRegistry createPageTemplateRegistry() {
    PageTemplateRegistry registry = new PageTemplateRegistry();
    PageTemplate twoSources = new PageTemplate(new ComponentId("default"));
    twoSources.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source1"));
    twoSources.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source2"));
    registry.register(twoSources);
    PageTemplate oneSource = new PageTemplate(new ComponentId("oneSource"));
    oneSource.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source1"));
    registry.register(oneSource);
    PageTemplate threeSources = new PageTemplate(new ComponentId("threeSources"));
    threeSources.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source1"));
    threeSources.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source2"));
    threeSources.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source3"));
    registry.register(threeSources);
    PageTemplate twoSourcesAndAny = new PageTemplate(new ComponentId("twoSourcesAndAny"));
    twoSourcesAndAny.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source1"));
    twoSourcesAndAny.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source2"));
    twoSourcesAndAny.getSection().elements().add(com.yahoo.search.pagetemplates.model.Source.any);
    registry.register(twoSourcesAndAny);
    PageTemplate anySource = new PageTemplate(new ComponentId("anySource"));
    anySource.getSection().elements().add(com.yahoo.search.pagetemplates.model.Source.any);
    registry.register(anySource);
    PageTemplate choiceOfSources = new PageTemplate(new ComponentId("choiceOfSources"));
    List<PageElement> alternatives = new ArrayList<>();
    alternatives.add(new com.yahoo.search.pagetemplates.model.Source("source1"));
    alternatives.add(new com.yahoo.search.pagetemplates.model.Source("source2"));
    choiceOfSources.getSection().elements().add(Choice.createSingletons(alternatives));
    registry.register(choiceOfSources);
    registry.freeze();
    return registry;
}
Also used : PageTemplate(com.yahoo.search.pagetemplates.PageTemplate) PageTemplateRegistry(com.yahoo.search.pagetemplates.PageTemplateRegistry) com.yahoo.search.intent.model(com.yahoo.search.intent.model) PageElement(com.yahoo.search.pagetemplates.model.PageElement) ComponentId(com.yahoo.component.ComponentId)

Example 3 with PageTemplate

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

the class Resolver method resolve.

/**
 * Override this to resolve choices. Before retuning this method <i>must</i> resolve the given choice
 * between a set of page templates <i>and</i> all choices found recursively within the <i>chosen</i>
 * page template. It is permissible but not required to add solutions also to choices present within those
 * templates which are not chosen.
 * <p>
 * This default implementation creates a Resolution and calls
 * <code>resolve(choice/mapChoice,query,result,resolution)</code> first on the given page template choice, then
 * on each choice found in that temnplate. This provides a simple API to resolvers which make each choice
 * independently.
 *
 * @param pageTemplate the choice of page templates to resolve - a choice containing singleton lists of PageTemplate elements
 * @param query the query, from which information useful for correct resolution can be found
 * @param result the result, from which further information useful for correct resolution can be found
 * @return the resolution of the choices contained in the given page template
 */
public Resolution resolve(Choice pageTemplate, Query query, Result result) {
    Resolution resolution = new Resolution();
    resolve(pageTemplate, query, result, resolution);
    PageTemplate chosenPageTemplate = (PageTemplate) pageTemplate.get(resolution.getResolution(pageTemplate)).get(0);
    ChoiceResolverVisitor choiceResolverVisitor = new ChoiceResolverVisitor(query, result, resolution);
    chosenPageTemplate.accept(choiceResolverVisitor);
    return choiceResolverVisitor.getResolution();
}
Also used : PageTemplate(com.yahoo.search.pagetemplates.PageTemplate)

Example 4 with PageTemplate

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

the class PageTemplateXMLReader method createPages.

private Map<ComponentId, Element> createPages(List<NamedReader> pageReaders, boolean validateReaderNames) {
    Map<ComponentId, Element> pageElementsByPageId = new LinkedHashMap<>();
    for (NamedReader reader : pageReaders) {
        Element pageElement = XML.getDocument(reader).getDocumentElement();
        if (!pageElement.getNodeName().equals("page")) {
            logger.info("Ignoring '" + reader.getName() + "': Expected XML root element 'page' but was '" + pageElement.getNodeName() + "'");
            continue;
        }
        String idString = pageElement.getAttribute("id");
        if (idString == null || idString.isEmpty())
            throw new IllegalArgumentException("Page template '" + reader.getName() + "' has no 'id' attribute in the root element");
        ComponentId id = new ComponentId(idString);
        if (validateReaderNames)
            validateFileName(reader.getName(), id, "page template");
        registry.register(new PageTemplate(id));
        pageElementsByPageId.put(id, pageElement);
    }
    return pageElementsByPageId;
}
Also used : PageTemplate(com.yahoo.search.pagetemplates.PageTemplate) Element(org.w3c.dom.Element) NamedReader(com.yahoo.io.reader.NamedReader) ComponentId(com.yahoo.component.ComponentId)

Example 5 with PageTemplate

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

the class PageTemplateXMLReader method readPages.

private void readPages() {
    for (Map.Entry<ComponentId, Element> pageElement : pageElementsByPageId.entrySet()) {
        try {
            PageTemplate page = registry.getComponent(pageElement.getValue().getAttribute("id"));
            readPageContent(pageElement.getValue(), page);
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Could not read page template '" + pageElement.getKey() + "'", e);
        }
    }
}
Also used : PageTemplate(com.yahoo.search.pagetemplates.PageTemplate) Element(org.w3c.dom.Element) ComponentId(com.yahoo.component.ComponentId)

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