Skip to content

Commit

Permalink
Merge pull request #29 from kirillsinyuk/feature/27
Browse files Browse the repository at this point in the history
#27 add text index
  • Loading branch information
kirillsinyuk authored Mar 26, 2024
2 parents 2215ce2 + 95127b3 commit 4510852
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
implementation("io.github.microutils:kotlin-logging-jvm:3.0.5")

implementation("io.mongock:mongock-springboot-v3:5.4.0")
implementation("io.mongock:mongodb-springdata-v4-driver:5.4.0")

implementation("com.github.curious-odd-man:rgxgen:1.4")

developmentOnly("org.springframework.boot:spring-boot-docker-compose")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.kvsinyuk.elasticsearch.adapter.out.mongo.migration

import io.mongock.api.annotations.ChangeUnit
import io.mongock.api.annotations.Execution
import io.mongock.api.annotations.RollbackExecution
import org.springframework.data.mongodb.core.MongoTemplate
import org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexDefinitionBuilder

@ChangeUnit(id = "1", order = "1", author = "sinyukkv")
class AddTextIndex {
@Execution
fun run(mongoTemplate: MongoTemplate) {
val textIndex =
TextIndexDefinitionBuilder()
.onField("sellers.name.firstName")
.onField("sellers.name.lastName")
.onField("sellers.name.middleName")
.onField("buyers.name.firstName")
.onField("buyers.name.lastName")
.onField("buyers.name.middleName")
.onField("guarantors.name.firstName")
.onField("guarantors.name.lastName")
.onField("guarantors.name.middleName")
.onField("number")
.named(INDEX_NAME)
.build()

mongoTemplate.indexOps("deal").ensureIndex(textIndex)
}

@RollbackExecution
fun rollback(mongoTemplate: MongoTemplate) {
mongoTemplate.indexOps("deal").dropIndex(INDEX_NAME)
}

companion object {
const val INDEX_NAME = "deal_text_idx"
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.kvsinyuk.elasticsearch.config

import io.mongock.runner.springboot.EnableMongock
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.data.mongodb.config.EnableMongoAuditing
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories

@Configuration
@EnableMongock
@EnableMongoAuditing
@EnableMongoRepositories(basePackages = ["com.kvsinyuk.elasticsearch.adapter.out.mongo"])
@ComponentScan(basePackages = ["com.kvsinyuk.elasticsearch"])
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
generator.batch.count: 100

mongock:
migration-scan-package: com.kvsinyuk.elasticsearch.adapter.out.mongo.migration

0 comments on commit 4510852

Please sign in to comment.