Search in sources :

Example 6 with Renderer

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

the class SearchHandler method handleBody.

private HttpSearchResponse handleBody(HttpRequest request) {
    // Find query profile
    String queryProfileName = request.getProperty("queryProfile");
    CompiledQueryProfile queryProfile = queryProfileRegistry.findQueryProfile(queryProfileName);
    boolean benchmarkOutput = VespaHeaders.benchmarkOutput(request);
    // Create query
    Query query = new Query(request, queryProfile);
    boolean benchmarkCoverage = VespaHeaders.benchmarkCoverage(benchmarkOutput, request.getJDiscRequest().headers());
    // Find and execute search chain if we have a valid query
    String invalidReason = query.validate();
    Chain<Searcher> searchChain = null;
    String searchChainName = null;
    if (invalidReason == null) {
        Tuple2<String, Chain<Searcher>> nameAndChain = resolveChain(query.properties().getString(Query.SEARCH_CHAIN));
        searchChainName = nameAndChain.first;
        searchChain = nameAndChain.second;
    }
    // Create the result
    Result result;
    if (invalidReason != null) {
        result = new Result(query, ErrorMessage.createIllegalQuery(invalidReason));
    } else if (queryProfile == null && queryProfileName != null) {
        result = new Result(query, ErrorMessage.createIllegalQuery("Could not resolve query profile '" + queryProfileName + "'"));
    } else if (searchChain == null) {
        result = new Result(query, ErrorMessage.createInvalidQueryParameter("No search chain named '" + searchChainName + "' was found"));
    } else {
        String pathAndQuery = UriTools.rawRequest(request.getUri());
        result = search(pathAndQuery, query, searchChain, searchChainRegistry);
    }
    Renderer renderer;
    if (result.getTemplating().usesDefaultTemplate()) {
        renderer = toRendererCopy(query.getPresentation().getRenderer());
        // pre-Vespa 6 Result.getEncoding() expects this to be set. TODO: Remove
        result.getTemplating().setRenderer(renderer);
    } else {
        // somebody explicitly assigned a old style template
        renderer = perRenderingCopy(result.getTemplating().getRenderer());
    }
    // Transform result to response
    HttpSearchResponse response = new HttpSearchResponse(getHttpResponseStatus(request, result), result, query, renderer);
    if (hostResponseHeaderKey.isPresent())
        response.headers().add(hostResponseHeaderKey.get(), selfHostname);
    if (benchmarkOutput)
        VespaHeaders.benchmarkOutput(response.headers(), benchmarkCoverage, response.getTiming(), response.getHitCounts(), getErrors(result), response.getCoverage());
    return response;
}
Also used : Chain(com.yahoo.component.chain.Chain) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) Renderer(com.yahoo.processing.rendering.Renderer) Result(com.yahoo.search.Result)

Example 7 with Renderer

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

the class RendererRegistry method addTemplateSet.

@SuppressWarnings({ "deprecation", "unchecked" })
private ComponentId addTemplateSet(UserTemplate<?> templateSet) {
    Renderer renderer = new SearchRendererAdaptor(templateSet);
    ComponentId rendererId = new ComponentId(templateSet.getName());
    renderer.initId(rendererId);
    register(rendererId, renderer);
    return rendererId;
}
Also used : SearchRendererAdaptor(com.yahoo.prelude.templates.SearchRendererAdaptor) Renderer(com.yahoo.processing.rendering.Renderer) ComponentId(com.yahoo.component.ComponentId)

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