@@ -141,7 +141,8 @@ class SearchAutocomplete(SearchExpression):
141
141
fuzzy: Optional dictionary of fuzzy matching parameters.
142
142
token_order: Optional value for `"tokenOrder"`; controls sequential vs.
143
143
any-order token matching.
144
- score: Optional expression to adjust score relevance (e.g., `{"boost": {"value": 5}}`).
144
+ score: Optional[SearchScore] expression to adjust score relevance
145
+ (e.g., `{"boost": {"value": 5}}`).
145
146
146
147
Reference: https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/
147
148
"""
@@ -179,7 +180,8 @@ def search_operator(self, compiler, connection):
179
180
180
181
class SearchEquals (SearchExpression ):
181
182
"""
182
- Atlas Search expression that matches documents with a field equal to the given value.
183
+ Atlas Search expression that matches documents with a field equal to
184
+ the given value.
183
185
184
186
This expression uses the `equals` operator to perform exact matches
185
187
on fields indexed in a MongoDB Atlas Search index.
@@ -190,7 +192,7 @@ class SearchEquals(SearchExpression):
190
192
Args:
191
193
path: The document path to compare (as string or expression).
192
194
value: The exact value to match against.
193
- score: Optional expression to modify the relevance score.
195
+ score: Optional[SearchScore] expression to modify the relevance score.
194
196
195
197
Reference: https://www.mongodb.com/docs/atlas/atlas-search/equals/
196
198
"""
@@ -233,7 +235,7 @@ class SearchExists(SearchExpression):
233
235
234
236
Args:
235
237
path: The document path to check (as string or expression).
236
- score: Optional expression to modify the relevance score.
238
+ score: Optional[SearchScore] expression to modify the relevance score.
237
239
238
240
Reference: https://www.mongodb.com/docs/atlas/atlas-search/exists/
239
241
"""
@@ -263,7 +265,8 @@ def search_operator(self, compiler, connection):
263
265
264
266
class SearchIn (SearchExpression ):
265
267
"""
266
- Atlas Search expression that matches documents where the field value is in a given list.
268
+ Atlas Search expression that matches documents where the field value
269
+ is in a given list.
267
270
268
271
This expression uses the `in` operator to match documents whose field
269
272
contains a value from the provided array of values.
@@ -274,7 +277,7 @@ class SearchIn(SearchExpression):
274
277
Args:
275
278
path: The document path to match against (as string or expression).
276
279
value: A list of values to check for membership.
277
- score: Optional expression to adjust the relevance score.
280
+ score: Optional[SearchScore] expression to adjust the relevance score.
278
281
279
282
Reference: https://www.mongodb.com/docs/atlas/atlas-search/in/
280
283
"""
@@ -309,7 +312,8 @@ class SearchPhrase(SearchExpression):
309
312
Atlas Search expression that matches a phrase in the specified field.
310
313
311
314
This expression uses the `phrase` operator to search for exact or near exact
312
- sequences of terms. It supports optional slop (word distance) and synonym sets.
315
+ sequences of terms. It supports optional slop (word distance)
316
+ and synonym sets.
313
317
314
318
Example:
315
319
SearchPhrase("description__text", "climate change", slop=2)
@@ -318,8 +322,9 @@ class SearchPhrase(SearchExpression):
318
322
path: The document path to search (as string or expression).
319
323
query: The phrase to match as a single string or list of terms.
320
324
slop: Optional maximum word distance allowed between phrase terms.
321
- synonyms: Optional name of a synonym mapping defined in the Atlas index.
322
- score: Optional expression to modify the relevance score.
325
+ synonyms: Optional name of a synonym mapping defined in the
326
+ Atlas index.
327
+ score: Optional[SearchScore] expression to modify the relevance score.
323
328
324
329
Reference: https://www.mongodb.com/docs/atlas/atlas-search/phrase/
325
330
"""
@@ -361,15 +366,16 @@ class SearchQueryString(SearchExpression):
361
366
362
367
This expression uses the `queryString` operator to parse and execute
363
368
full-text queries written in a simplified Lucene syntax. It supports
364
- advanced constructs like boolean operators, wildcards, and field-specific terms.
369
+ advanced constructs like boolean operators, wildcards,
370
+ and field-specific terms.
365
371
366
372
Example:
367
373
SearchQueryString("content__text", "django AND (search OR query)")
368
374
369
375
Args:
370
376
path: The document path to query (as string or expression).
371
377
query: The Lucene-style query string.
372
- score: Optional expression to modify the relevance score.
378
+ score: Optional[SearchScore] expression to modify the relevance score.
373
379
374
380
Reference: https://www.mongodb.com/docs/atlas/atlas-search/queryString/
375
381
"""
@@ -415,7 +421,7 @@ class SearchRange(SearchExpression):
415
421
lte: Optional inclusive upper bound (`<=`).
416
422
gt: Optional exclusive lower bound (`>`).
417
423
gte: Optional inclusive lower bound (`>=`).
418
- score: Optional expression to modify the relevance score.
424
+ score: Optional[SearchScore] expression to modify the relevance score.
419
425
420
426
Reference: https://www.mongodb.com/docs/atlas/atlas-search/range/
421
427
"""
@@ -468,8 +474,9 @@ class SearchRegex(SearchExpression):
468
474
Args:
469
475
path: The document path to match (as string or expression).
470
476
query: The regular expression pattern to apply.
471
- allow_analyzed_field: Whether to allow matching against analyzed fields (default is False).
472
- score: Optional expression to modify the relevance score.
477
+ allow_analyzed_field: Whether to allow matching against analyzed
478
+ fields (default is False).
479
+ score: Optional[SearchScore] expression to modify the relevance score.
473
480
474
481
Reference: https://www.mongodb.com/docs/atlas/atlas-search/regex/
475
482
"""
@@ -510,15 +517,22 @@ class SearchText(SearchExpression):
510
517
fuzzy matching, match criteria, and synonyms.
511
518
512
519
Example:
513
- SearchText("description__content", "mongodb", fuzzy={"maxEdits": 1}, match_criteria="all")
520
+ SearchText(
521
+ "description__content",
522
+ "mongodb",
523
+ fuzzy={"maxEdits": 1},
524
+ match_criteria="all"
525
+ )
514
526
515
527
Args:
516
528
path: The document path to search (as string or expression).
517
529
query: The search term or phrase.
518
530
fuzzy: Optional dictionary to configure fuzzy matching parameters.
519
- match_criteria: Optional criteria for term matching (e.g., "all" or "any").
520
- synonyms: Optional name of a synonym mapping defined in the Atlas index.
521
- score: Optional expression to adjust relevance scoring.
531
+ match_criteria: Optional criteria for term matching
532
+ (e.g., "all" or "any").
533
+ synonyms: Optional name of a synonym mapping defined in the
534
+ Atlas index.
535
+ score: Optional[SearchScore] expression to adjust relevance scoring.
522
536
523
537
Reference: https://www.mongodb.com/docs/atlas/atlas-search/text/
524
538
"""
@@ -570,8 +584,9 @@ class SearchWildcard(SearchExpression):
570
584
Args:
571
585
path: The document path to search (as string or expression).
572
586
query: The wildcard pattern to match.
573
- allow_analyzed_field: Whether to allow matching against analyzed fields (default is False).
574
- score: Optional expression to modify the relevance score.
587
+ allow_analyzed_field: Whether to allow matching against analyzed
588
+ fields (default is False).
589
+ score: Optional[SearchScore] expression to modify the relevance score.
575
590
576
591
Reference: https://www.mongodb.com/docs/atlas/atlas-search/wildcard/
577
592
"""
@@ -606,19 +621,22 @@ def search_operator(self, compiler, connection):
606
621
607
622
class SearchGeoShape (SearchExpression ):
608
623
"""
609
- Atlas Search expression that filters documents by spatial relationship with a geometry.
624
+ Atlas Search expression that filters documents by spatial relationship
625
+ with a geometry.
610
626
611
627
This expression uses the `geoShape` operator to match documents where
612
628
a geo field relates to a specified geometry by a spatial relation.
613
629
614
630
Example:
615
- SearchGeoShape("location", "within", {"type": "Polygon", "coordinates": [...]})
631
+ SearchGeoShape("location", "within",
632
+ {"type": "Polygon", "coordinates": [...]})
616
633
617
634
Args:
618
635
path: The document path to the geo field (as string or expression).
619
- relation: The spatial relation to test (e.g., "within", "intersects", "disjoint").
636
+ relation: The spatial relation to test
637
+ (e.g., "within", "intersects", "disjoint").
620
638
geometry: The GeoJSON geometry to compare against.
621
- score: Optional expression to modify the relevance score.
639
+ score: Optional[SearchScore] expression to modify the relevance score.
622
640
623
641
Reference: https://www.mongodb.com/docs/atlas/atlas-search/geoShape/
624
642
"""
@@ -659,13 +677,14 @@ class SearchGeoWithin(SearchExpression):
659
677
the geo field lies entirely within the given geometry.
660
678
661
679
Example:
662
- SearchGeoWithin("location", "Polygon", {"type": "Polygon", "coordinates": [...]})
680
+ SearchGeoWithin("location", "Polygon",
681
+ {"type": "Polygon", "coordinates": [...]})
663
682
664
683
Args:
665
684
path: The document path to the geo field (as string or expression).
666
685
kind: The GeoJSON geometry type (e.g., "Polygon", "MultiPolygon").
667
686
geo_object: The GeoJSON geometry defining the boundary.
668
- score: Optional expression to adjust the relevance score.
687
+ score: Optional[SearchScore] expression to adjust the relevance score.
669
688
670
689
Reference: https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/
671
690
"""
@@ -707,8 +726,10 @@ class SearchMoreLikeThis(SearchExpression):
707
726
SearchMoreLikeThis([{"_id": ObjectId("...")}, {"title": "Example"}])
708
727
709
728
Args:
710
- documents: A list of example documents or expressions to find similar documents.
711
- score: Optional expression to modify the relevance scoring.
729
+ documents: A list of example documents or expressions to find similar
730
+ documents.
731
+ score: Optional[SearchScore] expression to modify the relevance
732
+ scoring.
712
733
713
734
Reference: https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/
714
735
"""
@@ -741,11 +762,12 @@ def get_search_fields(self, compiler, connection):
741
762
742
763
class CompoundExpression (SearchExpression ):
743
764
"""
744
- Compound expression that combines multiple search clauses using boolean logic.
765
+ Compound expression that combines multiple search clauses using boolean
766
+ logic.
745
767
746
- This expression corresponds to the `compound` operator in MongoDB Atlas Search,
747
- allowing fine-grained control by combining multiple sub-expressions with
748
- `must`, `must_not`, `should`, and `filter` clauses.
768
+ This expression corresponds to the `compound` operator in MongoDB Atlas
769
+ Search, allowing fine-grained control by combining multiple
770
+ sub-expressions with `must`, `must_not`, `should`, and `filter` clauses.
749
771
750
772
Example:
751
773
CompoundExpression(
@@ -758,10 +780,13 @@ class CompoundExpression(SearchExpression):
758
780
Args:
759
781
must: List of expressions that **must** match.
760
782
must_not: List of expressions that **must not** match.
761
- should: List of expressions that **should** match (optional relevance boost).
762
- filter: List of expressions to filter results without affecting relevance.
763
- score: Optional expression to adjust scoring.
764
- minimum_should_match: Minimum number of `should` clauses that must match.
783
+ should: List of expressions that **should** match
784
+ (optional relevance boost).
785
+ filter: List of expressions to filter results without affecting
786
+ relevance.
787
+ score: Optional[SearchScore] expression to adjust scoring.
788
+ minimum_should_match: Minimum number of `should` clauses that
789
+ must match.
765
790
766
791
Reference: https://www.mongodb.com/docs/atlas/atlas-search/compound/
767
792
"""
@@ -884,22 +909,27 @@ def as_mql(self, compiler, connection):
884
909
885
910
class SearchVector (SearchExpression ):
886
911
"""
887
- Atlas Search expression that performs vector similarity search using `$vectorSearch`.
912
+ Atlas Search expression that performs vector similarity search
913
+ using `$vectorSearch`.
888
914
889
- This expression uses the `$vectorSearch` stage to retrieve documents whose vector
890
- embeddings are most similar to a given query vector, according to approximate or
891
- exact nearest-neighbor search.
915
+ This expression uses the `$vectorSearch` stage to retrieve documents
916
+ whose vector embeddings are most similar to a given query vector,
917
+ according to approximate or exact nearest-neighbor search.
892
918
893
919
Example:
894
- SearchVector("embedding", [0.1, 0.2, 0.3], limit=10, num_candidates=100)
920
+ SearchVector("embedding", [0.1, 0.2, 0.3], limit=10,
921
+ num_candidates=100)
895
922
896
923
Args:
897
924
path: The document path to the vector field (as string or expression).
898
925
query_vector: The query vector to compare against.
899
926
limit: Maximum number of matching documents to return.
900
- num_candidates: Optional number of candidates to consider during search.
901
- exact: Optional flag to enforce exact matching (default is approximate).
902
- filter: Optional filter expression to narrow candidate documents.
927
+ num_candidates: Optional number of candidates to consider
928
+ during search.
929
+ exact: Optional flag to enforce exact matching (default is
930
+ approximate).
931
+ filter: Optional raw mql filter expression to narrow
932
+ candidate documents.
903
933
904
934
Reference: https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/
905
935
"""
0 commit comments