You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
965 B
Kotlin

package moe.odango.index.utils
import io.inbot.eskotlinwrapper.dsl.ESQuery
class TermsSetQuery : ESQuery(name = "terms_set") {
operator fun set(field: String, value: TermSetConfig) {
queryDetails[field] = value.toMap()
}
operator fun String.invoke(block: TermSetConfig.() -> Unit) {
val config = TermSetConfig()
block(config)
set(this, config)
}
}
fun termsSet(block: TermsSetQuery.() -> Unit): TermsSetQuery {
val q = TermsSetQuery()
block(q)
return q
}
class TermSetConfig {
private val map = mutableMapOf<String, Any>()
@Suppress("UNCHECKED_CAST")
var terms: Set<Any>
set(value) {
map["terms"] = value as Any
}
get() = map["terms"] as? Set<Any> ?: emptySet()
var minimumShouldMatch: Int?
get() = map["minimum_should_match_field"] as? Int
set(value) { map["minimum_should_match_field"] = value as Any }
fun toMap() = map
}