-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75900ee
commit 67e5859
Showing
5 changed files
with
87 additions
and
33 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
31 changes: 31 additions & 0 deletions
31
api/src/main/kotlin/com/gmtkgamejam/routing/InfraRoutes.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,31 @@ | ||
package com.gmtkgamejam.routing | ||
|
||
import com.gmtkgamejam.models.posts.PostItem | ||
import com.gmtkgamejam.respondJSON | ||
import com.gmtkgamejam.search.OpenSearch | ||
import com.gmtkgamejam.search.OpensearchClusterConfigurer | ||
import com.gmtkgamejam.search.SearchItem | ||
import com.gmtkgamejam.services.PostService | ||
import io.ktor.http.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.routing.* | ||
import org.litote.kmongo.eq | ||
|
||
// TODO: Auth control | ||
fun Application.configureInfraRouting() { | ||
|
||
val postService = PostService() | ||
|
||
routing { | ||
route("/infra") { | ||
route("/se") { | ||
get("/reset") { | ||
OpensearchClusterConfigurer.initCluster() | ||
// TODO: Bulk uploading! | ||
postService.getPosts(PostItem::deletedAt eq null).map { OpenSearch.index(SearchItem(it)) } | ||
call.respondJSON("Search engine reset complete", HttpStatusCode.OK) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
47 changes: 47 additions & 0 deletions
47
api/src/main/kotlin/com/gmtkgamejam/search/OpensearchClusterConfigurer.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,47 @@ | ||
package com.gmtkgamejam.search | ||
|
||
import org.apache.hc.core5.http.HttpHost | ||
import org.opensearch.client.json.jackson.JacksonJsonpMapper | ||
import org.opensearch.client.opensearch.OpenSearchClient | ||
import org.opensearch.client.opensearch._types.mapping.SearchAsYouTypeProperty | ||
import org.opensearch.client.opensearch.indices.CreateIndexRequest | ||
import org.opensearch.client.opensearch.indices.DeleteIndexRequest | ||
import org.opensearch.client.transport.OpenSearchTransport | ||
import org.opensearch.client.transport.httpclient5.ApacheHttpClient5TransportBuilder | ||
|
||
object OpensearchClusterConfigurer { | ||
|
||
private val client: OpenSearchClient | ||
|
||
init { | ||
val transport: OpenSearchTransport = ApacheHttpClient5TransportBuilder | ||
.builder(HttpHost("http", "localhost", 9200)) | ||
.setMapper(JacksonJsonpMapper()) | ||
.build() | ||
|
||
client = OpenSearchClient(transport) | ||
} | ||
|
||
// Manually called when needed | ||
// TODO: Add to a superadmin dashboard somewhere | ||
/** | ||
* Initialise the cluster indexes | ||
* | ||
* Call to set up/refresh the cluster's `posts` index - all data will be lost | ||
*/ | ||
fun initCluster() { | ||
initIndices() | ||
} | ||
|
||
private fun initIndices() { | ||
client.indices().delete(DeleteIndexRequest.Builder().index("posts").build()) | ||
|
||
val createPostsIndex = CreateIndexRequest.Builder() | ||
.index("posts") | ||
.mappings { it.properties(mapOf("description_shingle" to SearchAsYouTypeProperty.Builder().build()._toProperty())) } | ||
.build() | ||
|
||
client.indices().create(createPostsIndex) | ||
} | ||
|
||
} |