当前位置:网站首页>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
边栏推荐
- 691. Cube IV
- TypeScript let與var的區別
- 【已解决】Unknown error 1146
- Leetcode 198: house raiding
- Map interface and method
- Raspberry pie update tool chain
- Jeecg menu path display problem
- JS monitors empty objects and empty references
- 4everland: the Web3 Developer Center on IPFs has deployed more than 30000 dapps!
- 1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
猜你喜欢
Reconnaissance et détection d'images - Notes
Arduino Serial系列函数 有关print read 的总结
Common methods of file class
Take you through the whole process and comprehensively understand the software accidents that belong to testing
Hash table, generic
[set theory] Stirling subset number (Stirling subset number concept | ball model | Stirling subset number recurrence formula | binary relationship refinement relationship of division)
Final, override, polymorphism, abstraction, interface
Qtip2 solves the problem of too many texts
IPv4 address
Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
随机推荐
Various postures of CS without online line
The babbage industrial policy forum
Final, override, polymorphism, abstraction, interface
The babbage industrial policy forum
An overview of IfM Engage
Industrial resilience
[coppeliasim4.3] C calls UR5 in the remoteapi control scenario
2. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
【已解决】win10找不到本地组策略编辑器解决方法
4EVERLAND:IPFS 上的 Web3 开发者中心,部署了超过 30,000 个 Dapp!
The difference between typescript let and VaR
Comparison of advantages and disadvantages between most complete SQL and NoSQL
TypeScript let与var的区别
LeetCode
OSI knowledge sorting
最全SQL与NoSQL优缺点对比
IPv4 address
JS monitors empty objects and empty references
Deep learning parameter initialization (I) Xavier initialization with code
docker建立mysql:5.7版本指定路径挂载不上。