settings
This helper method iterates over the paginated API response from the
Search for synonyms API operation
and lets you run an aggregator function on every iteration.
You can use this, for example, to retrieve all synonyms from your index.
Usage
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;
var appID = "ALGOLIA_APPLICATION_ID";
var apiKey = "ALGOLIA_API_KEY";
var indexName = "ALGOLIA_INDEX_NAME";
var client = new SearchClient(appID, apiKey);
var results = await client.BrowseSynonymsAsync(indexName, new SearchSynonymsParams {});
results.ToList().ForEach(synonym => Console.WriteLine($" - Synonym: {synonym.ObjectID}"));
package main
import (
"fmt"
"log"
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
func main() {
appID := "ALGOLIA_APPLICATION_ID"
apiKey := "ALGOLIA_API_KEY"
indexName := "ALGOLIA_INDEX_NAME"
client, err := search.NewClient(appID, apiKey)
if err != nil {
log.Fatalln(err)
}
var synonyms []search.SynonymHit
err = client.BrowseSynonyms(
indexName,
*search.NewEmptySearchSynonymsParams(),
search.WithAggregator(func(r any, err error) {
if err != nil {
log.Fatalf("There was an error: %v", err)
}
synonyms = append(synonyms, r.(*search.SearchSynonymsResponse).Hits...)
}),
)
if err != nil {
log.Fatal(err)
}
for _, synonym := range synonyms {
fmt.Printf("- Synonym: %s\n", synonym.ObjectID)
}
}
package org.example;
import com.algolia.api.SearchClient;
import com.algolia.model.search.SearchSynonymsParams;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
var appID = "ALGOLIA_APPLICATION_ID";
var apiKey = "ALGOLIA_API_KEY";
var indexName = "ALGOLIA_INDEX_NAME";
var client = new SearchClient(appID, apiKey);
var response = client.browseSynonyms(indexName, new SearchSynonymsParams());
for (var synonym : response) {
System.out.println("Synonym: " + synonym.getObjectID());
}
client.close();
}
}
import { algoliasearch as searchClient } from "algoliasearch";
const appId = "ALGOLIA_APPLICATION_ID";
const apiKey = "ALGOLIA_API_KEY";
const indexName = "ALGOLIA_INDEX_NAME";
const client = searchClient(appId, apiKey);
let synonyms = [];
await client.browseSynonyms({
indexName,
aggregator: (res) => {
synonyms.push(...res.hits);
},
});
synonyms.forEach((synonym) => console.log(`- Synonym: ${synonym.objectID}`))
package org.example
import com.algolia.client.api.SearchClient
import com.algolia.client.extensions.browseSynonyms
import com.algolia.client.model.search.SearchSynonymsParams
import com.algolia.client.model.search.SearchSynonymsResponse
import com.algolia.client.model.search.SynonymHit
suspend fun main() {
val appID = "ALGOLIA_APPLICATION_ID"
val apiKey = "ALGOLIA_API_KEY"
val indexName = "ALGOLIA_INDEX_NAME"
val client = SearchClient(appID, apiKey)
val synonyms = mutableListOf<SynonymHit>()
client.browseSynonyms(
indexName = indexName,
searchSynonymsParams = SearchSynonymsParams(),
aggregator = { res: SearchSynonymsResponse -> synonyms.addAll(res.hits) })
synonyms.forEach { synonym -> println("- Synonym: ${synonym.objectID}") }
}
<?php
ini_set('memory_limit', '512M');
require_once realpath(__DIR__.'/vendor/autoload.php');
use Algolia\AlgoliaSearch\Api\SearchClient;
$appID = 'ALGOLIA_APPLICATION_ID';
$apiKey = 'ALGOLIA_API_KEY';
$indexName = 'ALGOLIA_INDEX_NAME';
$client = SearchClient::create(appId: $appID, apiKey: $apiKey);
$res = $client->browseSynonyms($indexName);
$synonyms = [];
foreach ($res as $synonym) {
$synonyms[] = $synonym;
}
foreach ($synonyms as $synonym) {
echo '- Synonym ' . $synonym['objectID'] . "\n";
}
from algoliasearch.search.client import SearchClientSync
from algoliasearch.search.models import SearchSynonymsResponse, SynonymHit
app_id = "ALGOLIA_APPLICATION_ID"
api_key = "ALGOLIA_API_KEY"
index_name = "ALGOLIA_INDEX_NAME"
client = SearchClientSync(app_id, api_key)
synonyms = []
_ = client.browse_synonyms(
index_name=index_name, aggregator=lambda res: synonyms.extend(res.hits)
)
for synonym in synonyms:
print(f"- Synonym: {synonym.object_id}")
# frozen_string_literal: true
require "algolia"
app_id = "ALGOLIA_APPLICATION_ID"
api_key = "ALGOLIA_API_KEY"
index_name = "ALGOLIA_INDEX_NAME"
client = Algolia::SearchClient.create(app_id, api_key)
synonyms = client.browse_synonyms(index_name)
synonyms.each { |synonym| puts "- Synonym: #{synonym.algolia_object_id}" }
import Foundation
import Search
let appID = "ALGOLIA_APPLICATION_ID"
let apiKey = "ALGOLIA_API_KEY"
let indexName = "ALGOLIA_INDEX_NAME"
let client = try SearchClient(appID: appID, apiKey: apiKey)
var synonyms: [SynonymHit] = []
func aggregate(resp: SearchSynonymsResponse) {
synonyms.append(contentsOf: resp.hits)
}
try await client.browseSynonyms(
indexName: indexName,
searchSynonymsParams: SearchSynonymsParams(),
aggregator: aggregate
)
for synonym in synonyms {
print("- Synonym: \(synonym.objectID)")
}
Parameters
- C#
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
string
required
Index name from which to retrieve the synonyms.
SearchSynonymsParams
required
Parameters for the Search for synonyms request.
RequestOptions
Additional request options.
string
required
Index name from which to retrieve the synonyms.
SearchSynonymsParams
required
Parameters for the Search for synonyms request.
IterableOptions
Functional options to provide extra arguments.
Show available functions
Show available functions
function
Signature:
func(aggregator func(any, error)) iterableOptionProvides a function that runs on every iteration,
for example, to aggregate all synonyms from the response.function
Signature:
func(maxRetries int) iterableOptionSets the maximum number of iterations for this method.
For example, with search.WithMaxRetries(1)
this method stops after the first request.
By default,
BrowseSynoyms iterates through all pages of the API response.function
Signature:
func(timeout func(count int) time.Duration) iterableOptionProvides a function for calculating the waiting time between requests.
The timeout function accepts the iteration count as parameter.
This lets you implement varying timeouts.function
Signature:
func(key string, value string) requestOptionSets extra header parameters for this request.
To learn more, see Request options.function
Signature:
func(key string, value string) requestOptionSets extra query parameters for this request.
To learn more, see Request options.String
required
Index name from which to retrieve the synonyms.
SearchSynonymsParams
required
Parameters for the Search for synonyms request.
RequestOptions
Additional request options.
string
required
Index name from which to retrieve the synonyms.
function
required
Signature:
(SearchSynonymsResponse) => voidA function that runs on every iteration,
for example, to aggregate all synonyms from the response.SearchSynonymsParams
Parameters for the Search for synonyms request.
function
Signature:
(SearchSynonymsResponse) => boolA function that returns true when the iteration should stop.
By default, the iteration stops if the API response returns fewer than hitsPerPage hits.RequestOptions
Additional request options.
String
required
Index name from which to retrieve the synonyms.
SearchSynonymsParams
required
Parameters for the Search for synonyms request.
function
required
Signature:
(SearchSynonymsResponse) -> UnitA function that runs on every iteration, for example,
to aggregate all synonyms from the response.function
Signature:
(SearchSynonymsResponse) -> BooleanA function that returns true when the iteration should stop.
By default, the iteration stops if the API response returns fewer than hitsPerPage hits.RequestOptions
Additional request options.
string
required
Index name from which to retrieve the synonyms.
array
Additional request options.
str
required
Index name from which to retrieve the synonyms.
function
required
Signature:
(SearchSynonymsResponse) -> NoneA function that runs on every iteration,
for example, to aggregate all synonyms from the response.SearchSynonymsParams | None
Parameters for the Search for synonyms request.
RequestOptions
Additional request options.
String
required
Index name from which to retrieve the synonyms.
SearchSynonymsParams
Parameters for the Search for synonyms request.
Hash
Additional request options.
String
required
Index name from which to retrieve the synonyms.
SearchSynonymsParams
required
Parameters for the Search for synonyms request.
function
required
Signature:
SearchSynonymsResponse => UnitA function that runs on every iteration, for example,
to aggregate all records from the response.function
Signature:
SearchSynonymsResponse => BooleanA function that returns true when the iteration should stop.
By default, the iteration stops if the API response doesn’t contain a cursor field.RequestOptions
Additional request options.
String
required
Index name from which to retrieve the synonyms.
SearchSynonymsParams
required
Parameters for the Search for synonyms request.
function
required
Signature:
(SearchSynonymsResponse) -> VoidA function that runs on every iteration, for example,
to aggregate all records from the response.function
Signature:
(SearchSynonymsResponse) -> BoolA function that returns true when the iteration should stop.
By default, the iteration stops if the API response doesn’t contain a cursor field.RequestOptions
Additional request options.