commonMain.com.algolia.search.model.settings.Distinct.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algoliasearch-client-kotlin-jvm Show documentation
Show all versions of algoliasearch-client-kotlin-jvm Show documentation
"Algolia is a powerful search-as-a-service solution, made easy to use with API clients, UI libraries, and pre-built integrations. Algolia API Client for Kotlin lets you easily use the Algolia Search REST API from your JVM project, such as Android or backend implementations."
package com.algolia.search.model.settings
import com.algolia.search.serialize.internal.asJsonInput
import com.algolia.search.serialize.internal.asJsonOutput
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.boolean
import kotlinx.serialization.json.intOrNull
import kotlinx.serialization.json.jsonPrimitive
/**
* Enables de-duplication or grouping of results.
* Distinct functionality is based on one attribute, as defined in [Settings.attributeForDistinct].
* Using this attribute, you can limit the number of returned records that contain the same value in that attribute.
*/
@Serializable(Distinct.Companion::class)
public data class Distinct(val count: Int) {
init {
if (count < 0) throw IllegalArgumentException("Distinct must be a positive integer")
}
public companion object : KSerializer {
override val descriptor: SerialDescriptor = Int.serializer().descriptor
override fun serialize(encoder: Encoder, value: Distinct) {
encoder.asJsonOutput().encodeJsonElement(JsonPrimitive(value.count))
}
override fun deserialize(decoder: Decoder): Distinct {
val json = decoder.asJsonInput()
val int = json.jsonPrimitive.intOrNull
if (int != null) {
return Distinct(int)
}
return json.jsonPrimitive.boolean.let { if (it) Distinct(1) else Distinct(0) }
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy