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
Compatible with Kotlin 1.3.30 and higher
INSTALL
// Gradle
repositories {
mavenCentral()
}
dependencies {
implementation "com.algolia:algoliasearch-client-kotlin:$kotlin_client_version"
// for Gradle version < 6.0, use the following instead
implementation "com.algolia:algoliasearch-client-kotlin-jvm:$kotlin_client_version"
// Choose one of the following HTTP clients
implementation "io.ktor:ktor-client-apache:$ktor_version"
implementation "io.ktor:ktor-client-okhttp:$ktor_version"
implementation "io.ktor:ktor-client-android:$ktor_version"
implementation "io.ktor:ktor-client-cio:$ktor_version"
implementation "io.ktor:ktor-client-jetty:$ktor_version"
}
INDEX
// With JsonObject
val json = listOf(
ObjectID("myID1") to json {
"firstname" to "Jimmie"
"lastname" to "Barninger"
},
ObjectID("myID1") to json {
"firstname" to "Warren"
"lastname" to "Speach"
}
)
index.replaceObjects(json)
// With serializable class
@Serializable
data class Contact(
val firstname: String,
val lastname: String,
override val objectID: ObjectID
) : Indexable
val contacts = listOf(
Contact("Jimmie", "Barninger", ObjectID("myID")),
Contact("Jimmie", "Barninger", ObjectID("myID"))
)
index.replaceObjects(Contact.serializer(), contacts)
SEARCH
@Serializable
data class Contact(
val firstname: String,
val lastname: String
)
val indexName = IndexName("contacts")
val index = client.initIndex(indexName)
val query = queryBuilder {
query = "query string"
hitsPerPage = 50
attributesToRetrieve {
+"firstname"
+"lastname"
}
}
val result = index.search(query)
result.hits.deserialize(Contact.serializer())