From d83672aef509a04ff782f1063bce9a2cf32d310d Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 5 May 2025 17:02:02 -0400 Subject: [PATCH 1/5] DOCSP-49758: Atlas search indexes --- source/includes/model-data/indexes.py | 10 +++++++++ source/model-data/indexes.txt | 32 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/source/includes/model-data/indexes.py b/source/includes/model-data/indexes.py index 70194b2..37741d6 100644 --- a/source/includes/model-data/indexes.py +++ b/source/includes/model-data/indexes.py @@ -3,6 +3,7 @@ from django.db.models import Q, F from django_mongodb_backend.models import EmbeddedModel from django_mongodb_backend.fields import EmbeddedModelField, ArrayField +from django_mongodb_backend.indexes import SearchIndex class Nutrition(EmbeddedModel): calories = models.IntegerField(default=0) @@ -60,6 +61,15 @@ class Meta: ] # end-embedded +# start-atlas-search +class Meta: + db_table = "recipes" + indexes = [ + SearchIndex(fields=["title"], + name="title_search_idx"), + ] +# end-atlas-search + # start-partial class Meta: db_table = "recipes" diff --git a/source/model-data/indexes.txt b/source/model-data/indexes.txt index d092f22..85494ae 100644 --- a/source/model-data/indexes.txt +++ b/source/model-data/indexes.txt @@ -202,9 +202,41 @@ Advanced Index Configuration This section shows how to create the following advanced index types: +- :ref:`django-indexes-atlas-search` - :ref:`django-indexes-partial` - :ref:`django-indexes-unique` +.. _django-indexes-atlas-search: + +Atlas Search Indexes +~~~~~~~~~~~~~~~~~~~~ + +Atlas Search indexes specify the behavior of an Atlas Search, or a full-text +search on collections hosted on MongoDB Atlas. + +To create an Atlas Search index, assign the ``indexes`` option in your model's +``Meta`` class to a ``SearchIndex`` object. Pass the following arguments to the +``SearchIndex()`` constructor: + +- ``fields``: The fields you want to index. +- ``name``: *(Optional)* The name of your Atlas Search index. If you do not + specify this argument, {+django-odm+} automatically generates an index name. + +The following example updates the ``Recipe`` model's ``Meta`` class to create +an Atlas Search index named ``"title_search_idx"`` on the ``title`` field: + +.. literalinclude:: /includes/model-data/indexes.py + :start-after: start-atlas-search + :end-before: end-atlas-search + :language: python + :copyable: + :emphasize-lines: 3-6 + +.. tip:: + + To learn more about Atlas Search queries and indexes, see :atlas:`Atlas Search ` + in the Atlas documentation. + .. _django-indexes-partial: Partial Indexes From ecf23fea89b01263a8c74b55529bd7bfa5761c25 Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 8 May 2025 16:39:24 -0400 Subject: [PATCH 2/5] edits --- source/includes/model-data/indexes.py | 6 ++++-- source/model-data/indexes.txt | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/source/includes/model-data/indexes.py b/source/includes/model-data/indexes.py index 37741d6..33649ad 100644 --- a/source/includes/model-data/indexes.py +++ b/source/includes/model-data/indexes.py @@ -65,8 +65,10 @@ class Meta: class Meta: db_table = "recipes" indexes = [ - SearchIndex(fields=["title"], - name="title_search_idx"), + SearchIndex( + fields=["title"], + name="title_search_idx", + ) ] # end-atlas-search diff --git a/source/model-data/indexes.txt b/source/model-data/indexes.txt index 85494ae..fcd9139 100644 --- a/source/model-data/indexes.txt +++ b/source/model-data/indexes.txt @@ -211,8 +211,8 @@ index types: Atlas Search Indexes ~~~~~~~~~~~~~~~~~~~~ -Atlas Search indexes specify the behavior of an Atlas Search, or a full-text -search on collections hosted on MongoDB Atlas. +Atlas Search indexes specify the behavior of an Atlas Search, which is a +full-text search on collections hosted on MongoDB Atlas. To create an Atlas Search index, assign the ``indexes`` option in your model's ``Meta`` class to a ``SearchIndex`` object. Pass the following arguments to the @@ -220,7 +220,7 @@ To create an Atlas Search index, assign the ``indexes`` option in your model's - ``fields``: The fields you want to index. - ``name``: *(Optional)* The name of your Atlas Search index. If you do not - specify this argument, {+django-odm+} automatically generates an index name. + specify this argument, {+framework+} automatically generates an index name. The following example updates the ``Recipe`` model's ``Meta`` class to create an Atlas Search index named ``"title_search_idx"`` on the ``title`` field: @@ -234,8 +234,11 @@ an Atlas Search index named ``"title_search_idx"`` on the ``title`` field: .. tip:: - To learn more about Atlas Search queries and indexes, see :atlas:`Atlas Search ` - in the Atlas documentation. + To learn more about Atlas Search queries and indexes, see the following resources: + + - :atlas:`Atlas Search ` in the Atlas documentation. + - `SearchIndex <{+api+}ref/models/indexes/#searchindex>`__ class in the + {+django-odm+} API documentation. .. _django-indexes-partial: From 1e3aa92558d72458deeb7d7df8d76189c2899024 Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 9 May 2025 11:06:30 -0400 Subject: [PATCH 3/5] code highlight --- source/model-data/indexes.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/model-data/indexes.txt b/source/model-data/indexes.txt index fcd9139..84120e5 100644 --- a/source/model-data/indexes.txt +++ b/source/model-data/indexes.txt @@ -230,7 +230,7 @@ an Atlas Search index named ``"title_search_idx"`` on the ``title`` field: :end-before: end-atlas-search :language: python :copyable: - :emphasize-lines: 3-6 + :emphasize-lines: 3-8 .. tip:: From ffae44b7b92648e190fa6b459938ea6e3a346df9 Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 9 May 2025 11:10:02 -0400 Subject: [PATCH 4/5] edit --- source/limitations-upcoming.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/limitations-upcoming.txt b/source/limitations-upcoming.txt index 1707f70..0b3392a 100644 --- a/source/limitations-upcoming.txt +++ b/source/limitations-upcoming.txt @@ -64,8 +64,6 @@ Indexes {+django-odm+} does not support the following index functionalities: -- Creating ``$vectorSearch`` and ``$search`` indexes through the Django - Indexes API - Creating geospatial indexes through the Django Indexes API - Updating indexes in ``EmbeddedModelFields`` after model creation From cdd9c1ef178068a82a27ca2a0fb046ac300f74f6 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 21 May 2025 10:38:25 -0400 Subject: [PATCH 5/5] feature support page --- source/limitations-upcoming.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/limitations-upcoming.txt b/source/limitations-upcoming.txt index 953edf9..34b2a4c 100644 --- a/source/limitations-upcoming.txt +++ b/source/limitations-upcoming.txt @@ -54,9 +54,7 @@ Index Support - Planned GA Support * - Atlas Search and Atlas Vector Search indexes - - *Unsupported*. You cannot use the Django - Indexes API to create these indexes, but you can use - the PyMongo Driver by :ref:`exposing your MongoClient `. + - ✓ - ✓ * - Compound indexes