@@ -1011,6 +1011,8 @@ type indexSpec struct {
1011
1011
DefaultLanguage string "default_language,omitempty"
1012
1012
LanguageOverride string "language_override,omitempty"
1013
1013
TextIndexVersion int "textIndexVersion,omitempty"
1014
+
1015
+ Collation * Collation "collation,omitempty"
1014
1016
}
1015
1017
1016
1018
type Index struct {
@@ -1049,6 +1051,54 @@ type Index struct {
1049
1051
// from the weighted sum of the frequency for each of the indexed fields in
1050
1052
// that document. The default field weight is 1.
1051
1053
Weights map [string ]int
1054
+
1055
+ // Collation defines the collation to use for the index.
1056
+ Collation * Collation
1057
+ }
1058
+
1059
+ type Collation struct {
1060
+
1061
+ // Locale defines the collation locale.
1062
+ Locale string `bson:"locale"`
1063
+
1064
+ // CaseLevel defines whether to turn case sensitivity on at strength 1 or 2.
1065
+ CaseLevel bool `bson:"caseLevel,omitempty"`
1066
+
1067
+ // CaseFirst may be set to "upper" or "lower" to define whether
1068
+ // to have uppercase or lowercase items first. Default is "off".
1069
+ CaseFirst string `bson:"caseFirst,omitempty"`
1070
+
1071
+ // Strength defines the priority of comparison properties, as follows:
1072
+ //
1073
+ // 1 (primary) - Strongest level, denote difference between base characters
1074
+ // 2 (secondary) - Accents in characters are considered secondary differences
1075
+ // 3 (tertiary) - Upper and lower case differences in characters are
1076
+ // distinguished at the tertiary level
1077
+ // 4 (quaternary) - When punctuation is ignored at level 1-3, an additional
1078
+ // level can be used to distinguish words with and without
1079
+ // punctuation. Should only be used if ignoring punctuation
1080
+ // is required or when processing Japanese text.
1081
+ // 5 (identical) - When all other levels are equal, the identical level is
1082
+ // used as a tiebreaker. The Unicode code point values of
1083
+ // the NFD form of each string are compared at this level,
1084
+ // just in case there is no difference at levels 1-4
1085
+ //
1086
+ // Strength defaults to 3.
1087
+ Strength int `bson:"strength,omitempty"`
1088
+
1089
+ // NumericOrdering defines whether to order numbers based on numerical
1090
+ // order and not collation order.
1091
+ NumericOrdering bool `bson:"numericOrdering,omitempty"`
1092
+
1093
+ // Alternate controls whether spaces and punctuation are considered base characters.
1094
+ // May be set to "non-ignorable" (spaces and punctuation considered base characters)
1095
+ // or "shifted" (spaces and punctuation not considered base characters, and only
1096
+ // distinguished at strength > 3). Defaults to "non-ignorable".
1097
+ Alternate string `bson:"alternate,omitempty"`
1098
+
1099
+ // Backwards defines whether to have secondary differences considered in reverse order,
1100
+ // as done in the French language.
1101
+ Backwards bool `bson:"backwards,omitempty"`
1052
1102
}
1053
1103
1054
1104
// mgo.v3: Drop Minf and Maxf and transform Min and Max to floats.
@@ -1242,6 +1292,7 @@ func (c *Collection) EnsureIndex(index Index) error {
1242
1292
Weights : keyInfo .weights ,
1243
1293
DefaultLanguage : index .DefaultLanguage ,
1244
1294
LanguageOverride : index .LanguageOverride ,
1295
+ Collation : index .Collation ,
1245
1296
}
1246
1297
1247
1298
if spec .Min == 0 && spec .Max == 0 {
@@ -1456,6 +1507,7 @@ func indexFromSpec(spec indexSpec) Index {
1456
1507
DefaultLanguage : spec .DefaultLanguage ,
1457
1508
LanguageOverride : spec .LanguageOverride ,
1458
1509
ExpireAfter : time .Duration (spec .ExpireAfter ) * time .Second ,
1510
+ Collation : spec .Collation ,
1459
1511
}
1460
1512
if float64 (int (spec .Min )) == spec .Min && float64 (int (spec .Max )) == spec .Max {
1461
1513
index .Min = int (spec .Min )
@@ -1584,7 +1636,7 @@ func (s *Session) Refresh() {
1584
1636
}
1585
1637
1586
1638
// SetMode changes the consistency mode for the session.
1587
- //
1639
+ //
1588
1640
// The default mode is Strong.
1589
1641
//
1590
1642
// In the Strong consistency mode reads and writes will always be made to
0 commit comments