browse
This helper method iterates over the paginated API response from the Browse API operation
and lets you run an aggregator function on every iteration.
You can use this, for example, to retrieve all records from your index.
Usage
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;
var appID = "ALGOLIA_APPLICATION_ID";
var apiKey = "ALGOLIA_API_KEY";
var client = new SearchClient(appID, apiKey);
var results = await client.BrowseObjectsAsync<Hit>("ALGOLIA_INDEX_NAME", new BrowseParamsObject { Query = "test" });
results.ToList().ForEach(record => Console.WriteLine($" - Record: {record.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 records []search.Hit
err = client.BrowseObjects(
indexName,
*search.NewBrowseParamsObject().SetQuery("test"),
search.WithAggregator(func(r any, err error) {
if err != nil {
log.Fatalf("There was an error: %v", err)
}
records = append(records, r.(*search.BrowseResponse).Hits...)
}),
)
if err != nil {
log.Println(err)
}
for _, record := range records {
fmt.Printf("- Record: %s\n", record.ObjectID)
}
}
package org.example;
import com.algolia.api.SearchClient;
import com.algolia.model.search.BrowseParamsObject;
import com.algolia.model.search.Hit;
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.browseObjects(indexName, new BrowseParamsObject().setQuery("test"), Hit.class);
for (var record : response) {
System.out.println("- Record: " + record.getObjectID());
}
client.close();
}
}
import { algoliasearch as searchClient } from "algoliasearch";
const appId = "GRQS7LW2HJ";
const apiKey = "3b631dd673ec758c4b280e6b230de56f";
const indexName = "movies";
const client = searchClient(appId, apiKey);
let records = [];
await client.browseObjects({
indexName,
aggregator: (res) => {
records.push(...res.hits);
},
browseParams: {
query: "test",
},
});
records.forEach((record) => console.log(`- Record: ${record.objectID}`));
package org.example
import com.algolia.client.api.SearchClient
import com.algolia.client.extensions.browseObjects
import com.algolia.client.model.search.BrowseParamsObject
import com.algolia.client.model.search.BrowseResponse
import com.algolia.client.model.search.Hit
suspend fun main() {
val appID = "ALGOLIA_APPLICATION_ID"
val apiKey = "ALGOLIA_API_KEY"
val indexName = "ALGOLIA_INDEX_NAME"
val client = SearchClient(appID, apiKey)
val records = mutableListOf<Hit>()
client.browseObjects(
indexName = indexName,
params = BrowseParamsObject("test"),
aggregator = { res: BrowseResponse -> records.addAll(res.hits) })
records.forEach { record -> println("- Record: ${record.objectID}") }
}
<?php
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->browseObjects($indexName);
$records = [];
foreach ($res as $object) {
$records[] = $object;
}
foreach ($records as $record) {
echo '- Record ' . $record['objectID'] . "\n";
}
from algoliasearch.search.client import SearchClientSync
app_id = "ALGOLIA_APPLICATION_ID"
api_key = "ALGOLIA_API_KEY"
index_name = "ALGOLIA_INDEX_NAME"
client = SearchClientSync(app_id, api_key)
records = []
_ = client.browse_objects(
index_name=index_name,
aggregator=lambda res: records.extend(res.hits),
browse_params={"query": "test"},
)
for record in records:
print(f"- Record: {record.object_id}")
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)
records = client.browse_objects(index_name, { query: "test" })
records.each { |record| puts "- Record: #{record.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 records: [Hit] = []
func aggregate(resp: BrowseResponse<Hit>) {
records.append(contentsOf: resp.hits)
}
try await client.browseObjects(
indexName: indexName,
browseParams: BrowseParamsObject(query: "test"),
aggregator: aggregate
)
for record in records {
print("- Record: \(record.objectID)")
}
Parameters
- C#
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
string
required
Index name from which to retrieve the records.
BrowseParamsObject
required
Parameters for the Browse for records request.
typeparam
The model for your records, for example,
Algolia.Search.Models.Search.Hit.RequestOptions
Additional request options.
string
required
Index name from which to retrieve the records.
BrowseParamsObject
required
Parameters for the Browse for records 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 records 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,
BrowseObjects 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 records.
BrowseParamsObject
required
Parameters for the Browse for records request.
Class<T>
required
The model for your records, for example,
com.algolia.model.search.Hit.RequestOptions
Additional request options.
string
required
Index name from which to retrieve the records.
function
required
Signature:
(BrowseResponse) => voidA function that runs on every iteration,
for example, to aggregate all records from the response.BrowseParams
Parameters for the Browse for records request.
function
Signature:
(BrowseResponse) => boolA function that returns true when the iteration should stop.
By default, the iteration stops if the API response doesn’t contain a cursor property.RequestOptions
Additional request options.
String
required
Index name from which to retrieve the records.
BrowseParamsObject
required
Parameters for the Browse for records request.
function
required
Signature:
(BrowseResponse) -> UnitA function that runs on every iteration, for example,
to aggregate all records from the response.function
Signature:
(BrowseResponse) -> 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 records.
array
Additional request options.
str
required
Index name from which to retrieve the records.
function
required
Signature:
(BrowseResponse) -> NoneA function that runs on every iteration,
for example, to aggregate all records from the response.BrowseParamsObject | None
Parameters for the Browse for records request.
RequestOptions
Additional request options.
String
required
Index name from which to retrieve the records.
BrowseParamsObject
Parameters for the Browse for records request.
Hash
Additional request options.
String
required
Index name from which to retrieve the records.
BrowseParamsObject
required
Parameters for the Browse for records request.
function
required
Signature:
BrowseResponse => UnitA function that runs on every iteration, for example,
to aggregate all records from the response.T is your record model’s type.function
Signature:
BrowseResponse => 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.T is your record model’s type.RequestOptions
Additional request options.
String
required
Index name from which to retrieve the records.
BrowseParamsObject
required
Parameters for the Browse for records request.
function
required
Signature:
(BrowseResponse<T>) -> VoidA function that runs on every iteration, for example,
to aggregate all records from the response.T is your record model’s type.function
Signature:
(BrowseResponse<T>) -> 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.T is your record model’s type.RequestOptions
Additional request options.