Skip to content

Latest commit

 

History

History
131 lines (99 loc) · 4.92 KB

README.md

File metadata and controls

131 lines (99 loc) · 4.92 KB

Algolia for Scala

The perfect starting point to integrate Algolia within your Scala project

Maven Central Licence

DocumentationCommunity ForumStack OverflowReport a bugFAQSupport

✨ Features

  • Supports Scala 2.13 and 3.3
  • Asynchronous methods to target Algolia's API
  • Json as case class

💡 Getting Started

WARNING: The JVM has an infinite cache on successful DNS resolution. As our hostnames points to multiple IPs, the load could be not evenly spread among our machines, and you might also target a dead machine.

You should change this TTL by setting the property networkaddress.cache.ttl. For example, to set the cache to 60 seconds:

java.security.Security.setProperty("networkaddress.cache.ttl", "60");

For debug purposes, you can enable debug logging on the API client. It's using slf4j so it should be compatible with most java loggers.

💡 Getting Started

To get started, add the algoliasearch-client-scala dependency to your project, with Maven, add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.algolia</groupId>
    <artifactId>algoliasearch-scala_2.13</artifactId>
    <version>[2,)</version>
</dependency>

For snapshots, add the sonatype repository:

<repositories>
    <repository>
        <id>oss-sonatype</id>
        <name>oss-sonatype</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

If you're using sbt, add the following dependency to your build.sbt file:

libraryDependencies += "com.algolia" %% "algoliasearch-scala" % "[2,)"

For snapshots, add the sonatype repository:

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

You can now import the Algolia API client in your project and play with it.

import algoliasearch.api.SearchClient

val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")

// Add a new record to your Algolia index
val response = client.saveObject(
  indexName = "<YOUR_INDEX_NAME>",
  body = JObject(List(JField("objectID", JString("id")), JField("test", JString("val"))))
)

// Use the response
val value = Await.result(response, Duration(100, "sec"))

// Poll the task status to know when it has been indexed
client.waitTask("<YOUR_INDEX_NAME>", response.getTaskID())

// Fetch search results, with typo tolerance
val response = client.search(
  searchMethodParams = SearchMethodParams(
    requests = Seq(
      SearchForHits(
        indexName = "<YOUR_INDEX_NAME>",
        query = Some("<YOUR_QUERY>"),
        hitsPerPage = Some(50)
      )
    )
  )
)

// Use the response
val value = Await.result(response, Duration(100, "sec"))

For full documentation, visit the Algolia Scala API Client.

❓ Troubleshooting

Encountering an issue? Before reaching out to support, we recommend heading to our FAQ where you will find answers for the most common issues and gotchas with the client. You can also open a GitHub issue

Contributing

This repository hosts the code of the generated Algolia API client for Scala, if you'd like to contribute, head over to the main repository. You can also find contributing guides on our documentation website.

📄 License

The Algolia Scala API Client is an open-sourced software licensed under the MIT license.