ShardSearchRequest shardSearchRequest = new ShardSearchRequest();
shardSearchRequest.types(new String[] {Constants.DEFAULT_MAPPING_TYPE });
// TODO: use own CrateSearchContext that doesn't require ShardSearchRequest
SearchContext context = new DefaultSearchContext(
idGenerator.incrementAndGet(),
shardSearchRequest,
searchShardTarget,
engineSearcher,
indexService,
indexShard,
scriptService,
cacheRecycler,
pageCacheRecycler,
bigArrays
);
SearchContext.setCurrent(context);
try {
LuceneQueryBuilder builder = new LuceneQueryBuilder(functions, context, indexService.cache());
LuceneQueryBuilder.Context ctx = builder.convert(request.whereClause());
context.parsedQuery(new ParsedQuery(ctx.query(), ImmutableMap.<String, Filter>of()));
Float minScore = ctx.minScore();
if (minScore != null) {
context.minimumScore(minScore);
}
// the OUTPUTS_VISITOR sets the sourceFetchContext / version / minScore onto the SearchContext
OutputContext outputContext = new OutputContext(context, request.partitionBy());
OUTPUTS_VISITOR.process(request.outputs(), outputContext);
context.sort(generateLuceneSort(
context, request.orderBy(), request.reverseFlags(), request.nullsFirst()));
context.from(request.offset());
context.size(request.limit());
// pre process
dfsPhase.preProcess(context);
queryPhase.preProcess(context);
fetchPhase.preProcess(context);
// compute the context keep alive
long keepAlive = defaultKeepAlive;
context.keepAlive(keepAlive);
} catch (Throwable e) {
context.close();
throw ExceptionsHelper.convertToRuntime(e);
}
return context;
}