@@ -115,12 +115,12 @@ class CountryQueryService {
115
115
}
116
116
117
117
/// Builds the MongoDB aggregation pipeline based on the provided filters.
118
- List <Map <String , dynamic >> _buildAggregationPipeline (
118
+ List <Map <String , Object >> _buildAggregationPipeline (
119
119
Map <String , dynamic > filter,
120
120
PaginationOptions ? pagination,
121
121
List <SortOption >? sort,
122
122
) {
123
- final pipeline = < Map <String , dynamic >> [];
123
+ final pipeline = < Map <String , Object >> [];
124
124
final compoundMatchStages = < Map <String , dynamic >> [];
125
125
126
126
// --- Stage 1: Initial Match for active status, text search, and other filters ---
@@ -131,7 +131,10 @@ class CountryQueryService {
131
131
final qValue = filter['q' ];
132
132
if (qValue is String && qValue.isNotEmpty) {
133
133
compoundMatchStages.add ({
134
- r'$text' : {r'$search' : qValue},
134
+ 'name' : {
135
+ r'$regex' : qValue,
136
+ r'$options' : 'i' , // Case-insensitive
137
+ },
135
138
});
136
139
}
137
140
@@ -163,7 +166,10 @@ class CountryQueryService {
163
166
{
164
167
r'$match' : {
165
168
r'$expr' : {
166
- r'$eq' : [r'$headquarters._id' , r'$$countryId' ],
169
+ r'$eq' : [
170
+ r'$headquarters.id' ,
171
+ {r'$toString' : r'$$countryId' },
172
+ ],
167
173
},
168
174
'status' : ContentStatus .active.name,
169
175
},
@@ -174,7 +180,7 @@ class CountryQueryService {
174
180
});
175
181
pipeline.add ({
176
182
r'$match' : {
177
- 'matchingSources' : {r'$ne' : < dynamic > []},
183
+ 'matchingSources' : {r'$ne' : < Object > []},
178
184
},
179
185
});
180
186
}
@@ -191,7 +197,10 @@ class CountryQueryService {
191
197
{
192
198
r'$match' : {
193
199
r'$expr' : {
194
- r'$eq' : [r'$eventCountry._id' , r'$$countryId' ],
200
+ r'$eq' : [
201
+ r'$eventCountry.id' ,
202
+ {r'$toString' : r'$$countryId' },
203
+ ],
195
204
},
196
205
'status' : ContentStatus .active.name,
197
206
},
@@ -202,14 +211,14 @@ class CountryQueryService {
202
211
});
203
212
pipeline.add ({
204
213
r'$match' : {
205
- 'matchingHeadlines' : {r'$ne' : < dynamic > []},
214
+ 'matchingHeadlines' : {r'$ne' : < Object > []},
206
215
},
207
216
});
208
217
}
209
218
210
219
// --- Stage 4: Sorting ---
211
220
if (sort != null && sort.isNotEmpty) {
212
- final sortStage = < String , dynamic > {};
221
+ final sortStage = < String , Object > {};
213
222
for (final option in sort) {
214
223
sortStage[option.field] = option.order == SortOrder .asc ? 1 : - 1 ;
215
224
}
0 commit comments