Skip to content

Commit 590a614

Browse files
committed
feat: add tracking option to search dsl
1 parent 66551b9 commit 590a614

File tree

2 files changed

+36
-0
lines changed
  • core/src

2 files changed

+36
-0
lines changed

Diff for: core/src/main/kotlin/com/github/inflab/spring/data/mongodb/core/aggregation/search/SearchStageDsl.kt

+11
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ class SearchStageDsl : SearchOperator by SearchOperatorDsl(), SearchCollector by
4848
field = value
4949
}
5050

51+
/**
52+
* Document that specifies the tracking option to retrieve analytics information on the search terms.
53+
*
54+
* @see <a href="https://www.mongodb.com/docs/atlas/atlas-search/tracking">Track Search Terms</a>
55+
*/
56+
var tracking: String? = null
57+
set(value) {
58+
value?.let { document["tracking"] = Document("searchTerms", value) }
59+
field = value
60+
}
61+
5162
/**
5263
* Configures an option to include a lower bound count of the number of documents that match the query.
5364
*

Diff for: core/src/test/kotlin/com/github/inflab/spring/data/mongodb/core/aggregation/search/SearchStageDslTest.kt

+25
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,29 @@ internal class SearchStageDslTest : FreeSpec({
213213
)
214214
}
215215
}
216+
217+
"tracking" - {
218+
"should build a tracking option" {
219+
// given
220+
val stage = search {
221+
tracking = "text"
222+
}
223+
224+
// when
225+
val result = stage.build()
226+
227+
// then
228+
result.shouldBeJson(
229+
"""
230+
{
231+
"${"$"}search": {
232+
"tracking": {
233+
"searchTerms": "text"
234+
}
235+
}
236+
}
237+
""".trimIndent(),
238+
)
239+
}
240+
}
216241
})

0 commit comments

Comments
 (0)