Faceting
Engine Type | Supported? |
---|---|
Crawler-based Engine | YES |
API-based Engine | YES |
You can use faceting to give you a count of results for each value of a particular field.
- q
- required
- The query used within your search.
- engine_key
- required
- The Engine Key associated with your Engine. Found within your dashboard.
- facets
- optional
- Count the results of a given field within a DocumentType. As such, the
facet
parameter requires both a DocumentType and a field belonging to that DocumentType.
Example - Return a count of values within the
genre
field of the books
DocumentType: a book is either fiction
or non-fiction
. Crawler based Engines use page
as the default DocumentType.
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
-H 'Content-Type: application/json' \
-d '{
"engine_key": "YOUR_ENGINE_KEY",
"q": "brothers",
"facets":{
"books":["genre"]
}
}'
Example Response
{
"records": {
"books": [
{
"title": "The Brothers Karamazov",
"author": "Fyodor Dostoyevsky",
"price": "14.95"
},
...
]
},
"info": {
"books": {
"query": "brothers",
"current_page": 1,
"num_pages": 1,
"per_page": 20,
"total_result_count": 18,
"facets": {
"genre": {
"fiction": 11,
"non-fiction": 7
}
}
}
},
"errors": {}
}
Supported Field Types
Type | Faceting |
---|---|
string |
Yes |
text |
No |
enum |
Yes |
integer |
Yes |
float |
Yes |
date |
Yes |
location |
No |
Stuck? Looking for help? Contact support or check out the Site Search community forum!