- C#
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
The Query Suggestions API client is part of the To use the Query Suggestions API client,
import these namespaces:To create an instance of the client:Replace
Algolia.Search package.
To install this package, run:Report incorrect code
Copy
dotnet add package Algolia.Search
C#
Report incorrect code
Copy
using Algolia.Search.Clients;
using Algolia.Search.Http;
using Algolia.Search.Models.QuerySuggestions;
C#
Report incorrect code
Copy
var client = new QuerySuggestionsClient(
new QuerySuggestionsConfig(
"ALGOLIA_APPLICATION_ID",
"ALGOLIA_API_KEY",
"ALGOLIA_APPLICATION_REGION"
)
);
ALGOLIA_APPLICATION_REGION with your Algolia application’s analytics region: us for the United States or eu for Europe.
You can check your analytics region in the Infrastructure > Analytics section of the Algolia dashboard.The Query Suggestions API client is part of the To use the Query Suggestions API client, add this import to your files:To create an instance of the client:Make sure to use the region that matches your Algolia application’s analytics region:
algoliasearch-client-go package.
To install it, run:Report incorrect code
Copy
go get github.com/algolia/algoliasearch-client-go
Go
Report incorrect code
Copy
import suggestions "github.com/algolia/algoliasearch-client-go/v4/algolia/query-suggestions"
Go
Report incorrect code
Copy
client, err := suggestions.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", suggestions.US)
if err != nil {
// The client can fail to initialize if you pass an invalid parameter.
panic(err)
}
suggestions.US for the United States or suggestions.EU for Europe.
You can check your analytics region in the Infrastructure > Analytics section of the Algolia dashboard.The Query Suggestions API client is part of the or to your To use the Query Suggestions API client,
add these imports to your files:To create an instance of the client:Replace
algoliasearch package.
You can add this package to your pom.xml file for Maven:pom.xml
Report incorrect code
Copy
<dependency>
<groupId>com.algolia</groupId>
<artifactId>algoliasearch</artifactId>
<version>4.25.0</version>
</dependency>
build.gradle file for Gradle:build.gradle
Report incorrect code
Copy
implementation 'com.algolia:algoliasearch:4.25.0'
Java
Report incorrect code
Copy
import com.algolia.api.QuerySuggestionsClient;
import com.algolia.config.*;
Java
Report incorrect code
Copy
QuerySuggestionsClient client = new QuerySuggestionsClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION");
ALGOLIA_APPLICATION_REGION with your Algolia application’s analytics region: us for the United States or eu for Europe.
You can check your analytics region in the Infrastructure > Analytics section of the Algolia dashboard.The Query Suggestions API client is part of the To use this client, run:Replace
@algolia/client-query-suggestions package.
To install it, run:Report incorrect code
Copy
npm install @algolia/client-query-suggestions
JavaScript
Report incorrect code
Copy
import { querySuggestionsClient } from "@algolia/client-query-suggestions";
const client = querySuggestionsClient(
"ALGOLIA_APPLICATION_ID",
"ALGOLIA_API_KEY",
"ALGOLIA_APPLICATION_REGION",
);
ALGOLIA_APPLICATION_REGION with your Algolia application’s analytics region: us for the United States or eu for Europe.
You can check your analytics region in the Infrastructure > Analytics section of the Algolia dashboard.The Query Suggestions API client is part of the To use the Query Suggestions API client, add this import to your files:To create an instance of the client:Replace
algoliasearch-kotlin package.
You can add this package to your build.gradle.kts file:build.gradle.kts
Report incorrect code
Copy
implementation("com.algolia:algoliasearch-client-kotlin:3.28.0")
// You also need to add a KTOR engine as dependency, for example:
implementation("io.ktor:ktor-client-java:$ktor_version")
Kotlin
Report incorrect code
Copy
import com.algolia.client.api.QuerySuggestionsClient
import com.algolia.client.configuration.*
import com.algolia.client.transport.*
Kotlin
Report incorrect code
Copy
val client = QuerySuggestionsClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY", region = "ALGOLIA_APPLICATION_REGION")
ALGOLIA_APPLICATION_REGION with your Algolia application’s analytics region: us for the United States or eu for Europe.
You can check your analytics region in the Infrastructure > Analytics section of the Algolia dashboard.The Query Suggestions API client is part of the To use the Query Suggestions API client, add this import to your files:To create an instance of the client:Replace
algoliasearch-client-php package.
To install this package, run:Report incorrect code
Copy
composer require algolia/algoliasearch-client-php
PHP
Report incorrect code
Copy
use Algolia\AlgoliaSearch\Api\QuerySuggestionsClient;
PHP
Report incorrect code
Copy
$client = QuerySuggestionsClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY', 'ALGOLIA_APPLICATION_REGION');
ALGOLIA_APPLICATION_REGION with your Algolia application’s analytics region: us for the United States or eu for Europe.
You can check your analytics region in the Infrastructure > Analytics section of the Algolia dashboard.The Query Suggestions API client is part of the To use the Query Suggestions API client, add this import to your files:To create an instance of the client:Replace The client supports the The method names are the same for synchronous and asynchronous methods.
algoliasearch package.
You can install this package with pip:Report incorrect code
Copy
pip install 'algoliasearch>=4,<5'
Python
Report incorrect code
Copy
from algoliasearch.query_suggestions.client import QuerySuggestionsClientSync
from json import loads
Python
Report incorrect code
Copy
# In an asynchronous context, you can use QuerySuggestionsClient instead, which exposes the exact same methods.
client = QuerySuggestionsClientSync(
"ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION"
)
ALGOLIA_APPLICATION_REGION with your Algolia application’s analytics region: us for the United States or eu for Europe.
You can check your analytics region in the Infrastructure > Analytics section of the Algolia dashboard.Async code
To use the Query Suggestions client in async environments, add these imports instead:Python
Report incorrect code
Copy
import asyncio
from algoliasearch.query_suggestions.client import QuerySuggestionsClient
async with statement to automatically close open connections.Python
Report incorrect code
Copy
async def run():
async with QuerySuggestionsClient(ALGOLIA_APPLICATION_ID, ALGOLIA_API_KEY) as client:
# client.search(...)
The Query Suggestions API client is part of the To use the Query Suggestions API client,
add this import to your files:To create an instance of the client:Replace
algolia gem.
To install this gem, run:Report incorrect code
Copy
gem install algolia
Ruby
Report incorrect code
Copy
require "algolia"
Ruby
Report incorrect code
Copy
client = Algolia::QuerySuggestionsClient.create(
"ALGOLIA_APPLICATION_ID",
"ALGOLIA_API_KEY",
"ALGOLIA_APPLICATION_REGION"
)
ALGOLIA_APPLICATION_REGION with your Algolia application’s analytics region: us for the United States or eu for Europe.
You can check your analytics region in the Infrastructure > Analytics section of the Algolia dashboard.The Query Suggestions API client is part of the To use the Query Suggestions API client, add these imports to your files:To create an instance of the client:Replace
algoliasearch-scala package.
You can add this package to your build.sbt file:build.sbt
Report incorrect code
Copy
// For Scala 3:
libraryDependencies += "com.algolia" %% "algoliasearch-scala_3" % "2.27.0"
// For Scala 2:
libraryDependencies += "com.algolia" %% "algoliasearch-scala_2" % "2.27.0"
Scala
Report incorrect code
Copy
import algoliasearch.api.QuerySuggestionsClient
import algoliasearch.config.*
Scala
Report incorrect code
Copy
val client = QuerySuggestionsClient(
appId = "ALGOLIA_APPLICATION_ID",
apiKey = "ALGOLIA_API_KEY",
region = "ALGOLIA_APPLICATION_REGION"
)
ALGOLIA_APPLICATION_REGION with your Algolia application’s analytics region: us for the United States or eu for Europe.
You can check your analytics region in the Infrastructure > Analytics section of the Algolia dashboard.The Query Suggestions API client is part of the To use the Query Suggestions API client, add this import to your files:To create an instance of the client:Make sure to use the region that matches your Algolia application’s analytics region:
algoliasearch-client-swift package.
You can add this package to your Package.swift file:Package.swift
Report incorrect code
Copy
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Algolia API clients",
platforms: [
.macOS(.v11)
],
dependencies: [
.package(
url: "https://github.com/algolia/algoliasearch-client-swift.git", from: "9.28.0")
],
targets: [
.executableTarget(
name: "Algolia API clients",
dependencies: [
.product(name: "QuerySuggestions", package: "algoliasearch-client-swift")
]
)
]
)
Swift
Report incorrect code
Copy
import QuerySuggestions
Swift
Report incorrect code
Copy
let client = try QuerySuggestionsClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY", region: .us)
region.us for the United States and region.eu for Europe.
You can check your analytics region in the Infrastructure > Analytics section of the Algolia dashboard.