@@ -47,13 +47,11 @@ matches on fields indexed in a MongoDB Atlas Search index.
47
47
>>> Article.objects.annotate(score=SearchEquals(path="headline", value="title"))
48
48
<QuerySet [<Article: headline: title>]>
49
49
50
- The ``path `` argument can be either the name of a field (as a string), or a
51
- :class: `~django.db.models.F ` instance.
50
+ **Arguments: **
52
51
53
- The ``value `` argument must be a string or a :class: `~django.db.models.Value `.
54
-
55
- The optional ``score `` argument is a :class: `SearchScoreOption ` that tunes the
56
- relevance score.
52
+ - ``path ``: The document path to the field.
53
+ - ``value ``: The value to match.
54
+ - ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
57
55
58
56
``SearchAutocomplete ``
59
57
----------------------
@@ -75,16 +73,11 @@ in a MongoDB Atlas Search index.
75
73
<Article: title: Harry Potter’s Cultural Impact on Literature>
76
74
]>
77
75
78
- The ``path `` argument specifies the field to search and can be a string or a
79
- :class: `~django.db.models.F `.
80
-
81
- The ``query `` is the user input string to autocomplete and can be passed as a
82
- string or a :class: `~django.db.models.Value `.
76
+ **Arguments: **
83
77
84
- Optional arguments:
85
-
86
- - ``fuzzy ``: A dictionary with fuzzy matching options such as
87
- ``{"maxEdits": 1} ``.
78
+ - ``path ``: The document path to the field.
79
+ - ``query ``: The value to match.
80
+ - ``fuzzy ``: Fuzzy matching options, e.g., ``{"maxEdits": 1} ``.
88
81
- ``token_order ``: Controls token sequence behavior. Accepts values like
89
82
``"sequential" `` or ``"any" ``.
90
83
- ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
@@ -109,11 +102,10 @@ documents that include (or exclude) optional fields.
109
102
<Article: title: Indexing Strategies with MongoDB (by Miguel)>
110
103
]>
111
104
112
- The ``path `` argument specifies the document path to check and can be provided
113
- as a string or a :class: `~django.db.models.F `.
105
+ **Arguments: **
114
106
115
- The optional `` score `` argument is a :class: ` SearchScoreOption ` that tunes the
116
- relevance score.
107
+ - `` path ``: The document path to the field.
108
+ - `` score ``: A :class: ` SearchScoreOption ` to tune the relevance score.
117
109
118
110
``SearchIn ``
119
111
------------
@@ -134,12 +126,11 @@ field contains a value from the provided array.
134
126
<Article: title: Boosting Relevance Scores (number=2)>
135
127
]>
136
128
137
- The ``path `` argument can be the name of a field (as a string) or a
138
- :class: `~django.db.models.F `. The ``value `` must be a list
139
- of values or a :class: `~django.db.models.Value `.
129
+ **Arguments: **
140
130
141
- The optional ``score `` argument is a :class: `SearchScoreOption ` that tunes the
142
- relevance score.
131
+ - ``path ``: The document path to the field.
132
+ - ``value ``: The value to match.
133
+ - ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
143
134
144
135
``SearchPhrase ``
145
136
----------------
@@ -163,12 +154,10 @@ synonym mappings defined in the Atlas Search index.
163
154
<Article: title: The Impact of Rapid Change in Climate Systems>
164
155
]>
165
156
166
- The ``path `` argument specifies the field to search and can be a string or a
167
- :class: `~django.db.models.F `. The ``query `` is the phrase to
168
- match, passed as a string or a list of strings (terms).
169
-
170
- Optional arguments:
157
+ **Arguments: **
171
158
159
+ - ``path ``: The document path to the field.
160
+ - ``query ``: The value to match.
172
161
- ``slop ``: The maximum number of terms allowed between phrase terms.
173
162
- ``synonyms ``: The name of a synonym mapping defined in your Atlas index.
174
163
- ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
@@ -195,12 +184,12 @@ supports features like boolean operators, wildcards, and field-specific terms.
195
184
<Article: title: Advanced Query Techniques in Django ORM>
196
185
]>
197
186
198
- The ``path `` argument can be a string or a
199
- :class: `~django.db.models.F ` representing the field to query.
200
- The ``query `` argument is a Lucene-style query string.
187
+ **Arguments: **
188
+
189
+ - ``path ``: The document path to the field.
190
+ - ``query ``: A Lucene-style query string.
191
+ - ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
201
192
202
- The optional ``score `` argument is a :class: `SearchScoreOption ` that tunes the
203
- relevance score.
204
193
205
194
``SearchRange ``
206
195
---------------
@@ -221,11 +210,9 @@ date, or other comparable fields based on upper and/or lower bounds.
221
210
<Article: title: Pre-2020 Web Framework Evolution (number=2015)>
222
211
]>
223
212
224
- The ``path `` argument specifies the field to filter and can be a string or a
225
- :class: `~django.db.models.F `.
226
-
227
- Optional arguments:
213
+ **Arguments: **
228
214
215
+ - ``path ``: The document path to the field.
229
216
- ``lt ``: Exclusive upper bound (``< ``)
230
217
- ``lte ``: Inclusive upper bound (``<= ``)
231
218
- ``gt ``: Exclusive lower bound (``> ``)
@@ -251,22 +238,22 @@ expression pattern to the contents of a specified field.
251
238
<Article: title: Breaking_Changes in Atlas Search API>
252
239
]>
253
240
254
- The ``path `` argument specifies the field to search and can be provided as a
255
- string or a :class: `~django.db.models.F `. The ``query `` is a
256
- regular expression string that will be applied to the field contents.
257
-
258
- Optional arguments:
241
+ **Arguments: **
259
242
243
+ - ``path ``: The document path to the field.
244
+ - ``query ``: Regular expression string that will be applied to the field
245
+ contents.
260
246
- ``allow_analyzed_field ``: Boolean indicating whether to allow matching
261
- against analyzed fields (defaults to `` False ``) .
247
+ against analyzed fields.
262
248
- ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
263
249
264
250
``SearchText ``
265
251
--------------
266
252
267
253
.. class :: SearchText(path, query, *, fuzzy=None, match_criteria=None, synonyms=None, score=None)
268
254
269
- Performs full-text search using the :doc: `text operator <atlas:atlas-search/text >`.
255
+ Performs full-text search using the :doc: `text operator
256
+ <atlas:atlas-search/text>`.
270
257
271
258
Matches terms in the specified field and supports fuzzy matching, match
272
259
criteria, and synonym mappings.
@@ -284,16 +271,12 @@ criteria, and synonym mappings.
284
271
<Article: title: Understanding MongoDB Query Optimization>
285
272
]>
286
273
287
- The ``path `` argument specifies the field to search and can be provided as a
288
- string or a :class: `~django.db.models.F `. The ``query `` argument
289
- is the search term or phrase.
290
-
291
- Optional arguments:
274
+ **Arguments: **
292
275
276
+ - ``path ``: The document path to the field.
277
+ - ``query ``: The argument is the search term or phrase.
293
278
- ``fuzzy ``: A dictionary of fuzzy matching options, such as
294
279
``{"maxEdits": 1} ``.
295
- - ``match_criteria ``: Whether to match ``"all" `` or ``"any" `` terms (defaults
296
- to Atlas Search behavior).
297
280
- ``synonyms ``: The name of a synonym mapping defined in your Atlas index.
298
281
- ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
299
282
@@ -305,8 +288,8 @@ Optional arguments:
305
288
Matches strings using wildcard patterns.
306
289
307
290
Uses the :doc: `wildcard operator <atlas:atlas-search/wildcard >` to search for
308
- terms matching a pattern with ``* `` (any sequence of characters) and ``? `` (any
309
- single character) wildcards.
291
+ terms matching a pattern with ``* `` (any sequence of characters) and ``? ``
292
+ (any single character) wildcards.
310
293
311
294
.. code-block :: pycon
312
295
@@ -319,14 +302,12 @@ single character) wildcards.
319
302
<Article: title: report_2022_final_review>
320
303
]>
321
304
322
- The ``path `` argument specifies the field to search and can be a string or a
323
- :class: `~django.db.models.F `. The ``query `` is a wildcard string
324
- that may include ``* `` and ``? ``.
325
-
326
- Optional arguments:
305
+ **Arguments: **
327
306
328
- - ``allow_analyzed_field ``: Boolean that allows matching against analyzed
329
- fields (defaults to ``False ``).
307
+ - ``path ``: The document path to the field.
308
+ - ``query ``: A wildcard string that may include ``* `` and ``? ``.
309
+ - ``allow_analyzed_field ``: Boolean indicating whether to allow matching
310
+ against analyzed fields.
330
311
- ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
331
312
332
313
``SearchGeoShape ``
@@ -337,8 +318,8 @@ Optional arguments:
337
318
Filters documents based on spatial relationships with a geometry.
338
319
339
320
Uses the :doc: `geoShape operator <atlas:atlas-search/geoShape >` to match
340
- documents where a geo field has a specified spatial relation to a given GeoJSON
341
- geometry.
321
+ documents where a geo field has a specified spatial relation to a given
322
+ GeoJSON geometry.
342
323
343
324
.. code-block :: pycon
344
325
@@ -352,17 +333,13 @@ geometry.
352
333
<Article: title: Urban Planning in District 5 (location: [1, 2])>
353
334
]>
354
335
355
- The ``path `` argument specifies the field to filter and can be a string or a
356
- :class: `~django.db.models.F `.
357
-
358
- Required arguments:
336
+ **Arguments: **
359
337
338
+ - ``path ``: The document path to the field.
360
339
- ``relation ``: The spatial relation to test. Valid values include
361
340
``"within" ``, ``"intersects" ``, and ``"disjoint" ``.
362
341
- ``geometry ``: A GeoJSON geometry object to compare against.
363
-
364
- The optional ``score `` argument is a :class: `SearchScoreOption ` that tunes the
365
- relevance score.
342
+ - ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
366
343
367
344
``SearchGeoWithin ``
368
345
-------------------
@@ -387,16 +364,12 @@ geometry.
387
364
<Article: title: Urban Planning in District 5 (location: [1, 2])>
388
365
]>
389
366
390
- The ``path `` argument specifies the geo field to filter and can be a string or
391
- a :class: `~django.db.models.F `.
392
-
393
- Required arguments:
367
+ **Arguments: **
394
368
369
+ - ``path ``: The document path to the field.
395
370
- ``kind ``: The GeoJSON geometry type ``circle ``, ``box ``, or ``geometry ``.
396
371
- ``geo_object ``: The GeoJSON geometry defining the spatial boundary.
397
-
398
- The optional ``score `` argument is a :class: `SearchScoreOption ` that tunes the
399
- relevance score.
372
+ - ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
400
373
401
374
``SearchMoreLikeThis ``
402
375
----------------------
@@ -422,11 +395,12 @@ retrieve documents that resemble one or more example documents.
422
395
<Article: title: Similar Approaches in Database Design>
423
396
]>
424
397
425
- The ``documents `` argument must be a list of example documents or expressions
426
- that serve as references for similarity.
398
+ **Arguments: **
399
+
400
+ - ``documents ``: List of example documents or expressions
401
+ that serve as references for similarity.
402
+ - ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
427
403
428
- The optional ``score `` argument is a :class: `SearchScoreOption ` that tunes the
429
- relevance score.
430
404
431
405
``CompoundExpression ``
432
406
======================
@@ -454,64 +428,21 @@ contribute to document matching and scoring.
454
428
... )
455
429
<QuerySet [<Article: title: MongoDB Atlas Database Performance Optimization>]>
456
430
457
- Arguments:
431
+ ** Arguments: **
458
432
459
433
- ``must ``: A list of expressions that **must ** match.
460
434
- ``must_not ``: A list of expressions that **must not ** match.
461
- - ``should ``: A list of optional expressions that **should ** match.
462
- These can improve scoring.
435
+ - ``should ``: A list of optional expressions that **should ** match. These can
436
+ improve scoring.
463
437
- ``filter ``: A list of expressions used for filtering without affecting
464
438
relevance scoring.
465
- - ``minimum_should_match ``: The minimum number of ``should `` clauses that
466
- must match.
439
+ - ``minimum_should_match ``: The minimum number of ``should `` clauses that must
440
+ match.
467
441
- ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
468
442
469
- ``CompoundExpression `` is useful for building advanced and flexible query
470
- logic in Atlas Search.
471
-
472
- ``CombinedSearchExpression ``
473
- ============================
474
-
475
- .. class :: CombinedSearchExpression(lhs, operator, rhs)
476
-
477
- Expression that combines two Atlas Search expressions using a boolean
478
- operator.
479
443
480
- This expression is used internally when combining search expressions with
481
- Python's bitwise operators (``& ``, ``| ``, ``~ ``), corresponding to the logical
482
- operators such as ``and ``, ``or ``, and ``not ``.
483
-
484
- .. admonition :: Typical usage
485
-
486
- This expression is typically created when using the combinable interface
487
- (e.g., ``expr1 & expr2 ``). It can also be constructed manually.
488
-
489
- .. code-block :: pycon
490
-
491
- >>> from django_mongodb_backend.expressions import CombinedSearchExpression
492
- >>> expr1 = SearchText("headline", "mongodb")
493
- >>> expr2 = SearchText("body", "atlas")
494
- >>> CombinedSearchExpression(expr1, "and", expr2)
495
- CombinedSearchExpression(
496
- lhs=SearchText(path='headline', query='mongodb'),
497
- operator='and',
498
- rhs=SearchText(path='body', query='atlas')
499
- )
500
-
501
- Args:
502
-
503
- - ``lhs ``: The left-hand side search expression.
504
- - ``operator ``: A string representing the logical operator (``"and" ``,
505
- ``"or" ``, or ``"not" ``).
506
- - ``rhs ``: The right-hand side search expression.
507
-
508
- This is the underlying expression used to support operator overloading in
509
- Atlas Search expressions.
510
-
511
- .. _search-operations-combinable :
512
-
513
- Combinable expressions
514
- ----------------------
444
+ ``Combinable expressions ``
445
+ --------------------------
515
446
516
447
All Atlas Search expressions subclassed from ``SearchExpression ``
517
448
can be combined using Python's bitwise operators:
@@ -531,10 +462,6 @@ This allows for more expressive and readable search logic:
531
462
<Article: title: Modern MongoDB Features>
532
463
]>
533
464
534
- Under the hood, these expressions are translated into
535
- :class: `CombinedSearchExpression ` instances, which can be reused and nested
536
- with other compound expressions.
537
-
538
465
``SearchVector ``
539
466
================
540
467
@@ -543,8 +470,8 @@ with other compound expressions.
543
470
Performs vector similarity search using the :doc: `$vectorSearch stage
544
471
<atlas:atlas-vector-search/vector-search-stage>`.
545
472
546
- Retrieves documents whose vector field is most similar to a given query vector,
547
- using either approximate or exact nearest-neighbor search.
473
+ Retrieves documents whose vector field is most similar to a given query
474
+ vector, using either approximate or exact nearest-neighbor search.
548
475
549
476
.. code-block :: pycon
550
477
@@ -560,18 +487,16 @@ using either approximate or exact nearest-neighbor search.
560
487
... )
561
488
<QuerySet [<Article: Article object (6882f074359a4b191381b2e4)>]>
562
489
563
- Arguments:
564
490
565
- - ``path ``: The document path to the vector field (string or
566
- :class: `~django.db.models.F `).
491
+ **Arguments: **
492
+
493
+ - ``path ``: The document path to the field.
567
494
- ``query_vector ``: The input vector used for similarity comparison.
568
495
- ``limit ``: The maximum number of matching documents to return.
569
- - ``num_candidates ``: (Optional) The number of candidate documents considered
570
- during search.
571
- - ``exact ``: (Optional) Whether to enforce exact search instead of approximate
572
- (defaults to ``False ``).
573
- - ``filter ``: (Optional) A filter expression to restrict the candidate
574
- documents.
496
+ - ``num_candidates ``: The number of candidate documents considered during
497
+ search.
498
+ - ``exact ``: A boolean whether to enforce exact search instead of approximate.
499
+ - ``filter ``: A MQL filter expression to restrict the candidate documents.
575
500
576
501
.. warning ::
577
502
0 commit comments