@@ -48,6 +48,39 @@ class Field {
4848 /// Example value: `ReferencedCollectionName.fieldName` .
4949 final String ? reference;
5050
51+ /// Enable stemming for this string field.
52+ final bool stem;
53+
54+ /// Whether to store the field value on disk.
55+ ///
56+ /// When set to `false` , the field value won't be stored on disk.
57+ final bool store;
58+
59+ /// Enable range index for this numerical field.
60+ ///
61+ /// Useful for efficient range queries on numerical fields.
62+ final bool rangeIndex;
63+
64+ /// List of characters to use as token separators for this field.
65+ ///
66+ /// Overrides the collection-level token_separators setting for this field.
67+ final List <String >? tokenSeparators;
68+
69+ /// List of special characters to index as part of tokens for this field.
70+ ///
71+ /// Overrides the collection-level symbols_to_index setting for this field.
72+ final List <String >? symbolsToIndex;
73+
74+ /// Custom stem dictionary for this field.
75+ ///
76+ /// Allows specifying custom stemming rules for this field.
77+ final String ? stemDictionary;
78+
79+ /// Maximum length to truncate the field value to.
80+ ///
81+ /// Token values longer than this will be truncated.
82+ final int ? truncateLen;
83+
5184 Field (
5285 this .name, {
5386 this .type,
@@ -60,6 +93,13 @@ class Field {
6093 this .sort = false ,
6194 this .enableInfixSearch = false ,
6295 this .reference,
96+ this .stem = false ,
97+ this .store = true ,
98+ this .rangeIndex = false ,
99+ this .tokenSeparators,
100+ this .symbolsToIndex,
101+ this .stemDictionary,
102+ this .truncateLen,
63103 }) {
64104 if (name.isEmpty) {
65105 throw ArgumentError ('Ensure Field.name is not empty' );
@@ -84,6 +124,13 @@ class Field {
84124 sort: map['sort' ] ?? false ,
85125 enableInfixSearch: map['infix' ] ?? false ,
86126 reference: map['reference' ],
127+ stem: map['stem' ] ?? false ,
128+ store: map['store' ] ?? true ,
129+ rangeIndex: map['range_index' ] ?? false ,
130+ tokenSeparators: (map['token_separators' ] as List ? )? .cast <String >(),
131+ symbolsToIndex: (map['symbols_to_index' ] as List ? )? .cast <String >(),
132+ stemDictionary: map['stem_dictionary' ],
133+ truncateLen: map['truncate_len' ],
87134 );
88135 }
89136
@@ -117,6 +164,27 @@ class Field {
117164 if (reference != null ) {
118165 map['reference' ] = reference;
119166 }
167+ if (stem) {
168+ map['stem' ] = true ;
169+ }
170+ if (! store) {
171+ map['store' ] = false ;
172+ }
173+ if (rangeIndex) {
174+ map['range_index' ] = true ;
175+ }
176+ if (tokenSeparators != null ) {
177+ map['token_separators' ] = tokenSeparators;
178+ }
179+ if (symbolsToIndex != null ) {
180+ map['symbols_to_index' ] = symbolsToIndex;
181+ }
182+ if (stemDictionary != null && stemDictionary! .isNotEmpty) {
183+ map['stem_dictionary' ] = stemDictionary;
184+ }
185+ if (truncateLen != null ) {
186+ map['truncate_len' ] = truncateLen;
187+ }
120188 return map;
121189 }
122190
@@ -137,7 +205,14 @@ class Field {
137205 locale.hashCode ^
138206 sort.hashCode ^
139207 enableInfixSearch.hashCode ^
140- reference.hashCode;
208+ reference.hashCode ^
209+ stem.hashCode ^
210+ store.hashCode ^
211+ rangeIndex.hashCode ^
212+ tokenSeparators.hashCode ^
213+ symbolsToIndex.hashCode ^
214+ stemDictionary.hashCode ^
215+ truncateLen.hashCode;
141216
142217 @override
143218 bool operator == (Object other) {
@@ -153,8 +228,25 @@ class Field {
153228 other.locale == locale &&
154229 other.sort == sort &&
155230 other.enableInfixSearch == enableInfixSearch &&
156- other.reference == reference;
231+ other.reference == reference &&
232+ other.stem == stem &&
233+ other.store == store &&
234+ other.rangeIndex == rangeIndex &&
235+ _listEquals (other.tokenSeparators, tokenSeparators) &&
236+ _listEquals (other.symbolsToIndex, symbolsToIndex) &&
237+ other.stemDictionary == stemDictionary &&
238+ other.truncateLen == truncateLen;
239+ }
240+ }
241+
242+ bool _listEquals <T >(List <T >? a, List <T >? b) {
243+ if (a == null && b == null ) return true ;
244+ if (a == null || b == null ) return false ;
245+ if (a.length != b.length) return false ;
246+ for (int i = 0 ; i < a.length; i++ ) {
247+ if (a[i] != b[i]) return false ;
157248 }
249+ return true ;
158250}
159251
160252/// Used to update a colletion's fields.
@@ -177,6 +269,14 @@ class UpdateField extends Field {
177269 super .locale,
178270 super .sort,
179271 super .enableInfixSearch,
272+ super .reference,
273+ super .stem,
274+ super .store,
275+ super .rangeIndex,
276+ super .tokenSeparators,
277+ super .symbolsToIndex,
278+ super .stemDictionary,
279+ super .truncateLen,
180280 this .shouldDrop = false ,
181281 });
182282
@@ -203,6 +303,14 @@ class UpdateField extends Field {
203303 locale: field.locale,
204304 sort: field.sort,
205305 enableInfixSearch: field.enableInfixSearch,
306+ reference: field.reference,
307+ stem: field.stem,
308+ store: field.store,
309+ rangeIndex: field.rangeIndex,
310+ tokenSeparators: field.tokenSeparators,
311+ symbolsToIndex: field.symbolsToIndex,
312+ stemDictionary: field.stemDictionary,
313+ truncateLen: field.truncateLen,
206314 shouldDrop: map['drop' ] ?? false ,
207315 );
208316 }
@@ -263,6 +371,7 @@ enum Type {
263371 geopoint,
264372 geopolygon,
265373 object,
374+ image,
266375}
267376
268377extension _Type on Type {
@@ -276,6 +385,7 @@ extension _Type on Type {
276385 case Type .geopoint:
277386 case Type .geopolygon:
278387 case Type .object:
388+ case Type .image:
279389 final description = toString (),
280390 indexOfDot = description.indexOf ('.' ),
281391 value = description.substring (indexOfDot + 1 );
0 commit comments