@@ -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,12 +271,10 @@ 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
280
- ``match_criteria ``: Whether to match ``"all" `` or ``"any" `` terms (defaults
@@ -319,14 +304,12 @@ single character) wildcards.
319
304
<Article: title: report_2022_final_review>
320
305
]>
321
306
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:
307
+ **Arguments: **
327
308
328
- - ``allow_analyzed_field ``: Boolean that allows matching against analyzed
329
- fields (defaults to ``False ``).
309
+ - ``path ``: The document path to the field.
310
+ - ``query ``: A wildcard string that may include ``* `` and ``? ``.
311
+ - ``allow_analyzed_field ``: Boolean indicating whether to allow matching
312
+ against analyzed fields.
330
313
- ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
331
314
332
315
``SearchGeoShape ``
@@ -337,8 +320,8 @@ Optional arguments:
337
320
Filters documents based on spatial relationships with a geometry.
338
321
339
322
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.
323
+ documents where a geo field has a specified spatial relation to a given
324
+ GeoJSON geometry.
342
325
343
326
.. code-block :: pycon
344
327
@@ -352,17 +335,13 @@ geometry.
352
335
<Article: title: Urban Planning in District 5 (location: [1, 2])>
353
336
]>
354
337
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:
338
+ **Arguments: **
359
339
340
+ - ``path ``: The document path to the field.
360
341
- ``relation ``: The spatial relation to test. Valid values include
361
342
``"within" ``, ``"intersects" ``, and ``"disjoint" ``.
362
343
- ``geometry ``: A GeoJSON geometry object to compare against.
363
-
364
- The optional ``score `` argument is a :class: `SearchScoreOption ` that tunes the
365
- relevance score.
344
+ - ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
366
345
367
346
``SearchGeoWithin ``
368
347
-------------------
@@ -387,16 +366,12 @@ geometry.
387
366
<Article: title: Urban Planning in District 5 (location: [1, 2])>
388
367
]>
389
368
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:
369
+ **Arguments: **
394
370
371
+ - ``path ``: The document path to the field.
395
372
- ``kind ``: The GeoJSON geometry type ``circle ``, ``box ``, or ``geometry ``.
396
373
- ``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.
374
+ - ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
400
375
401
376
``SearchMoreLikeThis ``
402
377
----------------------
@@ -422,11 +397,12 @@ retrieve documents that resemble one or more example documents.
422
397
<Article: title: Similar Approaches in Database Design>
423
398
]>
424
399
425
- The ``documents `` argument must be a list of example documents or expressions
426
- that serve as references for similarity.
400
+ **Arguments: **
401
+
402
+ - ``documents ``: List of example documents or expressions
403
+ that serve as references for similarity.
404
+ - ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
427
405
428
- The optional ``score `` argument is a :class: `SearchScoreOption ` that tunes the
429
- relevance score.
430
406
431
407
``CompoundExpression ``
432
408
======================
@@ -454,64 +430,21 @@ contribute to document matching and scoring.
454
430
... )
455
431
<QuerySet [<Article: title: MongoDB Atlas Database Performance Optimization>]>
456
432
457
- Arguments:
433
+ ** Arguments: **
458
434
459
435
- ``must ``: A list of expressions that **must ** match.
460
436
- ``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.
437
+ - ``should ``: A list of optional expressions that **should ** match. These can
438
+ improve scoring.
463
439
- ``filter ``: A list of expressions used for filtering without affecting
464
440
relevance scoring.
465
- - ``minimum_should_match ``: The minimum number of ``should `` clauses that
466
- must match.
441
+ - ``minimum_should_match ``: The minimum number of ``should `` clauses that must
442
+ match.
467
443
- ``score ``: A :class: `SearchScoreOption ` to tune the relevance score.
468
444
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
445
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
- ----------------------
446
+ ``Combinable expressions ``
447
+ --------------------------
515
448
516
449
All Atlas Search expressions subclassed from ``SearchExpression ``
517
450
can be combined using Python's bitwise operators:
@@ -531,10 +464,6 @@ This allows for more expressive and readable search logic:
531
464
<Article: title: Modern MongoDB Features>
532
465
]>
533
466
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
467
``SearchVector ``
539
468
================
540
469
@@ -543,8 +472,8 @@ with other compound expressions.
543
472
Performs vector similarity search using the :doc: `$vectorSearch stage
544
473
<atlas:atlas-vector-search/vector-search-stage>`.
545
474
546
- Retrieves documents whose vector field is most similar to a given query vector,
547
- using either approximate or exact nearest-neighbor search.
475
+ Retrieves documents whose vector field is most similar to a given query
476
+ vector, using either approximate or exact nearest-neighbor search.
548
477
549
478
.. code-block :: pycon
550
479
@@ -560,18 +489,16 @@ using either approximate or exact nearest-neighbor search.
560
489
... )
561
490
<QuerySet [<Article: Article object (6882f074359a4b191381b2e4)>]>
562
491
563
- Arguments:
564
492
565
- - ``path ``: The document path to the vector field (string or
566
- :class: `~django.db.models.F `).
493
+ **Arguments: **
494
+
495
+ - ``path ``: The document path to the field.
567
496
- ``query_vector ``: The input vector used for similarity comparison.
568
497
- ``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.
498
+ - ``num_candidates ``: The number of candidate documents considered during
499
+ search.
500
+ - ``exact ``: A boolean whether to enforce exact search instead of approximate.
501
+ - ``filter ``: A MQL filter expression to restrict the candidate documents.
575
502
576
503
.. warning ::
577
504
0 commit comments