Skip to content

Commit 8388e41

Browse files
committed
WIP
1 parent ab3a2fe commit 8388e41

File tree

4 files changed

+74
-34
lines changed

4 files changed

+74
-34
lines changed

source/aggregation.txt

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,37 @@ To ``$explain`` an aggregation pipeline, call the
127127

128128
.. _java-rs-atlas-search-stage:
129129

130-
Pipeline Stages for Atlas Search
131-
--------------------------------
130+
Atlas Search
131+
------------
132132

133-
:atlas:`Atlas Search </atlas-search>` queries take the form of an aggregation pipeline stage. Atlas
134-
Search provides ``$search`` and ``$searchMeta`` stages, both of which must be the first
135-
stage in any query pipeline. For more information about Atlas pipeline stages,
136-
see the :atlas:`Choose the Aggregation Pipeline Stage
137-
</atlas-search/query-syntax/>` page in the Atlas
138-
manual.
133+
You can perform an :atlas:`Atlas Search </atlas-search>` query by creating and running
134+
an aggregation pipeline that contains one of the following pipeline stages:
135+
136+
- ``$search``
137+
- ``$searchMeta``
138+
139+
The {+driver-short+} provides the `Aggregates.search()
140+
<{+core-api+}/client/model/Aggregates.html#search(com.mongodb.client.model.search.SearchOperator)>`__
141+
and `Aggregates.searchMeta()
142+
<{+core-api+}/client/model/Aggregates.html#searchMeta(com.mongodb.client.model.search.SearchOperator)>`__
143+
methods to perform Atlas Search queries.
144+
145+
To learn more about Atlas Search pipeline stages, see :atlas:`Choose the
146+
Aggregation Pipeline Stage </atlas-search/query-syntax/>` in the Atlas
147+
documentation.
148+
149+
Create Pipeline Search Stages
150+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151+
152+
You can create the search criteria in your Atlas Search pipeline stage
153+
by using Search operators.
139154

140155
.. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst
141156

157+
.. replacement:: as-idx-link
158+
159+
the :ref:`java-rs-atlas-search-idx-mgmt` section of the Indexes guide
160+
142161
.. replacement:: atlas-query-operators-example
143162

144163
.. io-code-block::
@@ -153,9 +172,33 @@ manual.
153172
:language: console
154173
:visible: false
155174

156-
{"_id": {"$oid": "573a1397f29313caabce86db"}, "genres": ["Drama", "Sport"], "cast": ["Sylvester Stallone", "Talia Shire", "Burt Young", "Carl Weathers"], "title": "Rocky III", "year": 1982}
157-
{"_id": {"$oid": "573a1398f29313caabce9af0"}, "genres": ["Drama", "Sport"], "cast": ["Sylvester Stallone", "Talia Shire", "Burt Young", "Carl Weathers"], "title": "Rocky IV", "year": 1985}
175+
{"_id": ..., "genres": ["Comedy", "Romance"], "title": "Love at First Bite", "year": 1979}
176+
{"_id": ..., "genres": ["Comedy", "Drama"], "title": "Love Affair", "year": 1994}
177+
178+
Additional Information
179+
----------------------
180+
181+
To view a full list of expression operators, see :manual:`Aggregation
182+
Operators </reference/operator/aggregation/>` in the {+mdb-server+} manual.
183+
184+
To learn about assembling an aggregation pipeline and view examples, see
185+
:manual:`Aggregation Pipeline </core/aggregation-pipeline/>` in the {+mdb-server+} manual.
186+
187+
To learn more about creating pipeline stages, see :manual:`Aggregation
188+
Stages </reference/operator/aggregation-pipeline/>` in the {+mdb-server+} manual.
189+
190+
To learn more about explaining MongoDB operations, see
191+
:manual:`Explain Output </reference/explain-results/>` and
192+
:manual:`Query Plans </core/query-plans/>` in the {+mdb-server+} manual.
193+
194+
API Documentation
195+
~~~~~~~~~~~~~~~~~
158196

159-
.. replacement:: searchoperator-interface-api-docs
197+
To learn more about the classes and methods mentioned in this guide, see
198+
the following API documentation:
160199

161-
the `SearchOperator Interface API documentation <{+core-api+}/client/model/search/SearchOperator.html>`__
200+
- `aggregate() <{+driver-api+}/MongoCollection.html#aggregate(java.util.List)>`__
201+
- `Aggregates <{+core-api+}/client/model/Aggregates.html>`__
202+
- `AggregatePublisher <{+driver-api+}/AggregatePublisher.html>`__
203+
- `search() <{+core-api+}/client/model/Aggregates#search(com.mongodb.client.model.search.SearchOperator)>`__
204+
- `project() <{+core-api+}/client/model/Aggregates#project(org.bson.conversions.Bson)>`__

source/includes/aggregation/atlas-search-examples.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
11
package org.example;
2+
23
import com.mongodb.*;
34
import com.mongodb.client.model.Projections;
45
import com.mongodb.reactivestreams.client.*;
56
import org.bson.Document;
67

78
import reactor.core.publisher.Mono;
9+
810
import java.util.List;
11+
912
import org.bson.conversions.Bson;
1013

1114
import com.mongodb.client.model.Aggregates;
1215
import com.mongodb.client.model.search.SearchOperator;
16+
1317
import static com.mongodb.client.model.search.SearchPath.fieldPath;
18+
1419
import org.reactivestreams.Publisher;
1520

16-
public class Main {
21+
public class SearchHelpers {
1722
public static void main(String[] args) {
1823
// Replace the placeholder with your Atlas connection string
19-
String uri = "mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority&appName=Cluster0";
20-
21-
// Construct a ServerApi instance using the ServerApi.builder() method
22-
ServerApi serverApi = ServerApi.builder()
23-
.version(ServerApiVersion.V1)
24-
.build();
25-
26-
MongoClientSettings settings = MongoClientSettings.builder()
27-
.applyConnectionString(new ConnectionString(uri))
28-
.serverApi(serverApi)
29-
.build();
24+
String uri = "<connection string>";
3025

3126
// Create a new client and connect to the server
32-
try (MongoClient mongoClient = MongoClients.create(settings)) {
27+
try (MongoClient mongoClient = MongoClients.create(uri)) {
3328
MongoDatabase database = mongoClient.getDatabase("sample_mflix");
3429
MongoCollection<Document> movies = database.getCollection("movies");
3530

@@ -38,17 +33,17 @@ public static void main(String[] args) {
3833
SearchOperator.compound()
3934
.filter(
4035
List.of(
41-
SearchOperator.text(fieldPath("genres"), "Drama"),
42-
SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"),
43-
SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989),
44-
SearchOperator.wildcard(fieldPath("title"),"Rocky *")
36+
SearchOperator.in(fieldPath("genres"), List.of("Comedy")),
37+
SearchOperator.phrase(fieldPath("fullplot"), "new york"),
38+
SearchOperator.numberRange(fieldPath("year")).gtLt(1950, 2000),
39+
SearchOperator.wildcard(fieldPath("title"), "Love *")
4540
)));
4641

4742
Bson projection = Aggregates.project(Projections.fields(
48-
Projections.include("title", "year", "genres", "cast")
43+
Projections.include("title", "year", "genres")
4944
));
5045

51-
List<Bson> aggregateStages = List.of(searchStageFilters,projection);
46+
List<Bson> aggregateStages = List.of(searchStageFilters, projection);
5247

5348
Publisher<Document> publisher = movies.aggregate(aggregateStages);
5449
publisher.subscribe(new SubscriberHelpers.PrintDocumentSubscriber());

source/indexes.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ field:
177177
.. TODO: To learn more about wildcard indexes, see the :ref:`java-rs-clustered-index`
178178
.. guide.
179179

180+
.. _java-rs-atlas-search-idx-mgmt:
181+
180182
Atlas Search Index Management
181183
-----------------------------
182184

@@ -275,4 +277,4 @@ The following example deletes an index with the specified name:
275277
:dedent:
276278

277279
.. TODO: To learn more about removing indexes, see :ref:`java-rs-indexes-remove`
278-
.. in the Work with Indexes guide.
280+
.. in the Work with Indexes guide.

source/whats-new.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ and features:
5757

5858
.. replacement:: atlas-query-operators
5959

60-
the :ref:`Pipelines Stages for Atlas Search <java-rs-atlas-search-stage>`
61-
section of the Aggregation page
60+
the :ref:`java-rs-atlas-search-stage` section of the Aggregation
61+
guide
6262

6363
.. _javars-version-5.3:
6464

0 commit comments

Comments
 (0)