Skip to content

Commit 586dfb9

Browse files
authored
feat(mongox): accent-sensitive, case-insensitive collation (#46)
1 parent 69a4164 commit 586dfb9

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

mongox/pagination.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,26 @@ func (c *Collection) aggregateFilter(ctx context.Context, p usecasex.Pagination,
190190
}
191191

192192
func findOptionsFromPagination(p usecasex.Pagination, s *usecasex.Sort) *options.FindOptions {
193-
o := options.Find().SetAllowDiskUse(true).SetLimit(limit(p))
193+
o := options.Find().SetAllowDiskUse(true).SetLimit(limit(p))
194194

195-
if p.Offset != nil {
196-
o = o.SetSkip(p.Offset.Offset)
197-
}
195+
if p.Offset != nil {
196+
o = o.SetSkip(p.Offset.Offset)
197+
}
198198

199-
return o.SetCollation(&options.Collation{Strength: 1, Locale: "simple"}).SetSort(sortFilter(p, s))
199+
collation := options.Collation{
200+
Locale: "en",
201+
Strength: 2,
202+
}
203+
204+
return o.SetCollation(&collation).SetSort(sortFilter(p, s))
200205
}
201206

202207
func aggregateOptionsFromPagination(_ usecasex.Pagination, _ *usecasex.Sort) *options.AggregateOptions {
203-
return options.Aggregate().SetAllowDiskUse(true).SetCollation(&options.Collation{Strength: 1, Locale: "simple"})
208+
collation := options.Collation{
209+
Locale: "en",
210+
Strength: 2,
211+
}
212+
return options.Aggregate().SetAllowDiskUse(true).SetCollation(&collation)
204213
}
205214

206215
func (c *Collection) pageFilter(ctx context.Context, p usecasex.Pagination, s *usecasex.Sort) (any, error) {
@@ -256,11 +265,11 @@ func (c *Collection) pageFilter(ctx context.Context, p usecasex.Pagination, s *u
256265
}
257266

258267
func sortFilter(p usecasex.Pagination, s *usecasex.Sort) bson.D {
259-
var sortOptions bson.D
260-
if s != nil && s.Key != "" && s.Key != idKey {
261-
sortOptions = append(sortOptions, bson.E{Key: s.Key, Value: sortDirection(p, s)})
262-
}
263-
return append(sortOptions, bson.E{Key: idKey, Value: sortDirection(p, s)})
268+
var sortOptions bson.D
269+
if s != nil && s.Key != "" && s.Key != idKey {
270+
sortOptions = append(sortOptions, bson.E{Key: s.Key, Value: sortDirection(p, s)})
271+
}
272+
return append(sortOptions, bson.E{Key: idKey, Value: sortDirection(p, s)})
264273
}
265274

266275
func limit(p usecasex.Pagination) int64 {

0 commit comments

Comments
 (0)