final DirectoryReader directoryReader = context.searcher().getDirectoryReader();
final DirectoryReader directoryReader = context.searcher().getDirectoryReader();
/** * Loads the cache result, computing it if needed by executing the query phase and otherwise deserializing the cached * value into the {@link SearchContext#queryResult() context's query result}. The combination of load + compute allows * to have a single load operation that will cause other requests with the same key to wait till its loaded an reuse * the same cache. */ public void loadIntoContext(final ShardSearchRequest request, final SearchContext context, final QueryPhase queryPhase) throws Exception { assert canCache(request, context); Key key = buildKey(request, context); Loader loader = new Loader(queryPhase, context, key); Value value = cache.get(key, loader); if (loader.isLoaded()) { key.shard.requestCache().onMiss(); // see if its the first time we see this reader, and make sure to register a cleanup key CleanupKey cleanupKey = new CleanupKey(context.indexShard(), ((DirectoryReader) context.searcher().getIndexReader()).getVersion()); if (!registeredClosedListeners.containsKey(cleanupKey)) { Boolean previous = registeredClosedListeners.putIfAbsent(cleanupKey, Boolean.TRUE); if (previous == null) { ElasticsearchDirectoryReader.addReaderCloseListener(context.searcher().getDirectoryReader(), cleanupKey); } } } else { key.shard.requestCache().onHit(); // restore the cached query result into the context final QuerySearchResult result = context.queryResult(); result.readFromWithId(context.id(), value.reference.streamInput()); result.shardTarget(context.shardTarget()); } }
final DirectoryReader directoryReader = context.searcher().getDirectoryReader();
final DirectoryReader directoryReader = context.searcher().getDirectoryReader();