Search API Client for Kotlin

Kotlin

Algolia Search API client for Kotlin, v1

Sign up
What is Algolia

What is Algolia

Algolia empowers modern developers to build world class search and discovery experiences without any DevOps.
Libraries with every major language and framework make it easy to enrich your users' experiences. 

Features

  • Gives API access to all Algolia functionality, settings, advanced features, and ML/AI products

  • With or without Android Studio, or Intellij Idea

  • Frontend Android projects using Kotlin

  • Backend JVM projects using Kotlin

  • Kotlin multiplatform, Kotlinx serialization, Ktor HTTP client

  • Domain Specific Locator (DSL) 

  • Background retry strategy to ensure uptime

  • Seamless batching via iterators to optimize number of network calls

  • Zero downtime reindexing feature

Version

  • Compatible with Kotlin 1.3.30 and higher

Related Integrations

  • InstantSearch for Android
  • Autocomplete

Get started

  • Install
    1
    // Gradle
    2
    repositories {
    3
        mavenCentral()
    4
    }
    5
    6
    dependencies {
    7
        implementation "com.algolia:algoliasearch-client-kotlin:$kotlin_client_version"
    8
        // for Gradle version < 6.0, use the following instead
    9
        implementation "com.algolia:algoliasearch-client-kotlin-jvm:$kotlin_client_version"
    10
        // Choose one of the following HTTP clients
    11
        implementation "io.ktor:ktor-client-apache:$ktor_version"
    12
        implementation "io.ktor:ktor-client-okhttp:$ktor_version"
    13
        implementation "io.ktor:ktor-client-android:$ktor_version"
    14
        implementation "io.ktor:ktor-client-cio:$ktor_version"
    15
        implementation "io.ktor:ktor-client-jetty:$ktor_version"
    16
    }
  • Index
    1
    // With JsonObject
    2
    val json = listOf(
    3
        ObjectID("myID1") to json {
    4
            "firstname" to "Jimmie"
    5
            "lastname" to "Barninger"
    6
        },
    7
        ObjectID("myID1") to json {
    8
            "firstname" to "Warren"
    9
            "lastname" to "Speach"
    10
        }
    11
    )
    12
    13
    index.replaceObjects(json)
    14
    15
    // With serializable class
    16
    @Serializable
    17
    data class Contact(
    18
        val firstname: String,
    19
        val lastname: String,
    20
        override val objectID: ObjectID
    21
    ) : Indexable
    22
    23
    val contacts = listOf(
    24
        Contact("Jimmie", "Barninger", ObjectID("myID")),
    25
        Contact("Jimmie", "Barninger", ObjectID("myID"))
    26
    )
    27
    28
    index.replaceObjects(Contact.serializer(), contacts)
  • Search
    1
    @Serializable
    2
    data class Contact(
    3
        val firstname: String,
    4
        val lastname: String
    5
    )
    6
    7
    val indexName = IndexName("contacts")
    8
    val index = client.initIndex(indexName)
    9
    val query = queryBuilder {
    10
        query = "query string"
    11
        hitsPerPage = 50
    12
        attributesToRetrieve {
    13
            +"firstname"
    14
            +"lastname"
    15
        }
    16
    }
    17
    val result = index.search(query)
    18
    19
    result.hits.deserialize(Contact.serializer())
Get started for free
Explore developer docs