@@ -71,7 +71,7 @@ def __or__(self, other):
71
71
return self ._combine (other , Operator (Operator .OR ))
72
72
73
73
def __ror__ (self , other ):
74
- return self ._combine (self , Operator (Operator .OR ), other )
74
+ return self ._combine (other , Operator (Operator .OR ))
75
75
76
76
77
77
class SearchExpression (SearchCombinable , Expression ):
@@ -101,10 +101,14 @@ def get_source_expressions(self):
101
101
return []
102
102
103
103
def _get_indexed_fields (self , mappings ):
104
- for field , definition in mappings .get ("fields" , {}).items ():
105
- yield field
106
- for path in self ._get_indexed_fields (definition ):
107
- yield f"{ field } .{ path } "
104
+ if isinstance (mappings , list ):
105
+ for definition in mappings :
106
+ yield from self ._get_indexed_fields (definition )
107
+ else :
108
+ for field , definition in mappings .get ("fields" , {}).items ():
109
+ yield field
110
+ for path in self ._get_indexed_fields (definition ):
111
+ yield f"{ field } .{ path } "
108
112
109
113
def _get_query_index (self , fields , compiler ):
110
114
fields = set (fields )
@@ -142,9 +146,7 @@ class SearchAutocomplete(SearchExpression):
142
146
any-order token matching.
143
147
score: Optional expression to adjust score relevance (e.g., `{"boost": {"value": 5}}`).
144
148
145
- Notes:
146
- * Requires an Atlas Search index with `autocomplete` mappings.
147
- * The operator is injected under the `$search` stage in the aggregation pipeline.
149
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/
148
150
"""
149
151
150
152
def __init__ (self , path , query , fuzzy = None , token_order = None , score = None ):
@@ -193,10 +195,7 @@ class SearchEquals(SearchExpression):
193
195
value: The exact value to match against.
194
196
score: Optional expression to modify the relevance score.
195
197
196
- Notes:
197
- * The field must be indexed with a supported type for `equals`.
198
- * Supports numeric, string, boolean, and date values.
199
- * Score boosting can be applied using the `score` parameter.
198
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/equals/
200
199
"""
201
200
202
201
def __init__ (self , path , value , score = None ):
@@ -239,9 +238,7 @@ class SearchExists(SearchExpression):
239
238
path: The document path to check (as string or expression).
240
239
score: Optional expression to modify the relevance score.
241
240
242
- Notes:
243
- * The target field must be mapped in the Atlas Search index.
244
- * This does not test for null—only for presence.
241
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/exists/
245
242
"""
246
243
247
244
def __init__ (self , path , score = None ):
@@ -268,6 +265,23 @@ def search_operator(self, compiler, connection):
268
265
269
266
270
267
class SearchIn (SearchExpression ):
268
+ """
269
+ Atlas Search expression that matches documents where the field value is in a given list.
270
+
271
+ This expression uses the **in** operator to match documents whose field
272
+ contains a value from the provided array of values.
273
+
274
+ Example:
275
+ SearchIn("status", ["pending", "approved", "rejected"])
276
+
277
+ Args:
278
+ path: The document path to match against (as string or expression).
279
+ value: A list of values to check for membership.
280
+ score: Optional expression to adjust the relevance score.
281
+
282
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/in/
283
+ """
284
+
271
285
def __init__ (self , path , value , score = None ):
272
286
self .path = cast_as_field (path )
273
287
self .value = cast_as_value (value )
@@ -297,7 +311,7 @@ class SearchPhrase(SearchExpression):
297
311
"""
298
312
Atlas Search expression that matches a phrase in the specified field.
299
313
300
- This expression uses the **phrase** operator to search for exact or near- exact
314
+ This expression uses the **phrase** operator to search for exact or near exact
301
315
sequences of terms. It supports optional slop (word distance) and synonym sets.
302
316
303
317
Example:
@@ -310,10 +324,7 @@ class SearchPhrase(SearchExpression):
310
324
synonyms: Optional name of a synonym mapping defined in the Atlas index.
311
325
score: Optional expression to modify the relevance score.
312
326
313
- Notes:
314
- * The field must be mapped as `"type": "string"` with appropriate analyzers.
315
- * Slop allows flexibility in word positioning, like `"quick brown fox"`
316
- matching `"quick fox"` if `slop=1`.
327
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/phrase/
317
328
"""
318
329
319
330
def __init__ (self , path , query , slop = None , synonyms = None , score = None ):
@@ -363,9 +374,7 @@ class SearchQueryString(SearchExpression):
363
374
query: The Lucene-style query string.
364
375
score: Optional expression to modify the relevance score.
365
376
366
- Notes:
367
- * The query string syntax must conform to Atlas Search rules.
368
- * This operator is powerful but can be harder to validate or sanitize.
377
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/queryString/
369
378
"""
370
379
371
380
def __init__ (self , path , query , score = None ):
@@ -411,9 +420,7 @@ class SearchRange(SearchExpression):
411
420
gte: Optional inclusive lower bound (`>=`).
412
421
score: Optional expression to modify the relevance score.
413
422
414
- Notes:
415
- * At least one of `lt`, `lte`, `gt`, or `gte` must be provided.
416
- * The field must be mapped in the Atlas Search index as a comparable type.
423
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/range/
417
424
"""
418
425
419
426
def __init__ (self , path , lt = None , lte = None , gt = None , gte = None , score = None ):
@@ -467,10 +474,7 @@ class SearchRegex(SearchExpression):
467
474
allow_analyzed_field: Whether to allow matching against analyzed fields (default is False).
468
475
score: Optional expression to modify the relevance score.
469
476
470
- Notes:
471
- * Regular expressions must follow JavaScript regex syntax.
472
- * By default, the field must be mapped as `"analyzer": "keyword"`
473
- unless `allow_analyzed_field=True`.
477
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/regex/
474
478
"""
475
479
476
480
def __init__ (self , path , query , allow_analyzed_field = None , score = None ):
@@ -519,9 +523,7 @@ class SearchText(SearchExpression):
519
523
synonyms: Optional name of a synonym mapping defined in the Atlas index.
520
524
score: Optional expression to adjust relevance scoring.
521
525
522
- Notes:
523
- * The target field must be indexed for full-text search in Atlas.
524
- * Fuzzy matching helps match terms with minor typos or variations.
526
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/text/
525
527
"""
526
528
527
529
def __init__ (self , path , query , fuzzy = None , match_criteria = None , synonyms = None , score = None ):
@@ -574,11 +576,7 @@ class SearchWildcard(SearchExpression):
574
576
allow_analyzed_field: Whether to allow matching against analyzed fields (default is False).
575
577
score: Optional expression to modify the relevance score.
576
578
577
- Notes:
578
- * Wildcard patterns follow standard syntax, where `*` matches any sequence of characters
579
- and `?` matches a single character.
580
- * By default, the field should be keyword or unanalyzed
581
- unless `allow_analyzed_field=True`.
579
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/wildcard/
582
580
"""
583
581
584
582
def __init__ (self , path , query , allow_analyzed_field = None , score = None ):
@@ -625,9 +623,7 @@ class SearchGeoShape(SearchExpression):
625
623
geometry: The GeoJSON geometry to compare against.
626
624
score: Optional expression to modify the relevance score.
627
625
628
- Notes:
629
- * The field must be indexed as a geo shape type in Atlas Search.
630
- * Geometry must conform to GeoJSON specification.
626
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/geoShape/
631
627
"""
632
628
633
629
def __init__ (self , path , relation , geometry , score = None ):
@@ -674,9 +670,7 @@ class SearchGeoWithin(SearchExpression):
674
670
geo_object: The GeoJSON geometry defining the boundary.
675
671
score: Optional expression to adjust the relevance score.
676
672
677
- Notes:
678
- * The geo field must be indexed appropriately in the Atlas Search index.
679
- * The geometry must follow GeoJSON format.
673
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/
680
674
"""
681
675
682
676
def __init__ (self , path , kind , geo_object , score = None ):
@@ -719,9 +713,7 @@ class SearchMoreLikeThis(SearchExpression):
719
713
documents: A list of example documents or expressions to find similar documents.
720
714
score: Optional expression to modify the relevance scoring.
721
715
722
- Notes:
723
- * The documents should be representative examples to base similarity on.
724
- * Supports various field types depending on the Atlas Search configuration.
716
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/
725
717
"""
726
718
727
719
def __init__ (self , documents , score = None ):
@@ -774,9 +766,7 @@ class CompoundExpression(SearchExpression):
774
766
score: Optional expression to adjust scoring.
775
767
minimum_should_match: Minimum number of `should` clauses that must match.
776
768
777
- Notes:
778
- * This is the most flexible way to build complex Atlas Search queries.
779
- * Supports nesting of expressions to any depth.
769
+ Reference: https://www.mongodb.com/docs/atlas/atlas-search/compound/
780
770
"""
781
771
782
772
def __init__ (
@@ -859,10 +849,6 @@ class CombinedSearchExpression(SearchExpression):
859
849
lhs: The left-hand search expression.
860
850
operator: The boolean operator as a string (e.g., "and", "or", "not").
861
851
rhs: The right-hand search expression.
862
-
863
- Notes:
864
- * The operator must be supported by MongoDB Atlas Search boolean logic.
865
- * This class enables building complex nested search queries.
866
852
"""
867
853
868
854
def __init__ (self , lhs , operator , rhs ):
@@ -917,10 +903,7 @@ class SearchVector(SearchExpression):
917
903
exact: Optional flag to enforce exact matching.
918
904
filter: Optional filter expression to narrow candidate documents.
919
905
920
- Notes:
921
- * The vector field must be indexed as a vector type in Atlas Search.
922
- * Parameters like `num_candidates` and `exact` control search
923
- performance and accuracy trade-offs.
906
+ Reference: https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/
924
907
"""
925
908
926
909
def __init__ (
0 commit comments