Search in sources :

Example 1 with SectionHitGroup

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

the class Organizer method addHitsFromSource.

private void addHitsFromSource(Source source, SectionHitGroup sectionGroup, Result result, List<String> sourceList) {
    if (source == Source.any) {
        // Add any source not added yet
        for (Hit hit : result.hits()) {
            if (!(hit instanceof HitGroup))
                continue;
            String groupId = hit.getId().stringValue();
            if (!groupId.startsWith("source:"))
                continue;
            String sourceName = groupId.substring(7);
            if (sourceList.contains(sourceName))
                continue;
            sectionGroup.addAll(((HitGroup) hit).asList());
            // Add *'ed sources explicitly
            sourceList.add(sourceName);
        }
    } else {
        HitGroup sourceGroup = (HitGroup) result.hits().get("source:" + source.getName());
        if (sourceGroup != null)
            sectionGroup.addAll(sourceGroup.asList());
        // Add even if not found - may be added later
        sourceList.add(source.getName());
    }
}
Also used : SectionHitGroup(com.yahoo.search.pagetemplates.result.SectionHitGroup)

Example 2 with SectionHitGroup

use of com.yahoo.search.pagetemplates.result.SectionHitGroup 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 3 with SectionHitGroup

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

the class Organizer method toGroup.

/**
 * Creates the hit group corresponding to a section, drawing data from the given result
 */
private SectionHitGroup toGroup(Section section, Resolution resolution, Result result) {
    SectionHitGroup sectionGroup = new SectionHitGroup("section:" + section.getId());
    setField("id", section.getId(), sectionGroup);
    sectionGroup.setLeaf(section.elements(Section.class).size() == 0);
    setField("layout", section.getLayout().getName(), sectionGroup);
    setField("region", section.getRegion(), sectionGroup);
    List<String> sourceList = new ArrayList<>();
    renderElements(resolution, result, sectionGroup, sourceList, section.elements());
    // Trim to max
    if (section.getMax() >= 0)
        sectionGroup.trim(0, section.getMax());
    if (sectionGroup.size() > 1)
        assignOrderer(section, resolution, sourceList, sectionGroup);
    return sectionGroup;
}
Also used : ArrayList(java.util.ArrayList) SectionHitGroup(com.yahoo.search.pagetemplates.result.SectionHitGroup)

Example 4 with SectionHitGroup

use of com.yahoo.search.pagetemplates.result.SectionHitGroup 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

SectionHitGroup (com.yahoo.search.pagetemplates.result.SectionHitGroup)4 PageTemplate (com.yahoo.search.pagetemplates.PageTemplate)1 Renderer (com.yahoo.search.pagetemplates.model.Renderer)1 Source (com.yahoo.search.pagetemplates.model.Source)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1