-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOCSP-33429: atlas search idx mgmt (#144)
* DOCSP-33429: (wip) atlas search idx mgmt * DOCSP-33429: atlas search idx mgmt * fixes * MW PR fixes 1 * MW PR Small fixes (cherry picked from commit 1784061)
- Loading branch information
Showing
7 changed files
with
327 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
|
||
import com.mongodb.client.model.SearchIndexModel | ||
import com.mongodb.kotlin.client.coroutine.MongoClient | ||
import config.getConfig | ||
import kotlinx.coroutines.flow.toList | ||
import kotlinx.coroutines.runBlocking | ||
import org.bson.Document | ||
import org.junit.jupiter.api.AfterAll | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import kotlin.test.Ignore | ||
import kotlin.test.assertFalse | ||
|
||
// :replace-start: { | ||
// "terms": { | ||
// "CONNECTION_URI_PLACEHOLDER": "\"<connection string>\"" | ||
// } | ||
// } | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class SearchIndexesTest { | ||
|
||
companion object { | ||
private val config = getConfig() | ||
private val CONNECTION_URI_PLACEHOLDER = config.connectionUri | ||
|
||
val mongoClient = MongoClient.create(CONNECTION_URI_PLACEHOLDER) | ||
val database = mongoClient.getDatabase("sample_mflix") | ||
val moviesCollection = database.getCollection<Document>("movies") | ||
|
||
@AfterAll | ||
@JvmStatic | ||
fun afterAll() { | ||
runBlocking { | ||
moviesCollection.drop() | ||
} | ||
mongoClient.close() | ||
} | ||
} | ||
|
||
@Ignore | ||
@Test | ||
fun singleSearchIndexTest() = runBlocking { | ||
// :snippet-start: single-search-index-create | ||
val index = Document( | ||
"mappings", | ||
Document("dynamic", true) | ||
) | ||
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", index) | ||
// :snippet-end: | ||
println("Index created: $resultCreateIndex") | ||
assertEquals("myIndex", resultCreateIndex) | ||
} | ||
|
||
@Ignore | ||
@Test | ||
fun multipleSearchIndexTest() = runBlocking { | ||
// :snippet-start: multi-search-index-create | ||
val indexOne = SearchIndexModel( | ||
"myIndex1", | ||
Document("analyzer", "lucene.standard").append( | ||
"mappings", Document("dynamic", true) | ||
) | ||
) | ||
|
||
val indexTwo = SearchIndexModel( | ||
"myIndex2", | ||
Document("analyzer", "lucene.simple").append( | ||
"mappings", Document("dynamic", true) | ||
) | ||
) | ||
|
||
val resultCreateIndexes = moviesCollection | ||
.createSearchIndexes(listOf(indexOne, indexTwo)) | ||
// :snippet-end: | ||
assertEquals(listOf("myIndex1", "myIndex2"), resultCreateIndexes.toList()) | ||
} | ||
|
||
@Ignore | ||
@Test | ||
fun listSearchIndexTest() = runBlocking { | ||
// :snippet-start: list-search-indexes | ||
val searchIndexesList = moviesCollection.listSearchIndexes().toList() | ||
// :snippet-end: | ||
|
||
assertFalse(searchIndexesList.isEmpty()) | ||
} | ||
|
||
@Ignore | ||
@Test | ||
fun updateSearchIndexTest() = runBlocking { | ||
// :snippet-start: update-search-indexes | ||
moviesCollection.updateSearchIndex( | ||
"myIndex", | ||
Document("analyzer", "lucene.simple").append( | ||
"mappings", | ||
Document("dynamic", false) | ||
.append( | ||
"fields", | ||
Document( | ||
"title", | ||
Document("type", "string") | ||
) | ||
) | ||
) | ||
) | ||
// :snippet-end: | ||
} | ||
|
||
@Ignore | ||
@Test | ||
fun dropSearchIndexTest() = runBlocking { | ||
// :snippet-start: drop-search-index | ||
moviesCollection.dropSearchIndex("myIndex"); | ||
// :snippet-end: | ||
} | ||
|
||
} | ||
// :replace-end: |
1 change: 1 addition & 0 deletions
1
source/examples/generated/SearchIndexesTest.snippet.drop-search-index.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
moviesCollection.dropSearchIndex("myIndex"); |
1 change: 1 addition & 0 deletions
1
source/examples/generated/SearchIndexesTest.snippet.list-search-indexes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
val searchIndexesList = moviesCollection.listSearchIndexes().toList() |
16 changes: 16 additions & 0 deletions
16
source/examples/generated/SearchIndexesTest.snippet.multi-search-index-create.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
val indexOne = SearchIndexModel( | ||
"myIndex1", | ||
Document("analyzer", "lucene.standard").append( | ||
"mappings", Document("dynamic", true) | ||
) | ||
) | ||
|
||
val indexTwo = SearchIndexModel( | ||
"myIndex2", | ||
Document("analyzer", "lucene.simple").append( | ||
"mappings", Document("dynamic", true) | ||
) | ||
) | ||
|
||
val resultCreateIndexes = moviesCollection | ||
.createSearchIndexes(listOf(indexOne, indexTwo)) |
5 changes: 5 additions & 0 deletions
5
source/examples/generated/SearchIndexesTest.snippet.single-search-index-create.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
val index = Document( | ||
"mappings", | ||
Document("dynamic", true) | ||
) | ||
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", index) |
14 changes: 14 additions & 0 deletions
14
source/examples/generated/SearchIndexesTest.snippet.update-search-indexes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
moviesCollection.updateSearchIndex( | ||
"myIndex", | ||
Document("analyzer", "lucene.simple").append( | ||
"mappings", | ||
Document("dynamic", false) | ||
.append( | ||
"fields", | ||
Document( | ||
"title", | ||
Document("type", "string") | ||
) | ||
) | ||
) | ||
) |
Oops, something went wrong.