use of com.yahoo.search.pagetemplates.model.Source in project vespa by vespa-engine.
the class PageTemplateXMLReadingTestCase method assertCorrectSerp.
protected void assertCorrectSerp(PageTemplate page) {
assertNotNull("'serp' was read", page);
Section rootSection = page.getSection();
assertNotNull(rootSection);
assertEquals("mainAndRight", rootSection.getLayout().getName());
Section main = (Section) rootSection.elements(Section.class).get(0);
assertEquals("column", main.getLayout().getName());
assertEquals("main", main.getRegion());
assertEquals("web", ((Source) main.elements(Source.class).get(0)).getName());
Section right = (Section) rootSection.elements(Section.class).get(1);
assertEquals("column", right.getLayout().getName());
assertEquals("right", right.getRegion());
assertEquals("ads", ((Source) right.elements(Source.class).get(0)).getName());
}
use of com.yahoo.search.pagetemplates.model.Source 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);
}
use of com.yahoo.search.pagetemplates.model.Source in project vespa by vespa-engine.
the class PageTemplateSearcher method addPageTemplateSources.
private void addPageTemplateSources(Set<Source> pageSources, Query query) {
for (Source pageSource : pageSources) {
if (pageSource == Source.any)
continue;
query.getModel().getSources().add(pageSource.getName());
addParameters(pageSource, query);
}
}
use of com.yahoo.search.pagetemplates.model.Source in project vespa by vespa-engine.
the class PageTemplateSearcher method addSources.
/**
* Sets query.getModel().getSources() to the right value and add source parameters specified in templates
*/
private void addSources(List<PageElement> pages, Query query) {
// Determine all wanted sources
Set<Source> pageSources = new HashSet<>();
for (PageElement page : pages) pageSources.addAll(((PageTemplate) page).getSources());
addErrorIfSameSourceMultipleTimes(pages, pageSources, query);
if (query.getModel().getSources().size() > 0) {
// Add properties if the source list is set explicitly, but do not modify otherwise
addParametersForIncludedSources(pageSources, query);
return;
}
if (pageSources.contains(Source.any)) {
IntentModel intentModel = IntentModel.getFrom(query);
if (intentModel != null) {
query.getModel().getSources().addAll(intentModel.getSourceNames());
addPageTemplateSources(pageSources, query);
}
// otherwise leave empty to search all
} else {
// Let the page templates decide
addPageTemplateSources(pageSources, query);
}
}
use of com.yahoo.search.pagetemplates.model.Source in project vespa by vespa-engine.
the class TiledTemplateSet method renderSectionContent.
protected void renderSectionContent(HitGroup hit, XMLWriter writer) throws IOException {
if (hit instanceof SectionHitGroup) {
// render additional information
SectionHitGroup sectionGroup = (SectionHitGroup) hit;
for (Source source : sectionGroup.sources()) {
writer.openTag("source").attribute("url", source.getUrl());
renderParameters(source.parameters(), writer);
writer.closeTag();
}
for (Renderer renderer : sectionGroup.renderers()) {
writer.openTag("renderer").attribute("for", renderer.getRendererFor()).attribute("name", renderer.getName());
renderParameters(renderer.parameters(), writer);
writer.closeTag();
}
}
}
Aggregations