@@ -38,7 +38,33 @@ def test_vector_index_not_created(self):
38
38
)
39
39
40
40
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
+
41
55
class 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
+
42
68
def test_deconstruct (self ):
43
69
index = VectorSearchIndex (name = "recent_test_idx" , fields = ["number" ])
44
70
name , args , kwargs = index .deconstruct ()
@@ -48,15 +74,15 @@ def test_deconstruct(self):
48
74
def test_deconstruct_with_similarities (self ):
49
75
index = VectorSearchIndex (
50
76
name = "recent_test_idx" ,
51
- fields = ["number" , "text " ],
77
+ fields = ["number" , "char " ],
52
78
similarities = ["cosine" , "dotProduct" ],
53
79
)
54
80
path , args , kwargs = index .deconstruct ()
55
81
self .assertEqual (
56
82
kwargs ,
57
83
{
58
84
"name" : "recent_test_idx" ,
59
- "fields" : ["number" , "text " ],
85
+ "fields" : ["number" , "char " ],
60
86
"similarities" : ["cosine" , "dotProduct" ],
61
87
},
62
88
)
@@ -87,23 +113,25 @@ class SearchIndexSchemaTests(SchemaAssertionMixin, TestCase):
87
113
def test_simple (self ):
88
114
index = SearchIndex (
89
115
name = "recent_test_idx" ,
90
- fields = ["text " ],
116
+ fields = ["char " ],
91
117
)
92
118
with connection .schema_editor () as editor :
93
119
self .assertAddRemoveIndex (editor , index = index , model = SearchIndexTestModel )
94
120
95
- def test_all_fields (self ):
121
+ def test_valid_fields (self ):
96
122
index = SearchIndex (
97
123
name = "recent_test_idx" ,
98
124
fields = [
125
+ "big_integer" ,
126
+ "binary" ,
127
+ "char" ,
99
128
"boolean" ,
100
- "date " ,
101
- "embedded " ,
129
+ "datetime " ,
130
+ "embedded_model " ,
102
131
"float" ,
103
- "json_data " ,
104
- "number " ,
132
+ "integer " ,
133
+ "json " ,
105
134
"object_id" ,
106
- "text" ,
107
135
"vector_integer" ,
108
136
"vector_float" ,
109
137
],
@@ -118,29 +146,41 @@ def test_all_fields(self):
118
146
expected_options = {
119
147
"dynamic" : False ,
120
148
"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
+ },
121
161
"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" },
124
170
"float" : {
125
171
"indexDoubles" : True ,
126
172
"indexIntegers" : True ,
127
173
"representation" : "double" ,
128
174
"type" : "number" ,
129
175
},
130
- "json_data" : {"dynamic" : False , "fields" : {}, "type" : "document" },
131
- "number" : {
176
+ "integer" : {
132
177
"indexDoubles" : True ,
133
178
"indexIntegers" : True ,
134
179
"representation" : "double" ,
135
180
"type" : "number" ,
136
181
},
182
+ "json" : {"dynamic" : False , "fields" : {}, "type" : "document" },
137
183
"object_id" : {"type" : "objectId" },
138
- "text" : {
139
- "indexOptions" : "offsets" ,
140
- "norms" : "include" ,
141
- "store" : True ,
142
- "type" : "string" ,
143
- },
144
184
"vector_float" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
145
185
"vector_integer" : {"dynamic" : False , "fields" : {}, "type" : "embeddedDocuments" },
146
186
},
@@ -155,22 +195,22 @@ def test_all_fields(self):
155
195
@skipUnlessDBFeature ("supports_atlas_search" )
156
196
class VectorSearchIndexSchemaTests (SchemaAssertionMixin , TestCase ):
157
197
def test_simple (self ):
158
- index = VectorSearchIndex (name = "recent_test_idx" , fields = ["number " ])
198
+ index = VectorSearchIndex (name = "recent_test_idx" , fields = ["integer " ])
159
199
with connection .schema_editor () as editor :
160
200
self .assertAddRemoveIndex (editor , index = index , model = SearchIndexTestModel )
161
201
162
202
def test_multiple_fields (self ):
163
203
index = VectorSearchIndex (
164
204
name = "recent_test_idx" ,
165
205
fields = [
166
- "text" ,
206
+ "boolean" ,
207
+ "char" ,
208
+ "datetime" ,
209
+ "embedded_model" ,
210
+ "integer" ,
167
211
"object_id" ,
168
- "number" ,
169
- "embedded" ,
170
- "vector_integer" ,
171
212
"vector_float" ,
172
- "boolean" ,
173
- "date" ,
213
+ "vector_integer" ,
174
214
],
175
215
)
176
216
with connection .schema_editor () as editor :
@@ -183,24 +223,24 @@ def test_multiple_fields(self):
183
223
expected_options = {
184
224
"latestDefinition" : {
185
225
"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" },
187
231
{"path" : "object_id" , "type" : "filter" },
188
- {"path" : "number" , "type" : "filter" },
189
- {"path" : "embedded" , "type" : "filter" },
190
232
{
191
233
"numDimensions" : 10 ,
192
- "path" : "vector_integer " ,
234
+ "path" : "vector_float " ,
193
235
"similarity" : "cosine" ,
194
236
"type" : "vector" ,
195
237
},
196
238
{
197
239
"numDimensions" : 10 ,
198
- "path" : "vector_float " ,
240
+ "path" : "vector_integer " ,
199
241
"similarity" : "cosine" ,
200
242
"type" : "vector" ,
201
243
},
202
- {"path" : "boolean" , "type" : "filter" },
203
- {"path" : "date" , "type" : "filter" },
204
244
]
205
245
},
206
246
"latestVersion" : 0 ,
0 commit comments