I'm not sure there is much work here, depending on how the implementation goes, but there is some risk that in order to compute the rank for a $search pipeline we will need to generate this pipeline:
db.example.aggregate([
{$search: {/* query*}},
{$sort: {score: {$meta: "searchScore"}}},
{$_internalSetWindowFields: {output: {rank: {$rank: {}}}}
])
The second $sort doesn't do anything. It might be generated as part of $rankFusion's desugaring, since we need to specify a sortBy to $setWindowFields in order to compute the rank. Note that SERVER-91281 might mean that we don't need to generate this kind of pipeline, in which case this ticket is more of a no-op and can be tracked on the backlog as a request to optimize out a $sort in this scenario, if it comes up for a user who is using $setWindowFields.
- is depended on by
-
SERVER-95168 Implement $setWindowFields version of desugaring for $rankFusion
- Blocked
- is related to
-
SERVER-96059 Optimize away metadata $sort directly after $search for single node environments
- Open
- related to
-
SERVER-96065 Optimize away $sort directly after sorted $mergeCursors for sharded environments
- Open
-
SERVER-96067 Properly set the ‘preserveOrderAndMetadata’ field for common aggregation states
- Open
-
SERVER-96064 Optimize away $sort directly after $vectorSearch for single node environments
- Closed
-
SERVER-96068 Generalize the $sort removal optimizations after $search/$vectorSearch/$mergeCursors
- Open