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;
}
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());
}
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;
}
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);
}
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));
}
Aggregations