File tree Expand file tree Collapse file tree 2 files changed +27
-22
lines changed Expand file tree Collapse file tree 2 files changed +27
-22
lines changed Original file line number Diff line number Diff line change @@ -215,29 +215,11 @@ You can build a Atlas Search pipeline stage using search operators.
215
215
216
216
.. io-code-block::
217
217
218
- .. input::
218
+ .. input:: /includes/aggregation/aggregation.kt
219
219
:language: kotlin
220
-
221
- val searchStage: Bson = Aggregates.search(
222
- SearchOperator.compound()
223
- .filter(
224
- listOf(
225
- SearchOperator.text(fieldPath("genres"), "Drama"),
226
- SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"),
227
- SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989),
228
- SearchOperator.wildcard(fieldPath("title"), "Rocky *")
229
- )
230
- )
231
- )
232
-
233
- val projection = Projections.fields(
234
- Projections.include("title", "year", "genres", "cast")
235
- )
236
-
237
- val aggregatePipelineStages: List<Bson> = listOf(searchStage, Aggregates.project(projection))
238
- val results = collection.aggregate<Document>(aggregatePipelineStages)
239
-
240
- results.forEach { result -> println(result) }
220
+ :start-after: // start-atlas-searchoperator-helpers
221
+ :end-before: // end-atlas-searchoperator-helpers
222
+ :dedent:
241
223
242
224
.. output::
243
225
:language: console
Original file line number Diff line number Diff line change @@ -42,5 +42,28 @@ fun main() {
42
42
// start-aggregation-explain
43
43
print (collection.aggregate(pipeline).explain())
44
44
// end-aggregation-explain
45
+
46
+ // start-atlas-searchoperator-helpers
47
+ val searchStage: Bson = Aggregates .search(
48
+ SearchOperator .compound()
49
+ .filter(
50
+ listOf (
51
+ SearchOperator .text(fieldPath(" genres" ), " Drama" ),
52
+ SearchOperator .phrase(fieldPath(" cast" ), " sylvester stallone" ),
53
+ SearchOperator .numberRange(fieldPath(" year" )).gtLt(1980 , 1989 ),
54
+ SearchOperator .wildcard(fieldPath(" title" ), " Rocky *" )
55
+ )
56
+ )
57
+ )
58
+
59
+ val projection = Projections .fields(
60
+ Projections .include(" title" , " year" , " genres" , " cast" )
61
+ )
62
+
63
+ val aggregatePipelineStages: List <Bson > = listOf (searchStage, Aggregates .project(projection))
64
+ val results = collection.aggregate<Document >(aggregatePipelineStages)
65
+
66
+ results.forEach { result -> println (result) }
67
+ // end-atlas-searchoperator-helpers
45
68
}
46
69
You can’t perform that action at this time.
0 commit comments