Skip to content

Commit 1bc3617

Browse files
committed
eg updates
1 parent c27bb18 commit 1bc3617

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

source/atlas-search.txt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,21 @@ SearchOperator Helper Methods
130130

131131
.. replacement:: atlas-query-operators-example
132132

133-
.. code-block:: java
134-
135-
Bson searchStageFilters = Aggregates.search(
136-
SearchOperator.compound()
137-
.filter(
138-
List.of(
139-
SearchOperator.text(fieldPath("genres"), "Drama"),
140-
SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"),
141-
SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989),
142-
SearchOperator.wildcard(fieldPath("title"),"Rocky *")
143-
)));
133+
.. io-code-block::
134+
135+
.. input:: /includes/fundamentals/code-snippets/builders/AggregateSearchBuilderExample.java
136+
:language: java
137+
:start-after: // begin atlasHelperMethods
138+
:end-before: // end atlasHelperMethods
139+
:language: java
140+
:dedent:
141+
142+
.. output::
143+
:language: console
144+
:visible: false
145+
146+
Document{{_id=573a1397f29313caabce86db, genres=[Drama, Sport], cast=[Sylvester Stallone, Talia Shire, Burt Young, Carl Weathers], title=Rocky III, year=1982}}
147+
Document{{_id=573a1398f29313caabce9af0, genres=[Drama, Sport], cast=[Sylvester Stallone, Talia Shire, Burt Young, Carl Weathers], title=Rocky IV, year=1985}}
144148

145149
.. replacement:: searchoperator-interface-api-docs
146150

source/includes/fundamentals/code-snippets/builders/AggregateSearchBuilderExample.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,23 @@ private static void runAtlasTextSearch(MongoCollection<Document> collection) {
6060
*/
6161
private static void runAtlasSearchWithSearchHelperMethods(MongoCollection<Document> collection) {
6262
// begin atlasHelperMethods
63-
Bson search_stage = Aggregates.search(
63+
Bson searchStageFilters = Aggregates.search(
6464
SearchOperator.compound()
65-
.filter(
66-
List.of(
67-
SearchOperator.text(fieldPath("genres"), "Drama"),
68-
SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"),
69-
SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989),
70-
SearchOperator.wildcard(fieldPath("title"),"Rocky *")
71-
)));
65+
.filter(
66+
List.of(
67+
SearchOperator.text(fieldPath("genres"), "Drama"),
68+
SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"),
69+
SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989),
70+
SearchOperator.wildcard(fieldPath("title"),"Rocky *")
71+
)));
72+
73+
Bson projection = Aggregates.project(Projections.fields(
74+
Projections.include("title", "year", "genres", "cast")
75+
));
76+
77+
List<Bson> aggregateStages = List.of(searchStageFilters, projection);
78+
collection.aggregate(aggregateStages).forEach(System.out::println);
79+
7280
// end atlasHelperMethods
7381

7482
// To condense result data, add this projection into the pipeline

0 commit comments

Comments
 (0)