1
- ================
1
+ ============
2
2
Atlas search
3
- ================
3
+ ============
4
4
5
- The database functions in the ``django_mongodb_backend.expressions.search ``
6
- module ease the use of MongoDB Atlas search's `full text and vector search
7
- engine <https://www.mongodb.com/docs/atlas/atlas-search/> `_.
5
+ .. currentmodule :: django_mongodb_backend.expressions
8
6
9
- For the examples in this document, we'll use the following models:
7
+ .. versionadded :: 5.2.0b2
10
8
11
- .. code-block :: pycon
9
+ The database functions in the ``django_mongodb_backend.expressions.search ``
10
+ module ease the use of MongoDB Atlas search's :doc: `full text and vector search
11
+ engine <atlas:atlas-search>`.
12
+
13
+ For the examples in this document, we'll use the following models::
12
14
13
15
from django.db import models
14
16
from django_mongodb_backend.models import EmbeddedModel
15
17
from django_mongodb_backend.fields import ArrayField, EmbeddedModelField
16
18
19
+
17
20
class Writer(EmbeddedModel):
18
21
name = models.CharField(max_length=10)
19
22
@@ -26,17 +29,15 @@ For the examples in this document, we'll use the following models:
26
29
plot_embedding = ArrayField(models.FloatField(), size=3, null=True)
27
30
writer = EmbeddedModelField(Writer, null=True)
28
31
29
-
30
32
``SearchEquals ``
31
33
================
32
- Atlas Search expression that matches documents where a field is equal to a
33
- given value.
34
34
35
- This expression uses the ``equals `` operator to perform exact matches
36
- on fields indexed in a MongoDB Atlas Search index.
35
+ .. class :: SearchEquals(path, value, score=None)
37
36
38
- ` SearchEquals docs < https://www.mongodb.com/docs/atlas/atlas-search/equals/ >`_
37
+ Atlas Search expression that matches documents where a field is equal to a given value.
39
38
39
+ This expression uses the :doc: `equals operator <atlas:atlas-search/equals >` to perform
40
+ exact matches on fields indexed in a MongoDB Atlas Search index.
40
41
41
42
.. code-block :: pycon
42
43
@@ -48,11 +49,9 @@ The ``path`` argument can be either the name of a field (as a string), or a
48
49
:class: `~django.db.models.expressions.Col ` instance. The ``value `` argument
49
50
must be a string or a :class: `~django.db.models.expressions.Value `.
50
51
51
- ``SearchEquals `` objects can be reused and combined with other search
52
- expressions.
53
-
54
- See :ref: `search-operations-combinable `
52
+ ``SearchEquals `` objects can be reused and combined with other search expressions.
55
53
54
+ See :ref: `search-operations-combinable `.
56
55
57
56
``SearchAutocomplete ``
58
57
======================
@@ -90,8 +89,7 @@ Optional arguments:
90
89
``SearchAutocomplete `` expressions can be reused and composed with other
91
90
search expressions.
92
91
93
- See also: :ref: `search-operations-combinable `
94
-
92
+ See also: :ref: `search-operations-combinable `.
95
93
96
94
``SearchExists ``
97
95
================
@@ -122,8 +120,7 @@ result.
122
120
``SearchExists `` expressions can be reused and combined with other search
123
121
expressions.
124
122
125
- See also: :ref: `search-operations-combinable `
126
-
123
+ See also: :ref: `search-operations-combinable `.
127
124
128
125
``SearchIn ``
129
126
============
@@ -154,8 +151,7 @@ An optional ``score`` argument can be used to customize relevance scoring.
154
151
``SearchIn `` expressions can be reused and combined with other search
155
152
expressions.
156
153
157
- See also: :ref: `search-operations-combinable `
158
-
154
+ See also: :ref: `search-operations-combinable `.
159
155
160
156
``SearchPhrase ``
161
157
================
@@ -192,8 +188,7 @@ Optional arguments:
192
188
``SearchPhrase `` expressions can be reused and combined with other search
193
189
expressions.
194
190
195
- See also: :ref: `search-operations-combinable `
196
-
191
+ See also: :ref: `search-operations-combinable `.
197
192
198
193
``SearchQueryString ``
199
194
=====================
@@ -226,8 +221,7 @@ An optional ``score`` argument may be used to adjust relevance scoring.
226
221
``SearchQueryString `` expressions can be reused and combined with other search
227
222
expressions.
228
223
229
- See also: :ref: `search-operations-combinable `
230
-
224
+ See also: :ref: `search-operations-combinable `.
231
225
232
226
``SearchRange ``
233
227
===============
@@ -263,8 +257,7 @@ Optional arguments:
263
257
``SearchRange `` expressions can be reused and combined with other search
264
258
expressions.
265
259
266
- See also: :ref: `search-operations-combinable `
267
-
260
+ See also: :ref: `search-operations-combinable `.
268
261
269
262
``SearchRegex ``
270
263
===============
@@ -298,8 +291,7 @@ Optional arguments:
298
291
``SearchRegex `` expressions can be reused and combined with other search
299
292
expressions.
300
293
301
- See also: :ref: `search-operations-combinable `
302
-
294
+ See also: :ref: `search-operations-combinable `.
303
295
304
296
``SearchText ``
305
297
==============
@@ -343,7 +335,6 @@ Optional arguments:
343
335
344
336
See also: :ref: `search-operations-combinable `
345
337
346
-
347
338
``SearchWildcard ``
348
339
==================
349
340
@@ -353,7 +344,7 @@ This expression uses the ``wildcard`` operator to search for terms matching
353
344
a pattern with ``* `` (any sequence of characters) and ``? `` (any single
354
345
character) wildcards.
355
346
356
- `SearchWildcard docs <https://www.mongodb.com/docs/atlas/atlas-search/wildcard/ >`_
347
+ `SearchWildcard docs <https://www.mongodb.com/docs/atlas/atlas-search/wildcard/ >`_.
357
348
358
349
.. code-block :: pycon
359
350
@@ -379,19 +370,18 @@ Optional arguments:
379
370
``SearchWildcard `` expressions can be reused and combined with other search
380
371
expressions.
381
372
382
- See also: :ref: `search-operations-combinable `
383
-
373
+ See also: :ref: `search-operations-combinable `.
384
374
385
375
``SearchGeoShape ``
386
376
==================
387
377
388
378
Atlas Search expression that filters documents based on spatial relationships
389
379
with a geometry.
390
380
391
- This expression uses the `` geoShape `` operator to match documents where a geo
381
+ This expression uses the :doc: geoShape operator <atlas:atlas-search/geoShape>` to match documents where a geo
392
382
field has a specified spatial relation to a given GeoJSON geometry.
393
383
394
- `SearchGeoShape docs <https://www.mongodb.com/docs/atlas/atlas-search/geoShape/ >`_
384
+ `SearchGeoShape docs <https://www.mongodb.com/docs/atlas/atlas-search/geoShape/ >`_.
395
385
396
386
.. code-block :: pycon
397
387
@@ -421,8 +411,7 @@ Optional:
421
411
``SearchGeoShape `` expressions can be reused and combined with other search
422
412
expressions.
423
413
424
- See also: :ref: `search-operations-combinable `
425
-
414
+ See also: :ref: `search-operations-combinable `.
426
415
427
416
``SearchGeoWithin ``
428
417
===================
@@ -462,8 +451,7 @@ Optional:
462
451
``SearchGeoWithin `` expressions can be reused and combined with other search
463
452
expressions.
464
453
465
- See also: :ref: `search-operations-combinable `
466
-
454
+ See also: :ref: `search-operations-combinable `.
467
455
468
456
``SearchMoreLikeThis ``
469
457
======================
@@ -500,8 +488,7 @@ Optional:
500
488
``SearchMoreLikeThis `` expressions can be reused and combined with other search
501
489
expressions.
502
490
503
- See also: :ref: `search-operations-combinable `
504
-
491
+ See also: :ref: `search-operations-combinable `.
505
492
506
493
``CompoundExpression ``
507
494
======================
@@ -544,8 +531,7 @@ Arguments:
544
531
``CompoundExpression `` is useful for building advanced and flexible query
545
532
logic in Atlas Search.
546
533
547
- See also: :ref: `search-operations-combinable `
548
-
534
+ See also: :ref: `search-operations-combinable `.
549
535
550
536
``CombinedSearchExpression ``
551
537
============================
@@ -598,8 +584,8 @@ Atlas Search expressions.
598
584
599
585
.. _search-operations-combinable :
600
586
601
- ** Combinable expressions **
602
- --------------------------
587
+ Combinable expressions
588
+ ----------------------
603
589
604
590
All Atlas Search expressions subclassed from ``SearchExpression ``
605
591
can be combined using Python's bitwise operators:
@@ -672,7 +658,6 @@ Arguments:
672
658
``SearchVector `` is typically used on its own in the ``score `` annotation and
673
659
cannot be nested or composed.
674
660
675
-
676
661
``SearchScoreOption ``
677
662
=====================
678
663
@@ -706,7 +691,6 @@ subdocument and can be reused across multiple search expressions.
706
691
It is typically passed as the ``score `` parameter to any search expression that
707
692
supports it.
708
693
709
-
710
694
The ``search `` lookup
711
695
======================
712
696
@@ -735,7 +719,7 @@ Under the hood:
735
719
736
720
- The left-hand side of the lookup is wrapped into a ``SearchText `` expression.
737
721
- The lookup compiles to a MongoDB query that filters documents with a score
738
- greater or equal to zero.
722
+ greater or equal to zero.
739
723
740
724
This allows for concise and idiomatic integration of Atlas Search within Django
741
725
filters.
0 commit comments