@@ -510,38 +510,55 @@ def as_mql(self, compiler, connection):
510
510
return {"$search" : {"moreLikeThis" : params , "index" : index }}
511
511
512
512
513
+ class SearchVector (SearchExpression ):
514
+ def __init__ (
515
+ self ,
516
+ path ,
517
+ query_vector ,
518
+ index ,
519
+ limit ,
520
+ num_candidates = None ,
521
+ exact = None ,
522
+ filter = None ,
523
+ ):
524
+ self .path = path
525
+ self .query_vector = query_vector
526
+ self .index = index
527
+ self .limit = limit
528
+ self .num_candidates = num_candidates
529
+ self .exact = exact
530
+ self .filter = filter
531
+ super ().__init__ ()
532
+
533
+ def as_mql (self , compiler , connection ):
534
+ params = {
535
+ "index" : self .index ,
536
+ "path" : self .path ,
537
+ "queryVector" : self .query_vector ,
538
+ "limit" : self .limit ,
539
+ }
540
+ if self .num_candidates is not None :
541
+ params ["numCandidates" ] = self .num_candidates
542
+ if self .exact is not None :
543
+ params ["exact" ] = self .exact
544
+ if self .filter is not None :
545
+ params ["filter" ] = self .filter
546
+ return {"$vectorSearch" : params }
547
+
548
+
513
549
class SearchScoreOption :
514
550
"""Class to mutate scoring on a search operation"""
515
551
516
552
def __init__ (self , definitions = None ):
517
553
self .definitions = definitions
518
554
519
555
520
- class CombinedSearchExpression (SearchExpression ):
521
- def __init__ (self , lhs , connector , rhs , output_field = None ):
522
- super ().__init__ (output_field = output_field )
523
- self .connector = connector
524
- self .lhs = lhs
525
- self .rhs = rhs
526
-
527
- def as_mql (self , compiler , connection ):
528
- if self .connector == self .AND :
529
- return CompoundExpression (must = [self .lhs , self .rhs ])
530
- if self .connector == self .NEGATION :
531
- return CompoundExpression (must_must = [self .lhs ])
532
- raise ValueError (":)" )
533
-
534
- def __invert__ (self ):
535
- # SHOULD BE MOVED TO THE PARENT
536
- return self
537
-
538
-
539
556
class CompoundExpression (SearchExpression ):
540
557
def __init__ (self , must = None , must_not = None , should = None , filter = None , score = None ):
541
- self .must = must
542
- self .must_not = must_not
543
- self .should = should
544
- self .filter = filter
558
+ self .must = must or []
559
+ self .must_not = must_not or []
560
+ self .should = should or []
561
+ self .filter = filter or []
545
562
self .score = score
546
563
547
564
def as_mql (self , compiler , connection ):
0 commit comments