当前位置:网站首页>What did the DFS phase do
What did the DFS phase do
2022-07-03 07:30:00 【chuanyangwang】
/**
* Dfs phase of a search request, used to make scoring 100% accurate by collecting additional info from each shard before the query phase.
* The additional information is used to better compare the scores coming from all the shards, which depend on local factors (e.g. idf)
*/
public class DfsPhase implements SearchPhase {
@Override
public void preProcess(SearchContext context) {
}
@Override
public void execute(SearchContext context) {
try {
ObjectObjectHashMap<String, CollectionStatistics> fieldStatistics = HppcMaps.newNoNullKeysMap();
Map<Term, TermStatistics> stats = new HashMap<>();
IndexSearcher searcher = new IndexSearcher(context.searcher().getIndexReader()) {
@Override
public TermStatistics termStatistics(Term term, int docFreq, long totalTermFreq) throws IOException {
if (context.isCancelled()) {
throw new TaskCancelledException("cancelled");
}
TermStatistics ts = super.termStatistics(term, docFreq, totalTermFreq);
if (ts != null) {
stats.put(term, ts);
}
return ts;
}
@Override
public CollectionStatistics collectionStatistics(String field) throws IOException {
if (context.isCancelled()) {
throw new TaskCancelledException("cancelled");
}
CollectionStatistics cs = super.collectionStatistics(field);
if (cs != null) {
fieldStatistics.put(field, cs);
}
return cs;
}
};
searcher.createWeight(context.searcher().rewrite(context.query()), ScoreMode.COMPLETE, 1);
for (RescoreContext rescoreContext : context.rescore()) {
for (Query query : rescoreContext.getQueries()) {
searcher.createWeight(context.searcher().rewrite(query), ScoreMode.COMPLETE, 1);
}
}
Term[] terms = stats.keySet().toArray(new Term[0]);
TermStatistics[] termStatistics = new TermStatistics[terms.length];
for (int i = 0; i < terms.length; i++) {
termStatistics[i] = stats.get(terms[i]);
}
context.dfsResult().termsStatistics(terms, termStatistics)
.fieldStatistics(fieldStatistics)
.maxDoc(context.searcher().getIndexReader().maxDoc());
} catch (Exception e) {
throw new DfsPhaseExecutionException(context.shardTarget(), "Exception during dfs phase", e);
}
}
}
dfs Stage collect the statistical information of the word items of each segment . The method of collection is to use createWeight Two methods called when
- termStatistics
- collectionStatistics
org.elasticsearch.search.SearchService#executeQueryPhase(org.elasticsearch.search.query.QuerySearchRequest, org.elasticsearch.action.search.SearchShardTask, org.elasticsearch.action.ActionListener<org.elasticsearch.search.query.QuerySearchResult>)
public void executeQueryPhase(QuerySearchRequest request, SearchShardTask task, ActionListener<QuerySearchResult> listener) {
runAsync(request.id(), () -> {
final SearchContext context = findContext(request.id(), request);
context.setTask(task);
context.incRef();
try (SearchOperationListenerExecutor executor = new SearchOperationListenerExecutor(context)) {
contextProcessing(context);
// Will be obtained in the previous round dfs Put in aggregatedDfs in
context.searcher().setAggregatedDfs(request.dfs());
queryPhase.execute(context);
if (context.queryResult().hasSearchContext() == false && context.scrollContext() == null) {
// no hits, we can release the context since there will be no fetch phase
freeContext(context.id());
} else {
contextProcessedSuccessfully(context);
}
executor.success();
return context.queryResult();
} catch (Exception e) {
logger.trace("Query phase failed", e);
processFailure(context, e);
throw e;
} finally {
cleanContext(context);
}
}, listener);
}
dfs three
DFS_ACTION_NAME obtain dfs Information
QUERY_ID_ACTION_NAME take dfs The information is transmitted to each segment , And do query
FETCH_ID_ACTION_NAME fetch
边栏推荐
- VMware network mode - bridge, host only, NAT network
- Understanding of class
- New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears
- 【已解决】win10找不到本地组策略编辑器解决方法
- 【最详细】最新最全Redis面试大全(50道)
- Chrome 98 Private Network Access problem w/ disabled web security: Request had no target IP address
- Common problems in io streams
- Recursion, Fibonacci sequence
- [solved] unknown error 1146
- [most detailed] latest and complete redis interview book (50)
猜你喜欢
[coppeliasim4.3] C calls UR5 in the remoteapi control scenario
TCP cumulative acknowledgement and window value update
Comparison of advantages and disadvantages between most complete SQL and NoSQL
Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
在 4EVERLAND 上存储 WordPress 媒体内容,完成去中心化存储
URL programming
Leetcode 213: 打家劫舍 II
C code production YUV420 planar format file
"Baidu Cup" CTF game 2017 February, Web: blast-1
Common methods of file class
随机推荐
Sorting, dichotomy
Use of other streams
Arduino 软串口通信 的几点体会
Qtip2 solves the problem of too many texts
TypeScript let与var的区别
《指環王:力量之戒》新劇照 力量之戒鑄造者亮相
专题 | 同步 异步
Map interface and method
Common problems in io streams
【已解决】SQLException: Invalid value for getInt() - ‘田鹏‘
pgAdmin 4 v6.11 发布,PostgreSQL 开源图形化管理工具
The difference between typescript let and VaR
The babbage industrial policy forum
High concurrency memory pool
1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
PgSQL converts string to double type (to_number())
[Development Notes] cloud app control on device based on smart cloud 4G adapter gc211
Operation and maintenance technical support personnel have hardware maintenance experience in Hong Kong
Comparison of advantages and disadvantages between most complete SQL and NoSQL
Hash table, generic