@@ -92,9 +92,10 @@ absl::optional<Operator> Query::FindOpInsideFilters(
9292 return absl::nullopt ;
9393}
9494
95- std::shared_ptr<std::vector<OrderBy>> Query::CalculateNormalizedOrderBys () const {
95+ std::shared_ptr<std::vector<OrderBy>> Query::CalculateNormalizedOrderBys ()
96+ const {
97+ // Any explicit order by fields should be added as is.
9698 auto result = std::make_shared<std::vector<OrderBy>>(explicit_order_bys_);
97-
9899 std::set<FieldPath> fieldsNormalized;
99100 for (const OrderBy& order_by : explicit_order_bys_) {
100101 fieldsNormalized.insert (order_by.field ());
@@ -111,21 +112,20 @@ std::shared_ptr<std::vector<OrderBy>> Query::CalculateNormalizedOrderBys() const
111112 // the same field, the field should be added only once. Note:
112113 // `std::set<model::FieldPath>` sorts the key field before other fields.
113114 // However, we want the key field to be sorted last.
114- const std::set<model::FieldPath> inequality_fields =
115- InequalityFilterFields ();
115+ const std::set<model::FieldPath> inequality_fields = InequalityFilterFields ();
116116
117117 for (const model::FieldPath& field : inequality_fields) {
118118 if (fieldsNormalized.find (field) == fieldsNormalized.end () &&
119119 !field.IsKeyFieldPath ()) {
120120 result->push_back (OrderBy (field, last_direction));
121- }
121+ }
122122 }
123123
124124 // Add the document key field to the last if it is not explicitly ordered.
125125 if (fieldsNormalized.find (FieldPath::KeyFieldPath ()) ==
126126 fieldsNormalized.end ()) {
127127 result->push_back (OrderBy (FieldPath::KeyFieldPath (), last_direction));
128- }
128+ }
129129
130130 return result;
131131}
0 commit comments