Facet Searching
For an introduction to Facet Searching, see this post
Overview
Faceted Search can be achieved by using the GetTopFieldValues
and Filters
parameters of a Search Request.
Getting the Top Field Values
Use GetTopFieldValues
to retrieve field values appearing in the search request, sorted most to least occurring.
Note that only Enumerable Fields can be retrieved using this method.
Parameters
Fields
(Optional) - Restrict search request to specified fields only. By default, retrieves all enumerable fields.MaxValues
(Optional, default 10) - The maximum number of field values to retrieve, per field.
Example (Excerpt from a search request):
{
"Parameters": {
"Query": "vehicle",
"Page": 1,
"GetTopFieldValues": {
"Fields": [
"Brand",
"Fuel"
]
}
}
}
The search request response will contain an array of TopFieldValues
{
"DocCount": 70,
"Errors": [],
"Hits": 122,
"Results": [
...
],
"TopFieldValues": [
{
"Field": "Brand",
"Values": [
{
"Value": "Ford",
"Count": 48
},
{
"Value": "Mercedes Benz",
"Count": 22
}
]
},
{
"Field": "Fuel",
"Values": [
{
"Value": "Diesel",
"Count": 50
},
{
"Value": "Hybrid",
"Count": 15
},
{
"Value": "Electric",
"Count": 5
}
]
}
]
}
Field
- The name of the Enumerable FieldValues
- An array of the most common values for this field.Value
- The field valueCount
- In how many documents the value occurs.
Using Field Filters
Use the Filters
parameter of a search request to filter on Field Values.
FieldValuesMatchAny
- Filter results to documents containing fields with any one of the values passedField
- The name of the field to matchValues
- An array of acceptable values
Example (Excerpt from a search request):
{
"Parameters": {
"Query": "vehicle",
"Page": 1,
"Filters": {
"FieldValuesMatchAny": [
{
"Field": "Brand",
"Values": [
"Mercedes Benz"
]
},
{
"Field": "Fuel",
"Values": [
"Hybrid",
"Electric"
]
}
]
}
}
}
The above request would search for ‘vehicle’ and retrieve all Mercedes Benz that are Hybrid or Electric.
Note:
FieldValuesMatchAny
is a convenience parameter only.
It is possible to achieve the same results using the equivalent Field Search Query:
vehicle and (("Brand" contains "Mercedes Benz") and ("Fuel" contains ("Hybrid" or "Electric")))