All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.algolia.client.model.search.RemoveStopWords.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

/**
 * Removes stop (common) words from the query before executing it. `removeStopWords` is used in conjunction with the `queryLanguages` setting. _list_: language ISO codes for which stop words should be enabled. This list will override any values that you may have set in `queryLanguages`. _true_: enables the stop words feature, ensuring that stop words are removed from consideration in a search. 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 stop words feature, allowing stop words to be taken into account in a search.
 *
 * Implementations:
 * - [Boolean] - *[RemoveStopWords.of]*
 * - [List] - *[RemoveStopWords.of]*
 */
@Serializable(RemoveStopWordsSerializer::class)
public sealed interface RemoveStopWords {

  @JvmInline
  public value class BooleanValue(public val value: Boolean) : RemoveStopWords

  @JvmInline
  public value class ListOfStringValue(public val value: List) : RemoveStopWords

  public companion object {

    /** [RemoveStopWords] as [Boolean] Value. */
    public fun of(value: Boolean): RemoveStopWords {
      return BooleanValue(value)
    }

    /** [RemoveStopWords] as [List] Value. */
    public fun of(value: List): RemoveStopWords {
      return ListOfStringValue(value)
    }
  }
}

internal class RemoveStopWordsSerializer : KSerializer {

  override val descriptor: SerialDescriptor = buildClassSerialDescriptor("RemoveStopWords")

  override fun serialize(encoder: Encoder, value: RemoveStopWords) {
    when (value) {
      is RemoveStopWords.BooleanValue -> Boolean.serializer().serialize(encoder, value.value)
      is RemoveStopWords.ListOfStringValue -> ListSerializer(String.serializer()).serialize(encoder, value.value)
    }
  }

  override fun deserialize(decoder: Decoder): RemoveStopWords {
    val codec = decoder.asJsonDecoder()
    val tree = codec.decodeJsonElement()

    // deserialize Boolean
    if (tree is JsonPrimitive) {
      try {
        val value = codec.json.decodeFromJsonElement(Boolean.serializer(), tree)
        return RemoveStopWords.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 RemoveStopWords.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