net.nemerosa.ontrack.model.structure.SearchIndexMappingExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ontrack-model Show documentation
Show all versions of ontrack-model Show documentation
Ontrack module: ontrack-model
package net.nemerosa.ontrack.model.structure
import kotlin.reflect.KProperty1
@SearchIndexMappingMarker
fun indexMappings(code: SearchIndexMappingBuilder.() -> Unit): SearchIndexMapping {
val builder = SearchIndexMappingBuilder()
builder.code()
return builder.createMapping()
}
@SearchIndexMappingMarker
class SearchIndexMappingBuilder {
private val fields = mutableListOf>()
operator fun KProperty1.unaryPlus(): SearchIndexMappingFieldBuilder {
val builder = SearchIndexMappingFieldBuilder(this)
fields.add(builder)
return builder
}
fun type(typeName: String, typeInit: SearchIndexMappingFieldTypeBuilder.() -> Unit = {}) = SearchIndexMappingFieldTypeBuilder(typeName).apply { typeInit() }
fun id(typeInit: SearchIndexMappingFieldTypeBuilder.() -> Unit = {}) = type("long", typeInit)
fun keyword(typeInit: SearchIndexMappingFieldTypeBuilder.() -> Unit = {}) = type("keyword", typeInit)
fun nested(typeInit: SearchIndexMappingFieldTypeBuilder.() -> Unit = {}) = type("nested", typeInit)
fun `object`(typeInit: SearchIndexMappingFieldTypeBuilder.() -> Unit = {}) = type("object", typeInit)
fun timestamp(typeInit: SearchIndexMappingFieldTypeBuilder.() -> Unit = {}) = type("date", typeInit)
fun text(typeInit: SearchIndexMappingFieldTypeBuilder.() -> Unit = {}) = type("text", typeInit)
fun createMapping() = SearchIndexMapping(
fields = fields.map { it.createField() }
)
}
@SearchIndexMappingMarker
class SearchIndexMappingFieldBuilder(
private val property: KProperty1
) {
private val types = mutableListOf()
infix fun to(typeBuilder: SearchIndexMappingFieldTypeBuilder): SearchIndexMappingFieldBuilder {
types.add(typeBuilder.createType())
return this
}
fun createField() = SearchIndexMappingField(
name = property.name,
types = types.toList()
)
}
@SearchIndexMappingMarker
class SearchIndexMappingFieldTypeBuilder(private val typeName: String) {
var index: Boolean? = null
var scoreBoost: Double? = null
fun createType(): SearchIndexMappingFieldType {
return SearchIndexMappingFieldType(
type = typeName,
index = index,
scoreBoost = scoreBoost
)
}
}
@DslMarker
annotation class SearchIndexMappingMarker
© 2015 - 2025 Weber Informatics LLC | Privacy Policy