@@ -207,6 +207,46 @@ def test_valid_fields(self):
207
207
with connection .schema_editor () as editor :
208
208
editor .remove_index (index = index , model = SearchIndexTestModel )
209
209
210
+ def test_field_mappings (self ):
211
+ index = SearchIndex (
212
+ name = "recent_test_idx" ,
213
+ field_mappings = {
214
+ "custom_field" : {
215
+ "type" : "string" ,
216
+ "analyzer" : "lucene.standard" ,
217
+ "searchAnalyzer" : "lucene.standard" ,
218
+ "norms" : "include" ,
219
+ "store" : True ,
220
+ "indexOptions" : "offsets" ,
221
+ }
222
+ },
223
+ )
224
+ with connection .schema_editor () as editor :
225
+ editor .add_index (index = index , model = SearchIndexTestModel )
226
+ try :
227
+ index_info = connection .introspection .get_constraints (
228
+ cursor = None ,
229
+ table_name = SearchIndexTestModel ._meta .db_table ,
230
+ )
231
+ expected_options = {
232
+ "dynamic" : False ,
233
+ "fields" : {
234
+ "custom_field" : {
235
+ "type" : "string" ,
236
+ "analyzer" : "lucene.standard" ,
237
+ "searchAnalyzer" : "lucene.standard" ,
238
+ "norms" : "include" ,
239
+ "store" : True ,
240
+ "indexOptions" : "offsets" ,
241
+ }
242
+ },
243
+ }
244
+ self .assertCountEqual (index_info [index .name ]["columns" ], index .fields )
245
+ self .assertEqual (index_info [index .name ]["options" ], expected_options )
246
+ finally :
247
+ with connection .schema_editor () as editor :
248
+ editor .remove_index (index = index , model = SearchIndexTestModel )
249
+
210
250
def test_analyzer_inclusion (self ):
211
251
index = SearchIndex (
212
252
name = "recent_test_idx" ,
0 commit comments