Retrieving facets
To retrieve facets and their respective counts as part of the JSON response, you must specify a list of facets in the facets parameter at query time.
For example, you can retrieve your books' facets with the search
method, and the facets
parameter.
When the
facets
parameter is empty, the engine returns no facet information.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Scala
await client.search({
requests: [
{
indexName: '<YOUR_INDEX_NAME>',
query: '<YOUR_QUERY>',
facets: ['author', 'genre'],
},
],
});
To extract all facet information, you can use a wildcard (*
).
await client.search({
requests: [
{
indexName: '<YOUR_INDEX_NAME>',
query: '<YOUR_QUERY>',
facets: ['*'],
},
],
});
$client->search([
'requests' => [
[
'indexName' => '<YOUR_INDEX_NAME>',
'query' => '<YOUR_QUERY>',
'facets' => ['author', 'genre'],
],
],
]);
To extract all facet information, you can use a wildcard (*
).
$client->search([
'requests' => [
[
'indexName' => '<YOUR_INDEX_NAME>',
'query' => '<YOUR_QUERY>',
'facets' => ['*'],
],
],
]);
import com.algolia.model.search.*;
client.search(
new SearchMethodParams()
.addRequests(
new SearchForHits()
.setIndexName("<YOUR_INDEX_NAME>")
.setQuery("<YOUR_QUERY>")
.addFacets("author")
.addFacets("genre")
)
);
To extract all facet information, you can use a wildcard (*
).
import com.algolia.model.search.*;
client.search(
new SearchMethodParams()
.addRequests(
new SearchForHits()
.setIndexName("<YOUR_INDEX_NAME>")
.setQuery("<YOUR_QUERY>")
.addFacets("*")
)
);
import com.algolia.model.search.*;
client.search(
searchMethodParams = SearchMethodParams(
requests = listOf(
SearchForHits(
indexName = "<YOUR_INDEX_NAME>",
query = "<YOUR_QUERY>",
facets = listOf("author", "genre"),
)
)
)
)
To extract all facet information, you can use a wildcard (*
).
import com.algolia.model.search.*;
client.search(
searchMethodParams = SearchMethodParams(
requests = listOf(
SearchForHits(
indexName = "<YOUR_INDEX_NAME>",
query = "<YOUR_QUERY>",
facets = listOf("*"),
)
)
)
)
await client.search(
searchMethodParams: SearchMethodParams(
requests: [
SearchForHits(
indexName: "<YOUR_INDEX_NAME>",
query: "<YOUR_QUERY>",
facets: ["author", "genre"],
),
],
),
);
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
indexName := "<INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"
searchClient, _ := search.NewClient(appID, apiKey)
results, err := searchClient.Search(
searchClient.NewApiSearchRequest(
search.NewSearchMethodParams(
[]search.SearchQuery{
search.SearchForHitsAsSearchQuery(
search.NewSearchForHits(
indexName,
search.WithSearchForHitsFacets([]string{"author", "genre"}),
),
),
},
),
),
)
if err != nil {
panic(err)
}
To extract all facet information, you can use a wildcard (*
).
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
indexName := "<INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"
searchClient, _ := search.NewClient(appID, apiKey)
results, err := searchClient.Search(
searchClient.NewApiSearchRequest(
search.NewSearchMethodParams(
[]search.SearchQuery{
search.SearchForHitsAsSearchQuery(
search.NewSearchForHits(
indexName,
search.WithSearchForHitsFacets([]string{"*"}),
),
),
},
),
),
)
if err != nil {
panic(err)
}