scope search
type array of strings
default []
description

Facets to retrieve.

If not specified or empty, no facets are retrieved. The special value * may be used to retrieve all facets.

Facets must have been declared beforehand in the attributesForFaceting index setting.

For each of the retrieved facets, the response will contain a list of the most frequent facet values in objects matching the current query. Each value will be returned with its associated count (number of matched objects containing that value).

Faceting does not filter your results. If you want to filter results, you should use filters.

If the number of hits is high, facet counts may be approximate. The response field exhaustiveFacetsCount is true when the count is exact.

Examples

Only retrieve faceting data for some attributes

For this example, let’s consider that attributesForFaceting are set to: ["category", "author", "nb_views", "nb_downloads"] but, for the current search, you want to retrieve facet values only for category and author.

<?php
$results = $index->search('query', [
  'facets' => ['category', 'author']
]);
results = index.search('query', {
  facets: ['category', 'author']
})
index.search({
  query: 'query',
  facets: ['category', 'author']
}).then(res => {
  // console.log(res);
});
results = index.search('query', {
    'facets': ['category', 'author']
})
let query = Query(query: "query")
query.facets = ["category", "author"]

index.search(query, completionHandler: { (res, error) in
    print(res)
})
index.search(new Query("query").setFacets("category", "author"));
index.search(
  new Query("query").SetFacets(new string[] { "category", "author" })
);
index.search(
  new Query("query").setFacets(Arrays.asList(
    "category",
    "author"
  ))
);
res, err := index.Search("query", algoliasearch.Map{
    "facets": []string{
        "category",
        "author",
    },
})
client.execute {
  search into "myIndex" query Query(
    query = Some("query"),
    facets = Some(Seq(
      "category",
      "author"
    ))
  )
}
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala