Search in sources :

Example 1 with Source

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());
}
Also used : Section(com.yahoo.search.pagetemplates.model.Section) Source(com.yahoo.search.pagetemplates.model.Source)

Example 2 with Source

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);
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) Resolver(com.yahoo.search.pagetemplates.engine.Resolver) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) Renderer(com.yahoo.search.pagetemplates.model.Renderer) Section(com.yahoo.search.pagetemplates.model.Section) Source(com.yahoo.search.pagetemplates.model.Source) Resolution(com.yahoo.search.pagetemplates.engine.Resolution)

Example 3 with Source

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);
    }
}
Also used : Source(com.yahoo.search.pagetemplates.model.Source)

Example 4 with Source

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);
    }
}
Also used : IntentModel(com.yahoo.search.intent.model.IntentModel) PageElement(com.yahoo.search.pagetemplates.model.PageElement) Source(com.yahoo.search.pagetemplates.model.Source)

Example 5 with Source

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();
        }
    }
}
Also used : Renderer(com.yahoo.search.pagetemplates.model.Renderer) Source(com.yahoo.search.pagetemplates.model.Source) SectionHitGroup(com.yahoo.search.pagetemplates.result.SectionHitGroup)

Aggregations

Source (com.yahoo.search.pagetemplates.model.Source)7 Section (com.yahoo.search.pagetemplates.model.Section)3 Choice (com.yahoo.search.pagetemplates.model.Choice)2 Renderer (com.yahoo.search.pagetemplates.model.Renderer)2 IntentModel (com.yahoo.search.intent.model.IntentModel)1 Resolution (com.yahoo.search.pagetemplates.engine.Resolution)1 Resolver (com.yahoo.search.pagetemplates.engine.Resolver)1 DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)1 PageElement (com.yahoo.search.pagetemplates.model.PageElement)1 SectionHitGroup (com.yahoo.search.pagetemplates.result.SectionHitGroup)1 HashSet (java.util.HashSet)1