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;
}
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;
}
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();
}
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;
}
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);
}
}
}
Aggregations