@@ -38,7 +38,33 @@ def test_vector_index_not_created(self):
3838 )
3939
4040
41+ class SearchIndexTests (SimpleTestCase ):
42+ def test_no_init_args (self ):
43+ """All arguments must be kwargs."""
44+ msg = "SearchIndex.__init__() takes 1 positional argument but 2 were given"
45+ with self .assertRaisesMessage (TypeError , msg ):
46+ SearchIndex ("foo" )
47+
48+ def test_no_extra_kargs (self ):
49+ """Unused wargs that appear on Index aren't accepted."""
50+ msg = "SearchIndex.__init__() got an unexpected keyword argument 'condition'"
51+ with self .assertRaisesMessage (TypeError , msg ):
52+ SearchIndex (condition = "" )
53+
54+
4155class VectorSearchIndexTests (SimpleTestCase ):
56+ def test_no_init_args (self ):
57+ """All arguments must be kwargs."""
58+ msg = "VectorSearchIndex.__init__() takes 1 positional argument but 2 were given"
59+ with self .assertRaisesMessage (TypeError , msg ):
60+ VectorSearchIndex ("foo" )
61+
62+ def test_no_extra_kargs (self ):
63+ """Unused wargs that appear on Index aren't accepted."""
64+ msg = "VectorSearchIndex.__init__() got an unexpected keyword argument 'condition'"
65+ with self .assertRaisesMessage (TypeError , msg ):
66+ VectorSearchIndex (condition = "" )
67+
4268 def test_deconstruct (self ):
4369 index = VectorSearchIndex (name = "recent_test_idx" , fields = ["number" ])
4470 name , args , kwargs = index .deconstruct ()
@@ -48,15 +74,15 @@ def test_deconstruct(self):
4874 def test_deconstruct_with_similarities (self ):
4975 index = VectorSearchIndex (
5076 name = "recent_test_idx" ,
51- fields = ["number" , "text " ],
77+ fields = ["number" , "char " ],
5278 similarities = ["cosine" , "dotProduct" ],
5379 )
5480 path , args , kwargs = index .deconstruct ()
5581 self .assertEqual (
5682 kwargs ,
5783 {
5884 "name" : "recent_test_idx" ,
59- "fields" : ["number" , "text " ],
85+ "fields" : ["number" , "char " ],
6086 "similarities" : ["cosine" , "dotProduct" ],
6187 },
6288 )
@@ -87,23 +113,25 @@ class SearchIndexSchemaTests(SchemaAssertionMixin, TestCase):
87113 def test_simple (self ):
88114 index = SearchIndex (
89115 name = "recent_test_idx" ,
90- fields = ["text " ],
116+ fields = ["char " ],
91117 )
92118 with connection .schema_editor () as editor :
93119 self .assertAddRemoveIndex (editor , index = index , model = SearchIndexTestModel )
94120
95- def test_all_fields (self ):
121+ def test_valid_fields (self ):
96122 index = SearchIndex (
97123 name = "recent_test_idx" ,
98124 fields = [
125+ "big_integer" ,
126+ "binary" ,
127+ "char" ,
99128 "boolean" ,
100- "date " ,
101- "embedded " ,
129+ "datetime " ,
130+ "embedded_model " ,
102131 "float" ,
103- "json_data " ,
104- "number " ,
132+ "integer " ,
133+ "json " ,
105134 "object_id" ,
106- "text" ,
107135 "vector_integer" ,
108136 "vector_float" ,
109137 ],
@@ -118,29 +146,41 @@ def test_all_fields(self):
118146 expected_options = {
119147 "dynamic" : False ,
120148 "fields" : {
149+ "big_integer" : {
150+ "indexDoubles" : True ,
151+ "indexIntegers" : True ,
152+ "representation" : "double" ,
153+ "type" : "number" ,
154+ },
155+ "binary" : {
156+ "indexOptions" : "offsets" ,
157+ "norms" : "include" ,
158+ "store" : True ,
159+ "type" : "string" ,
160+ },
121161 "boolean" : {"type" : "boolean" },
122- "date" : {"type" : "date" },
123- "embedded" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
162+ "char" : {
163+ "indexOptions" : "offsets" ,
164+ "norms" : "include" ,
165+ "store" : True ,
166+ "type" : "string" ,
167+ },
168+ "datetime" : {"type" : "date" },
169+ "embedded_model" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
124170 "float" : {
125171 "indexDoubles" : True ,
126172 "indexIntegers" : True ,
127173 "representation" : "double" ,
128174 "type" : "number" ,
129175 },
130- "json_data" : {"dynamic" : False , "fields" : {}, "type" : "document" },
131- "number" : {
176+ "integer" : {
132177 "indexDoubles" : True ,
133178 "indexIntegers" : True ,
134179 "representation" : "double" ,
135180 "type" : "number" ,
136181 },
182+ "json" : {"dynamic" : False , "fields" : {}, "type" : "document" },
137183 "object_id" : {"type" : "objectId" },
138- "text" : {
139- "indexOptions" : "offsets" ,
140- "norms" : "include" ,
141- "store" : True ,
142- "type" : "string" ,
143- },
144184 "vector_float" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
145185 "vector_integer" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
146186 },
@@ -155,22 +195,22 @@ def test_all_fields(self):
155195@skipUnlessDBFeature ("supports_atlas_search" )
156196class VectorSearchIndexSchemaTests (SchemaAssertionMixin , TestCase ):
157197 def test_simple (self ):
158- index = VectorSearchIndex (name = "recent_test_idx" , fields = ["number " ])
198+ index = VectorSearchIndex (name = "recent_test_idx" , fields = ["integer " ])
159199 with connection .schema_editor () as editor :
160200 self .assertAddRemoveIndex (editor , index = index , model = SearchIndexTestModel )
161201
162202 def test_multiple_fields (self ):
163203 index = VectorSearchIndex (
164204 name = "recent_test_idx" ,
165205 fields = [
166- "text" ,
206+ "boolean" ,
207+ "char" ,
208+ "datetime" ,
209+ "embedded_model" ,
210+ "integer" ,
167211 "object_id" ,
168- "number" ,
169- "embedded" ,
170- "vector_integer" ,
171212 "vector_float" ,
172- "boolean" ,
173- "date" ,
213+ "vector_integer" ,
174214 ],
175215 )
176216 with connection .schema_editor () as editor :
@@ -183,24 +223,24 @@ def test_multiple_fields(self):
183223 expected_options = {
184224 "latestDefinition" : {
185225 "fields" : [
186- {"path" : "text" , "type" : "filter" },
226+ {"path" : "boolean" , "type" : "filter" },
227+ {"path" : "char" , "type" : "filter" },
228+ {"path" : "datetime" , "type" : "filter" },
229+ {"path" : "embedded_model" , "type" : "filter" },
230+ {"path" : "integer" , "type" : "filter" },
187231 {"path" : "object_id" , "type" : "filter" },
188- {"path" : "number" , "type" : "filter" },
189- {"path" : "embedded" , "type" : "filter" },
190232 {
191233 "numDimensions" : 10 ,
192- "path" : "vector_integer " ,
234+ "path" : "vector_float " ,
193235 "similarity" : "cosine" ,
194236 "type" : "vector" ,
195237 },
196238 {
197239 "numDimensions" : 10 ,
198- "path" : "vector_float " ,
240+ "path" : "vector_integer " ,
199241 "similarity" : "cosine" ,
200242 "type" : "vector" ,
201243 },
202- {"path" : "boolean" , "type" : "filter" },
203- {"path" : "date" , "type" : "filter" },
204244 ]
205245 },
206246 "latestVersion" : 0 ,
0 commit comments