[Feature Request] When scores are already calculated with sorting applied & track_scores is set to true then do not recalculate scores in the Fetch phase #13610
Labels
enhancement
Enhancement or improvement to existing feature or request
Search:Query Capabilities
untriaged
Is your feature request related to a problem? Please describe
When Hybrid query with the sorting is applied and track_scores=true in the search request then do not recalculate the scores in fetch phase.
Currently, when sorting is applied and track_scores=true then instance of FetchScorePhase processor is created in the fetch phase to calculate the scores for the hits fetched in the fetch phase.
In the Hybrid query case scenario(sort is applied and track_scores is true), then normalized scores are calculated while executing phase results pipeline processor therefore we do not have to calculate scores in the fetch phase because normalized scores are calculated exclusively by normalization processor.
Describe the solution you'd like
When hybrid query with sorting applied and track scores is enabled then we can deduce that score is already calculated.
In other query type scenarios then score will be float.NaN in the scoredocs.
In FetchSearchPhase.java innerRun() method when we deduce the reduceQueryPhase from the topDocs then those TopDocs contains ScoreDocs. The score calculated in the Query phase is present in present in the ScoreDocs. Moreover, if sorting is applied then reduceQueryPhase has an object of sortedTopDocs which contains isSortedByField object.
Therefore we can deduce one condition that
If we can deduce score is already calculated then do not calculate the scores in Fetch Phase by disabling the FetchScorePhase instantiation.
Also we need to add a new parameter isScoreAlreadyCalculated in the ShardFetchRequest which is propagated to FetchPhase.java and if isScoreAlreadyCalculated =true then do not instantiate FetchScorePhase processor.
Related component
Search:Query Capabilities
Additional context
Hybrid Scores are normalized using normalization processor which is a phase results processor. Normalization works as below during search
Multiple Shards Scenario the order of execution of phases looks like
Single Shard Scenario the order of execution of phases looks like
The text was updated successfully, but these errors were encountered: