
commonMain.com.algolia.client.model.search.IgnorePlurals.kt Maven / Gradle / Ivy
/** Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. */
package com.algolia.client.model.search
import com.algolia.client.exception.AlgoliaClientException
import com.algolia.client.extensions.internal.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.*
import kotlin.jvm.JvmInline
/**
* Treats singular, plurals, and other forms of declensions as matching terms. `ignorePlurals` is used in conjunction with the `queryLanguages` setting. _list_: language ISO codes for which ignoring plurals should be enabled. This list will override any values that you may have set in `queryLanguages`. _true_: enables the ignore plurals feature, where singulars and plurals are considered equivalent (\"foot\" = \"feet\"). The languages supported here are either [every language](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/supported-languages/) (this is the default) or those set by `queryLanguages`. _false_: turns off the ignore plurals feature, so that singulars and plurals aren't considered to be the same (\"foot\" will not find \"feet\").
*
* Implementations:
* - [Boolean] - *[IgnorePlurals.of]*
* - [List] - *[IgnorePlurals.of]*
*/
@Serializable(IgnorePluralsSerializer::class)
public sealed interface IgnorePlurals {
@JvmInline
public value class BooleanValue(public val value: Boolean) : IgnorePlurals
@JvmInline
public value class ListOfStringValue(public val value: List) : IgnorePlurals
public companion object {
/** [IgnorePlurals] as [Boolean] Value. */
public fun of(value: Boolean): IgnorePlurals {
return BooleanValue(value)
}
/** [IgnorePlurals] as [List] Value. */
public fun of(value: List): IgnorePlurals {
return ListOfStringValue(value)
}
}
}
internal class IgnorePluralsSerializer : KSerializer {
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("IgnorePlurals")
override fun serialize(encoder: Encoder, value: IgnorePlurals) {
when (value) {
is IgnorePlurals.BooleanValue -> Boolean.serializer().serialize(encoder, value.value)
is IgnorePlurals.ListOfStringValue -> ListSerializer(String.serializer()).serialize(encoder, value.value)
}
}
override fun deserialize(decoder: Decoder): IgnorePlurals {
val codec = decoder.asJsonDecoder()
val tree = codec.decodeJsonElement()
// deserialize Boolean
if (tree is JsonPrimitive) {
try {
val value = codec.json.decodeFromJsonElement(Boolean.serializer(), tree)
return IgnorePlurals.of(value)
} catch (e: Exception) {
// deserialization failed, continue
println("Failed to deserialize Boolean (error: ${e.message})")
}
}
// deserialize List
if (tree is JsonArray) {
try {
val value = codec.json.decodeFromJsonElement(ListSerializer(String.serializer()), tree)
return IgnorePlurals.of(value)
} catch (e: Exception) {
// deserialization failed, continue
println("Failed to deserialize List (error: ${e.message})")
}
}
throw AlgoliaClientException("Failed to deserialize json element: $tree")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy