当前位置:网站首页>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
边栏推荐
- SQL create temporary table
- PgSQL converts string to double type (to_number())
- 【最詳細】最新最全Redis面試大全(50道)
- New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears
- Why is data service the direction of the next generation data center?
- Recursion, Fibonacci sequence
- 【最详细】最新最全Redis面试大全(50道)
- Longest common prefix and
- URL programming
- Hello world of vertx
猜你喜欢

Common problems in io streams

专题 | 同步 异步

Circuit, packet and message exchange

c语言指针的概念

Paper learning -- Study on the similarity of water level time series of Xingzi station in Poyang Lake

691. Cube IV

HCIA notes

Spa single page application

1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log

Le Seigneur des anneaux: l'anneau du pouvoir
随机推荐
2. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
691. Cube IV
Warehouse database fields_ Summary of SQL problems in kingbase8 migration of Jincang database
Interview questions about producers and consumers (important)
Lombok -- simplify code
PdfWriter. GetInstance throws system Nullreferenceexception [en] pdfwriter GetInstance throws System. NullRef
La différence entre le let Typescript et le Var
Realize the reuse of components with different routing parameters and monitor the changes of routing parameters
Operation and maintenance technical support personnel have hardware maintenance experience in Hong Kong
TreeMap
[set theory] Stirling subset number (Stirling subset number concept | ball model | Stirling subset number recurrence formula | binary relationship refinement relationship of division)
Common analysis with criteria method
Arduino Serial系列函数 有关print read 的总结
Understanding of class
JUnit unit test of vertx
Leetcode 198: house raiding
"Moss ma not found" solution
Discussion on some problems of array
Introduction of transformation flow
Various postures of CS without online line