Search in sources :

Example 1 with Renderer

use of com.yahoo.processing.rendering.Renderer in project vespa by vespa-engine.

the class AbstractProcessingHandler method selectRenderer.

private static Renderer selectRenderer(com.yahoo.processing.Request processingRequest, ComponentRegistry<Renderer> renderers, Renderer defaultRenderer) {
    Renderer renderer = null;
    // TODO: Support setting a particular renderer instead of just selecting
    // by name?
    String rendererId = processingRequest.properties().getString("format");
    if (rendererId != null && !"".equals(rendererId)) {
        renderer = renderers.getComponent(ComponentSpecification.fromString(rendererId));
        if (renderer == null)
            processingRequest.errors().add(new ErrorMessage("Could not find renderer", "Requested '" + rendererId + "', has " + renderers.allComponents()));
    }
    if (renderer == null)
        renderer = defaultRenderer;
    return renderer;
}
Also used : AsynchronousSectionedRenderer(com.yahoo.processing.rendering.AsynchronousSectionedRenderer) Renderer(com.yahoo.processing.rendering.Renderer) ProcessingRenderer(com.yahoo.processing.rendering.ProcessingRenderer) ErrorMessage(com.yahoo.processing.request.ErrorMessage)

Example 2 with Renderer

use of com.yahoo.processing.rendering.Renderer in project vespa by vespa-engine.

the class ProcessingHandlerTestCase method testDefaultRendererIsAddedToRegistryWhenNoneIsGivenByUser.

@Test
public void testDefaultRendererIsAddedToRegistryWhenNoneIsGivenByUser() throws Exception {
    String defaultId = AbstractProcessingHandler.DEFAULT_RENDERER_ID;
    driver = new ProcessingTestDriver(Collections.<Chain<Processor>>emptyList());
    Renderer defaultRenderer = driver.processingHandler().getRenderers().getComponent(defaultId);
    assertThat(defaultRenderer, notNullValue());
}
Also used : Chain(com.yahoo.component.chain.Chain) Renderer(com.yahoo.processing.rendering.Renderer) ProcessingRenderer(com.yahoo.processing.rendering.ProcessingRenderer) Test(org.junit.Test)

Example 3 with Renderer

use of com.yahoo.processing.rendering.Renderer in project vespa by vespa-engine.

the class SearchHandler method searchAndFill.

/**
 * Used from container SDK, for internal use only
 */
public Result searchAndFill(Query query, Chain<? extends Searcher> searchChain, SearchChainRegistry registry) {
    Result errorResult = validateQuery(query);
    if (errorResult != null)
        return errorResult;
    Renderer<Result> renderer = rendererRegistry.getRenderer(query.getPresentation().getRenderer());
    // here too in which case it will still be "unset" after we set it :-)
    if (query.getPresentation().getSummary() == null && renderer instanceof com.yahoo.search.rendering.Renderer)
        query.getPresentation().setSummary(((com.yahoo.search.rendering.Renderer) renderer).getDefaultSummaryClass());
    Execution execution = new Execution(searchChain, new Execution.Context(registry, indexFacts, specialTokens, rendererRegistry, linguistics));
    query.getModel().setExecution(execution);
    execution.trace().setForceTimestamps(query.properties().getBoolean(FORCE_TIMESTAMPS, false));
    if (query.properties().getBoolean(DETAILED_TIMING_LOGGING, false)) {
        // check and set (instead of set directly) to avoid overwriting stuff from prepareForBreakdownAnalysis()
        execution.context().setDetailedDiagnostics(true);
    }
    Result result = execution.search(query);
    if (result.getTemplating() == null)
        result.getTemplating().setRenderer(renderer);
    ensureQuerySet(result, query);
    execution.fill(result, result.getQuery().getPresentation().getSummary());
    traceExecutionTimes(query, result);
    traceVespaVersion(query);
    traceRequestAttributes(query);
    return result;
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Renderer(com.yahoo.processing.rendering.Renderer) Result(com.yahoo.search.Result)

Example 4 with Renderer

use of com.yahoo.processing.rendering.Renderer in project vespa by vespa-engine.

the class SearchHandler method errorResponse.

@SuppressWarnings("unchecked")
private HttpResponse errorResponse(HttpRequest request, ErrorMessage errorMessage) {
    Query query = new Query();
    Result result = new Result(query, errorMessage);
    Renderer renderer = getRendererCopy(ComponentSpecification.fromString(request.getProperty("format")));
    // Pre-Vespa 6 Result.getEncoding() expects this TODO: Remove
    result.getTemplating().setRenderer(renderer);
    return new HttpSearchResponse(getHttpResponseStatus(request, result), result, query, renderer);
}
Also used : Query(com.yahoo.search.Query) Renderer(com.yahoo.processing.rendering.Renderer) Result(com.yahoo.search.Result)

Example 5 with Renderer

use of com.yahoo.processing.rendering.Renderer in project vespa by vespa-engine.

the class ProcessingHandlerTestCase method testUserSpecifiedDefaultRendererIsNotReplacedInRegistry.

@Test
public void testUserSpecifiedDefaultRendererIsNotReplacedInRegistry() throws Exception {
    String defaultId = AbstractProcessingHandler.DEFAULT_RENDERER_ID;
    Renderer myDefaultRenderer = new ProcessingRenderer();
    ComponentRegistry<Renderer> renderers = new ComponentRegistry<>();
    renderers.register(ComponentId.fromString(defaultId), myDefaultRenderer);
    driver = new ProcessingTestDriver(Collections.<Chain<Processor>>emptyList(), renderers);
    Renderer defaultRenderer = driver.processingHandler().getRenderers().getComponent(defaultId);
    assertThat(defaultRenderer, sameInstance(myDefaultRenderer));
}
Also used : Chain(com.yahoo.component.chain.Chain) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) Renderer(com.yahoo.processing.rendering.Renderer) ProcessingRenderer(com.yahoo.processing.rendering.ProcessingRenderer) ProcessingRenderer(com.yahoo.processing.rendering.ProcessingRenderer) Test(org.junit.Test)

Aggregations

Renderer (com.yahoo.processing.rendering.Renderer)7 Chain (com.yahoo.component.chain.Chain)3 ProcessingRenderer (com.yahoo.processing.rendering.ProcessingRenderer)3 Result (com.yahoo.search.Result)3 Query (com.yahoo.search.Query)2 Test (org.junit.Test)2 ComponentId (com.yahoo.component.ComponentId)1 ComponentRegistry (com.yahoo.component.provider.ComponentRegistry)1 SearchRendererAdaptor (com.yahoo.prelude.templates.SearchRendererAdaptor)1 AsynchronousSectionedRenderer (com.yahoo.processing.rendering.AsynchronousSectionedRenderer)1 ErrorMessage (com.yahoo.processing.request.ErrorMessage)1 Searcher (com.yahoo.search.Searcher)1 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)1 Execution (com.yahoo.search.searchchain.Execution)1