Skip to content

Commit 4896615

Browse files
committed
WIP
1 parent e99726e commit 4896615

File tree

7 files changed

+77
-88
lines changed

7 files changed

+77
-88
lines changed

examples/src/test/kotlin/AggregatesBuilderTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class AggregatesBuilderTest {
5656
val genres: List<String>,
5757
val rated: String,
5858
val plot: String,
59+
val fullplot: String,
5960
val runtime: Int,
6061
val imdb: IMDB
6162
){
@@ -951,6 +952,37 @@ class AggregatesBuilderTest {
951952
assertEquals("Back to the Future", results.first().title)
952953
}
953954

955+
/* NOTE: Test is not run by default. FTS requires the creation of a text index on the collection before running
956+
(see note at top of file for additional setup requirements for FTS).
957+
*/
958+
@Ignore
959+
fun atlasSearchOperatorTest() = runBlocking {
960+
// :snippet-start: atlas-search-pipeline
961+
val searchStage = Aggregates.search(
962+
SearchOperator.compound()
963+
.filter(
964+
listOf(
965+
SearchOperator.`in`(SearchPath.fieldPath(Movie::genres.name), listOf("Comedy")),
966+
SearchOperator.phrase(SearchPath.fieldPath(Movie::fullplot.name), "new york"),
967+
SearchOperator.numberRange(SearchPath.fieldPath(Movie::year.name)).gtLt(1950, 2000),
968+
SearchOperator.wildcard(SearchPath.fieldPath(Movie::title.name), "Love *")
969+
)
970+
)
971+
)
972+
973+
val projectStage = Aggregates.project(
974+
Projections.include("title", "year", "genres", "cast"))
975+
976+
val pipeline = listOf(searchStage, projectStage)
977+
val resultsFlow = ftsCollection.aggregate(pipeline)
978+
979+
resultsFlow.collect { println(it) }
980+
// :snippet-end:
981+
982+
val result = resultsFlow.toList()
983+
assertEquals(2, result.size)
984+
}
985+
954986
/* NOTE: Test is not run by default. FTS requires the creation of a text index on the collection before running
955987
(see note at top of file for additional setup requirements for FTS).
956988
*/

examples/src/test/kotlin/AggregationTest.kt

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -245,35 +245,4 @@ class AggregationTest {
245245
assertEquals(method1, method2)
246246

247247
}
248-
249-
/* NOTE: Test is not run by default. FTS requires the creation of a text index on the collection before running.
250-
*/
251-
@Ignore
252-
fun atlasSearchOperatorTest() = runBlocking {
253-
val collection = mongoClient.getDatabase("sample_mflix").getCollection<Document>("movies")
254-
// :snippet-start: atlas-search-pipeline
255-
val searchStage = Aggregates.search(
256-
SearchOperator.compound()
257-
.filter(
258-
listOf(
259-
SearchOperator.`in`(fieldPath("genres"), listOf("Comedy")),
260-
SearchOperator.phrase(fieldPath("fullplot"), "new york"),
261-
SearchOperator.numberRange(fieldPath("year")).gtLt(1950, 2000),
262-
SearchOperator.wildcard(fieldPath("title"), "Love *")
263-
)
264-
)
265-
)
266-
267-
val projectStage = Aggregates.project(
268-
Projections.include("title", "year", "genres", "cast"))
269-
270-
val pipeline = listOf(searchStage, projectStage)
271-
val resultsFlow = collection.aggregate(pipeline)
272-
273-
resultsFlow.collect { println(it) }
274-
// :snippet-end:
275-
276-
val result = resultsFlow.toList()
277-
assertEquals(2, result.size)
278-
}
279248
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
val searchStage = Aggregates.search(
2+
SearchOperator.compound()
3+
.filter(
4+
listOf(
5+
SearchOperator.`in`(SearchPath.fieldPath(Movie::genres.name), listOf("Comedy")),
6+
SearchOperator.phrase(SearchPath.fieldPath(Movie::fullplot.name), "new york"),
7+
SearchOperator.numberRange(SearchPath.fieldPath(Movie::year.name)).gtLt(1950, 2000),
8+
SearchOperator.wildcard(SearchPath.fieldPath(Movie::title.name), "Love *")
9+
)
10+
)
11+
)
12+
13+
val projectStage = Aggregates.project(
14+
Projections.include("title", "year", "genres", "cast"))
15+
16+
val pipeline = listOf(searchStage, projectStage)
17+
val resultsFlow = ftsCollection.aggregate(pipeline)
18+
19+
resultsFlow.collect { println(it) }

source/examples/generated/AggregatesBuilderTest.snippet.movie-data-class.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ data class Movie(
44
val genres: List<String>,
55
val rated: String,
66
val plot: String,
7+
val fullplot: String,
78
val runtime: Int,
89
val imdb: IMDB
910
){

source/examples/generated/AggregationTest.snippet.atlas-search-pipeline.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.

source/fundamentals/aggregation.txt

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -215,43 +215,6 @@ first element in the ``categories`` field.
215215
Results(name=456 Cookies Shop, firstCategory=Bakery)
216216
Results(name=XYZ Steak Buffet, firstCategory=Steak)
217217

218-
.. _kotlin-cr-atlas-search-stage:
219-
220-
Pipelines Stages for Atlas Search
221-
---------------------------------
222-
223-
:atlas:`Atlas Search </atlas-search>` queries take the form of an aggregation pipeline stage. Atlas
224-
Search provides ``$search`` and ``$searchMeta`` stages, both of which must be the first
225-
stage in any query pipeline. For more information about Atlas pipeline stages,
226-
see the :atlas:`Choose the Aggregation Pipeline Stage
227-
</atlas-search/query-syntax/>` page in the Atlas
228-
manual.
229-
230-
.. tip:: Aggregates Builders
231-
232-
This example in this section uses helper methods from the
233-
:ref:`Aggregates <aggregates-builders>` builder class.
234-
235-
.. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst
236-
237-
.. replacement:: as-idx-link
238-
239-
the :ref:`kotlin-search-indexes` section of the Indexes guide
240-
241-
.. replacement:: atlas-query-operators-example
242-
243-
.. io-code-block::
244-
245-
.. input:: /examples/generated/AggregationTest.snippet.atlas-search-pipeline.kt
246-
:language: kotlin
247-
248-
.. output::
249-
:language: console
250-
:visible: false
251-
252-
Document{{_id=573a1397f29313caabce734c, genres=[Comedy, Romance], cast=[George Hamilton, Susan Saint James, Richard Benjamin, Dick Shawn], title=Love at First Bite, year=1979}}
253-
Document{{_id=573a1399f29313caabcee81e, genres=[Comedy, Drama], cast=[Warren Beatty, Annette Bening, Katharine Hepburn, Garry Shandling], title=Love Affair, year=1994}}
254-
255218
API Documentation
256219
-----------------
257220

@@ -262,4 +225,3 @@ see the following API Documentation:
262225
- `$group <{+core-api+}/client/model/Aggregates.html#group(TExpression,java.util.List)>`__
263226
- `$project <{+core-api+}/client/model/Aggregates.html#project(org.bson.conversions.Bson)>`__
264227
- `Projections <{+core-api+}/client/model/Projections.html>`__
265-
- `SearchOperator <{+core-api+}/com/mongodb/client/model/search/SearchOperator.html>`__

source/fundamentals/builders/aggregates.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,31 @@ field in the ``movies`` collection for text that contains the word "Future":
887887
Learn more about the builders from the
888888
`search package API documentation <{+core-api+}/client/model/search/package-summary.html>`__.
889889

890+
.. _kotlin-cr-atlas-search-stage:
891+
892+
Search Operator Methods
893+
~~~~~~~~~~~~~~~~~~~~~~~
894+
895+
.. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst
896+
897+
.. replacement:: as-idx-link
898+
899+
the :ref:`kotlin-search-indexes` section of the Indexes guide
900+
901+
.. replacement:: atlas-query-operators-example
902+
903+
.. io-code-block::
904+
905+
.. input:: /examples/generated/AggregatesBuilderTest.snippet.atlas-search-pipeline.kt
906+
:language: kotlin
907+
908+
.. output::
909+
:language: console
910+
:visible: false
911+
912+
Document{{_id=573a1397f29313caabce734c, genres=[Comedy, Romance], cast=[George Hamilton, Susan Saint James, Richard Benjamin, Dick Shawn], title=Love at First Bite, year=1979}}
913+
Document{{_id=573a1399f29313caabcee81e, genres=[Comedy, Drama], cast=[Warren Beatty, Annette Bening, Katharine Hepburn, Garry Shandling], title=Love Affair, year=1994}}
914+
890915
Atlas Search Metadata
891916
---------------------
892917

0 commit comments

Comments
 (0)