@@ -16,7 +16,7 @@ Overview
1616--------
1717
1818In this guide, you can learn how to run a **text search** in the MongoDB
19- Java driver.
19+ Kotlin driver.
2020
2121You can use a text search to retrieve documents that contain a **term**
2222or a **phrase** in a specified field. A term is a sequence of characters
@@ -52,6 +52,11 @@ movie franchise. Each document contains a title field and a tags field.
5252 { "_id": 3, "title": "Furious 7", "tags": ["emotional"] }
5353 { "_id": 4, "title": "The Fate of the Furious", "tags": ["betrayal"] }
5454
55+ This data is modeled with the following Kotlin data class:
56+
57+ .. literalinclude:: /examples/generated/SearchTextTest.snippet.search-data-model.kt
58+ :language: kotlin
59+
5560Text Index
5661~~~~~~~~~~
5762
@@ -65,11 +70,8 @@ searches on the ``title`` field, create a text index using the
6570:ref:`Indexes <index-text-indexes>` builder with the following
6671snippet:
6772
68- .. literalinclude:: /includes/fundamentals/code-snippets/SearchText.java
69- :language: java
70- :dedent:
71- :start-after: begin textIndex
72- :end-before: end textIndex
73+ .. literalinclude:: /examples/generated/SearchTextTest.snippet.text-index.kt
74+ :language: kotlin
7375
7476For more information, see the following resources:
7577
@@ -105,16 +107,14 @@ which means the search matches lowercase and uppercase values.
105107
106108To specify a case sensitive search, use the following snippet:
107109
108- .. code-block:: java
109-
110- TextSearchOptions options = new TextSearchOptions().caseSensitive(true);
111- Bson filter = Filters.text("SomeText", options);
110+ .. literalinclude:: /examples/generated/SearchTextTest.snippet.specify-options.kt
111+ :language: kotlin
112112
113113For more information about the methods and classes mentioned in this section,
114114see the following API Documentation:
115115
116- - `Filters.text() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Filters.html#text(java.lang.String )>`__
117- - `TextSearchOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/TextSearchOptions.html >`__
116+ - `Filters.text() <TODO:(DOCSP-29169 )>`__
117+ - `TextSearchOptions <TODO:(DOCSP-29169) >`__
118118
119119.. _term_search:
120120
@@ -131,19 +131,16 @@ The following example runs a text search on the documents in the
131131``fast_and_furious_movies`` collection for titles that contain the
132132term "fast":
133133
134- .. literalinclude:: /includes/fundamentals/code-snippets/SearchText.java
135- :language: java
136- :dedent:
137- :start-after: begin termExample
138- :end-before: end termExample
134+ .. io-code-block::
139135
140- The following shows the output of the preceding code:
136+ .. input:: /examples/generated/SearchTextTest.snippet.search-term.kt
137+ :language: kotlin
141138
142- .. code-block :: json
143- :copyable: false
139+ .. output ::
140+ :language: console
144141
145- { "_id": 1, " title": " 2 Fast 2 Furious ", " tags": [" undercover", " drug dealer"] }
146- { "_id": 2, " title": " Fast 5", " tags": [" bank robbery", " full team"] }
142+ Movies(id= 1, title= 2 Fast 2 Furious, tags=[ undercover, drug dealer])
143+ Movies(id= 2, title= Fast 5, tags=[ bank robbery, full team])
147144
148145To match multiple terms in your text search, separate each term
149146with spaces in the ``Filters.text()`` builder method. The builder method
@@ -158,19 +155,16 @@ The following example runs a text search on the documents in the
158155``fast_and_furious_movies`` collection for titles that contain the
159156terms "fate" or "7":
160157
161- .. literalinclude:: /includes/fundamentals/code-snippets/SearchText.java
162- :language: java
163- :dedent:
164- :start-after: begin multipleTermExample
165- :end-before: end multipleTermExample
158+ .. io-code-block::
166159
167- The following shows the output of the preceding code:
160+ .. input:: /examples/generated/SearchTextTest.snippet.search-multiple-terms.kt
161+ :language: kotlin
168162
169- .. code-block :: json
170- :copyable: false
163+ .. output ::
164+ :language: console
171165
172- { "_id": 3, " title": " Furious 7", " tags": [" emotional"] }
173- { "_id": 4, " title": " The Fate of the Furious", " tags": [" betrayal"] }
166+ Movies(id= 3, title= Furious 7, tags=[ emotional])
167+ Movies(id= 4, title= The Fate of the Furious, tags=[ betrayal])
174168
175169Search Text by a Phrase
176170~~~~~~~~~~~~~~~~~~~~~~~
@@ -188,18 +182,15 @@ The following example runs a text search on the documents in the
188182``fast_and_furious_movies`` collection for titles that contain the
189183phrase "fate of the furious":
190184
191- .. literalinclude:: /includes/fundamentals/code-snippets/SearchText.java
192- :language: java
193- :dedent:
194- :start-after: begin phraseExample
195- :end-before: end phraseExample
185+ .. io-code-block::
196186
197- The following shows the output of the preceding code:
187+ .. input:: /examples/generated/SearchTextTest.snippet.search-phrase.kt
188+ :language: kotlin
198189
199- .. code-block :: json
200- :copyable: false
190+ .. output ::
191+ :language: console
201192
202- { "_id": 4, " title": " The Fate of the Furious", " tags": [" betrayal"] }
193+ Movies(id= 4, title= The Fate of the Furious, tags=[ betrayal])
203194
204195Search Text with Terms Excluded
205196~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -223,16 +214,13 @@ The following example runs a text search on the documents in the
223214``fast_and_furious_movies`` collection for titles that contain the
224215term "furious", but do not contain the term "fast":
225216
226- .. literalinclude:: /includes/fundamentals/code-snippets/SearchText.java
227- :language: java
228- :dedent:
229- :start-after: begin negateExample
230- :end-before: end negateExample
217+ .. io-code-block::
231218
232- The following shows the output of the preceding code:
219+ .. input:: /examples/generated/SearchTextTest.snippet.exclude-term.kt
220+ :language: kotlin
233221
234- .. code-block :: json
235- :copyable: false
222+ .. output ::
223+ :language: console
236224
237- { "_id": 3, " title": " Furious 7", " tags": [" emotional"] }
238- { "_id": 4, " title": " The Fate of the Furious", " tags": [" betrayal"] }
225+ Movies(id= 3, title= Furious 7, tags=[ emotional])
226+ Movies(id= 4, title= The Fate of the Furious, tags=[ betrayal])
0 commit comments