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

commonMain.com.algolia.search.model.rule.Anchoring.kt Maven / Gradle / Ivy

Go to download

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 SearchREST API from your JVM project, such as Android or backend implementations.

The newest version!
package com.algolia.search.model.rule

import com.algolia.search.model.internal.Raw
import com.algolia.search.model.search.Query
import com.algolia.search.serialize.KeyContains
import com.algolia.search.serialize.KeyEndsWith
import com.algolia.search.serialize.KeyIs
import com.algolia.search.serialize.KeyStartsWith
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

@Serializable(Anchoring.Companion::class)
public sealed class Anchoring(override val raw: String) : Raw {

    /**
     * The [Pattern] matches the [Query.query].
     */
    public object Is : Anchoring(KeyIs)

    /**
     * The [Pattern] matches the beginning of the [Query.query].
     */
    public object StartsWith : Anchoring(KeyStartsWith)

    /**
     * The [Pattern] matches the beginning of the [Query.query].
     */
    public object EndsWith : Anchoring(KeyEndsWith)

    /**
     * The [Pattern] is contained by the [Query.query].
     */
    public object Contains : Anchoring(KeyContains)

    public data class Other(override val raw: String) : Anchoring(raw)

    public companion object : KSerializer {

        private val serializer = String.serializer()

        override val descriptor: SerialDescriptor = serializer.descriptor

        override fun serialize(encoder: Encoder, value: Anchoring) {
            serializer.serialize(encoder, value.raw)
        }

        override fun deserialize(decoder: Decoder): Anchoring {
            return when (val string = serializer.deserialize(decoder)) {
                KeyIs -> Is
                KeyEndsWith -> EndsWith
                KeyStartsWith -> StartsWith
                KeyContains -> Contains
                else -> Other(string)
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy