@@ -81,6 +81,8 @@ def get_source_expressions(self):
81
81
82
82
@staticmethod
83
83
def cast_as_value (value ):
84
+ if value is None :
85
+ return None
84
86
return Value (value ) if not hasattr (value , "resolve_expression" ) else value
85
87
86
88
@staticmethod
@@ -131,14 +133,14 @@ def get_search_fields(self, compiler, connection):
131
133
def search_operator (self , compiler , connection ):
132
134
params = {
133
135
"path" : self .path .as_mql (compiler , connection , as_path = True ),
134
- "query" : self .query .as_mql ( compiler , connection ) ,
136
+ "query" : self .query .value ,
135
137
}
136
138
if self .score is not None :
137
139
params ["score" ] = self .score .as_mql (compiler , connection )
138
140
if self .fuzzy is not None :
139
- params ["fuzzy" ] = self .fuzzy .as_mql ( compiler , connection )
141
+ params ["fuzzy" ] = self .fuzzy .value
140
142
if self .token_order is not None :
141
- params ["tokenOrder" ] = self .token_order .as_mql ( compiler , connection )
143
+ params ["tokenOrder" ] = self .token_order .value
142
144
return {"autocomplete" : params }
143
145
144
146
@@ -161,7 +163,7 @@ def set_source_expressions(self, exprs):
161
163
def search_operator (self , compiler , connection ):
162
164
params = {
163
165
"path" : self .path .as_mql (compiler , connection , as_path = True ),
164
- "value" : self .value .as_mql ( compiler , connection ) ,
166
+ "value" : self .value .value ,
165
167
}
166
168
if self .score is not None :
167
169
params ["score" ] = self .score .as_mql (compiler , connection )
@@ -211,10 +213,10 @@ def set_source_expressions(self, exprs):
211
213
def search_operator (self , compiler , connection ):
212
214
params = {
213
215
"path" : self .path .as_mql (compiler , connection , as_path = True ),
214
- "value" : self .value .as_mql ( compiler , connection ) ,
216
+ "value" : self .value .value ,
215
217
}
216
218
if self .score is not None :
217
- params ["score" ] = self .score .definitions
219
+ params ["score" ] = self .score .as_mql ( compiler , connection )
218
220
return {"in" : params }
219
221
220
222
@@ -239,14 +241,14 @@ def set_source_expressions(self, exprs):
239
241
def search_operator (self , compiler , connection ):
240
242
params = {
241
243
"path" : self .path .as_mql (compiler , connection , as_path = True ),
242
- "query" : self .query .as_mql ( compiler , connection ) ,
244
+ "query" : self .query .value ,
243
245
}
244
246
if self .score is not None :
245
247
params ["score" ] = self .score .as_mql (compiler , connection )
246
248
if self .slop is not None :
247
- params ["slop" ] = self .slop .as_mql ( compiler , connection )
249
+ params ["slop" ] = self .slop .value
248
250
if self .synonyms is not None :
249
- params ["synonyms" ] = self .synonyms .as_mql ( compiler , connection )
251
+ params ["synonyms" ] = self .synonyms .value
250
252
return {"phrase" : params }
251
253
252
254
@@ -269,10 +271,10 @@ def set_source_expressions(self, exprs):
269
271
def search_operator (self , compiler , connection ):
270
272
params = {
271
273
"defaultPath" : self .path .as_mql (compiler , connection , as_path = True ),
272
- "query" : self .query .as_mql ( compiler , connection ) ,
274
+ "query" : self .query .value ,
273
275
}
274
276
if self .score is not None :
275
- params ["score" ] = self .score .definitions
277
+ params ["score" ] = self .score .as_mql ( compiler , connection )
276
278
return {"queryString" : params }
277
279
278
280
@@ -300,15 +302,15 @@ def search_operator(self, compiler, connection):
300
302
"path" : self .path .as_mql (compiler , connection , as_path = True ),
301
303
}
302
304
if self .score is not None :
303
- params ["score" ] = self .score .definitions
305
+ params ["score" ] = self .score .as_mql ( compiler , connection )
304
306
if self .lt is not None :
305
- params ["lt" ] = self .lt .as_mql ( compiler , connection )
307
+ params ["lt" ] = self .lt .value
306
308
if self .lte is not None :
307
- params ["lte" ] = self .lte .as_mql ( compiler , connection )
309
+ params ["lte" ] = self .lte .value
308
310
if self .gt is not None :
309
- params ["gt" ] = self .gt .as_mql ( compiler , connection )
311
+ params ["gt" ] = self .gt .value
310
312
if self .gte is not None :
311
- params ["gte" ] = self .gte .as_mql ( compiler , connection )
313
+ params ["gte" ] = self .gte .value
312
314
return {"range" : params }
313
315
314
316
@@ -332,12 +334,12 @@ def set_source_expressions(self, exprs):
332
334
def search_operator (self , compiler , connection ):
333
335
params = {
334
336
"path" : self .path .as_mql (compiler , connection , as_path = True ),
335
- "query" : self .query .as_mql ( compiler , connection , as_path = True ) ,
337
+ "query" : self .query .value ,
336
338
}
337
339
if self .score :
338
- params ["score" ] = self .score .definitions
340
+ params ["score" ] = self .score .as_mql ( compiler , connection )
339
341
if self .allow_analyzed_field is not None :
340
- params ["allowAnalyzedField" ] = self .allow_analyzed_field
342
+ params ["allowAnalyzedField" ] = self .allow_analyzed_field . value
341
343
return {"regex" : params }
342
344
343
345
@@ -363,16 +365,16 @@ def set_source_expressions(self, exprs):
363
365
def search_operator (self , compiler , connection ):
364
366
params = {
365
367
"path" : self .path .as_mql (compiler , connection , as_path = True ),
366
- "query" : self .query .as_mql ( compiler , connection , as_path = True ) ,
368
+ "query" : self .query .value ,
367
369
}
368
370
if self .score :
369
- params ["score" ] = self .score .definitions
371
+ params ["score" ] = self .score .as_mql ( compiler , connection )
370
372
if self .fuzzy is not None :
371
- params ["fuzzy" ] = self .fuzzy
373
+ params ["fuzzy" ] = self .fuzzy . value
372
374
if self .match_criteria is not None :
373
- params ["matchCriteria" ] = self .match_criteria
375
+ params ["matchCriteria" ] = self .match_criteria . value
374
376
if self .synonyms is not None :
375
- params ["synonyms" ] = self .synonyms
377
+ params ["synonyms" ] = self .synonyms . value
376
378
return {"text" : params }
377
379
378
380
@@ -396,12 +398,12 @@ def set_source_expressions(self, exprs):
396
398
def search_operator (self , compiler , connection ):
397
399
params = {
398
400
"path" : self .path .as_mql (compiler , connection , as_path = True ),
399
- "query" : self .query .as_mql ( compiler , connection , as_path = True ) ,
401
+ "query" : self .query .value ,
400
402
}
401
403
if self .score :
402
- params ["score" ] = self .score .definitions
404
+ params ["score" ] = self .score .query . as_mql ( compiler , connection )
403
405
if self .allow_analyzed_field is not None :
404
- params ["allowAnalyzedField" ] = self .allow_analyzed_field
406
+ params ["allowAnalyzedField" ] = self .allow_analyzed_field . value
405
407
return {"wildcard" : params }
406
408
407
409
@@ -425,11 +427,11 @@ def set_source_expressions(self, exprs):
425
427
def search_operator (self , compiler , connection ):
426
428
params = {
427
429
"path" : self .path .as_mql (compiler , connection , as_path = True ),
428
- "relation" : self .relation ,
429
- "geometry" : self .geometry ,
430
+ "relation" : self .relation . value ,
431
+ "geometry" : self .geometry . value ,
430
432
}
431
433
if self .score :
432
- params ["score" ] = self .score .definitions
434
+ params ["score" ] = self .score .as_mql ( compiler , connection )
433
435
return {"geoShape" : params }
434
436
435
437
@@ -453,10 +455,10 @@ def set_source_expressions(self, exprs):
453
455
def search_operator (self , compiler , connection ):
454
456
params = {
455
457
"path" : self .path .as_mql (compiler , connection , as_path = True ),
456
- self .kind : self .geo_object ,
458
+ self .kind . value : self .geo_object . value ,
457
459
}
458
460
if self .score :
459
- params ["score" ] = self .score .definitions
461
+ params ["score" ] = self .score .as_mql ( compiler , connection )
460
462
return {"geoWithin" : params }
461
463
462
464
@@ -474,10 +476,10 @@ def set_source_expressions(self, exprs):
474
476
475
477
def search_operator (self , compiler , connection ):
476
478
params = {
477
- "like" : self .documents ,
479
+ "like" : self .documents . as_mql ( compiler , connection ) ,
478
480
}
479
481
if self .score :
480
- params ["score" ] = self .score .definitions
482
+ params ["score" ] = self .score .as_mql ( compiler , connection )
481
483
return {"moreLikeThis" : params }
482
484
483
485
def get_search_fields (self , compiler , connection ):
@@ -507,7 +509,7 @@ def __init__(
507
509
def get_search_fields (self , compiler , connection ):
508
510
fields = set ()
509
511
for clause in self .must + self .should + self .filter + self .must_not :
510
- fields .update (clause .get_search_fields ())
512
+ fields .update (clause .get_search_fields (compiler , connection ))
511
513
return fields
512
514
513
515
def resolve_expression (
@@ -532,13 +534,19 @@ def resolve_expression(
532
534
def search_operator (self , compiler , connection ):
533
535
params = {}
534
536
if self .must :
535
- params ["must" ] = [clause .search_operator () for clause in self .must ]
537
+ params ["must" ] = [clause .search_operator (compiler , connection ) for clause in self .must ]
536
538
if self .must_not :
537
- params ["mustNot" ] = [clause .search_operator () for clause in self .must_not ]
539
+ params ["mustNot" ] = [
540
+ clause .search_operator (compiler , connection ) for clause in self .must_not
541
+ ]
538
542
if self .should :
539
- params ["should" ] = [clause .search_operator () for clause in self .should ]
543
+ params ["should" ] = [
544
+ clause .search_operator (compiler , connection ) for clause in self .should
545
+ ]
540
546
if self .filter :
541
- params ["filter" ] = [clause .search_operator () for clause in self .filter ]
547
+ params ["filter" ] = [
548
+ clause .search_operator (compiler , connection ) for clause in self .filter
549
+ ]
542
550
if self .minimum_should_match is not None :
543
551
params ["minimumShouldMatch" ] = self .minimum_should_match
544
552
return {"compound" : params }
@@ -650,15 +658,15 @@ def _get_query_index(self, fields, compiler):
650
658
651
659
def as_mql (self , compiler , connection ):
652
660
params = {
653
- "index" : self ._get_query_index (self .get_search_fields (), compiler ),
661
+ "index" : self ._get_query_index (self .get_search_fields (compiler , connection ), compiler ),
654
662
"path" : self .path .as_mql (compiler , connection , as_path = True ),
655
- "queryVector" : self .query_vector .as_mql ( compiler , connection ) ,
656
- "limit" : self .limit .as_mql ( compiler , connection ) ,
663
+ "queryVector" : self .query_vector .value ,
664
+ "limit" : self .limit .value ,
657
665
}
658
666
if self .num_candidates is not None :
659
- params ["numCandidates" ] = self .num_candidates .as_mql ( compiler , connection )
667
+ params ["numCandidates" ] = self .num_candidates .value
660
668
if self .exact is not None :
661
- params ["exact" ] = self .exact .as_mql ( compiler , connection )
669
+ params ["exact" ] = self .exact .value
662
670
if self .filter is not None :
663
671
params ["filter" ] = self .filter .as_mql (compiler , connection )
664
672
return {"$vectorSearch" : params }
0 commit comments