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