@@ -115,12 +115,12 @@ class CountryQueryService {
115115 }
116116
117117 /// Builds the MongoDB aggregation pipeline based on the provided filters.
118- List <Map <String , dynamic >> _buildAggregationPipeline (
118+ List <Map <String , Object >> _buildAggregationPipeline (
119119 Map <String , dynamic > filter,
120120 PaginationOptions ? pagination,
121121 List <SortOption >? sort,
122122 ) {
123- final pipeline = < Map <String , dynamic >> [];
123+ final pipeline = < Map <String , Object >> [];
124124 final compoundMatchStages = < Map <String , dynamic >> [];
125125
126126 // --- Stage 1: Initial Match for active status, text search, and other filters ---
@@ -131,7 +131,10 @@ class CountryQueryService {
131131 final qValue = filter['q' ];
132132 if (qValue is String && qValue.isNotEmpty) {
133133 compoundMatchStages.add ({
134- r'$text' : {r'$search' : qValue},
134+ 'name' : {
135+ r'$regex' : qValue,
136+ r'$options' : 'i' , // Case-insensitive
137+ },
135138 });
136139 }
137140
@@ -163,7 +166,10 @@ class CountryQueryService {
163166 {
164167 r'$match' : {
165168 r'$expr' : {
166- r'$eq' : [r'$headquarters._id' , r'$$countryId' ],
169+ r'$eq' : [
170+ r'$headquarters.id' ,
171+ {r'$toString' : r'$$countryId' },
172+ ],
167173 },
168174 'status' : ContentStatus .active.name,
169175 },
@@ -174,7 +180,7 @@ class CountryQueryService {
174180 });
175181 pipeline.add ({
176182 r'$match' : {
177- 'matchingSources' : {r'$ne' : < dynamic > []},
183+ 'matchingSources' : {r'$ne' : < Object > []},
178184 },
179185 });
180186 }
@@ -191,7 +197,10 @@ class CountryQueryService {
191197 {
192198 r'$match' : {
193199 r'$expr' : {
194- r'$eq' : [r'$eventCountry._id' , r'$$countryId' ],
200+ r'$eq' : [
201+ r'$eventCountry.id' ,
202+ {r'$toString' : r'$$countryId' },
203+ ],
195204 },
196205 'status' : ContentStatus .active.name,
197206 },
@@ -202,14 +211,14 @@ class CountryQueryService {
202211 });
203212 pipeline.add ({
204213 r'$match' : {
205- 'matchingHeadlines' : {r'$ne' : < dynamic > []},
214+ 'matchingHeadlines' : {r'$ne' : < Object > []},
206215 },
207216 });
208217 }
209218
210219 // --- Stage 4: Sorting ---
211220 if (sort != null && sort.isNotEmpty) {
212- final sortStage = < String , dynamic > {};
221+ final sortStage = < String , Object > {};
213222 for (final option in sort) {
214223 sortStage[option.field] = option.order == SortOrder .asc ? 1 : - 1 ;
215224 }
0 commit comments