# GroupBy Request
# Description
A groupBy request will take a special kind of IndexName configured within the Indexes config under a GroupBys tag which creates the ability to group items by whichever aspects are configured within that GroupBys section, for example, Genre and Author to be grouped together. It will display the details of the max and minimum item in the ranges specified, as well as the count of items that match that groupBy. These can be sorted by a specific order as well e.g. max price descending.
# Benefits of a Group By Request
Group By can be used to present results to the user when those results have to be grouped by more than one aspect. For example, if you were looking to buy a book, group by could be used to group all the books by their genre as well as displaying their maximum and minimum price by putting parameter price in the ranges section.
# Syntax
?groupby=IndexName|Ranges|OrderBys|Skip|Limit
# Attributes
Note: all attributes marked with * are required.
- IndexName*
- The GroupBy item that is configured within the indexes config and is the main section of the syntax, determining what the results will be grouped by.
- Ranges
- The list of ranges that you wish to display the min and max for in the result separated by a ",".
- OrderBys*
- The specific way in which the results are ordered by, for example, they can be ordered by max price descending so the highest max price is shown first.
- Skip
- The number of items to skip in the list, defaults to 0 items. Can be used for pagination.
- Limit
- The number of items that will be displayed, defaults to show all
# Example One
# Code
groupby=GenreAuthorGroup|Price|~Range.Price.Max|1|23
The following is a part of the result produced by the above code.
{
"GroupBy":{
"Groups":[
{
"Values":{
"Genre":"Horror",
"Author":"Junji Ito",
},
"Ranges":{
"Price":{
"Min":30,
"Max":50,
}
},
"Count":3,
"SelectedCount":3,
},
{
"Values":{
"Genre":"Fantasy",
"Author":"Chris D' Lacey",
},
"Ranges":{
"Price":{
"Min":10,
"Max":15,
}
},
"Count":15,
"SelectedCount":15,
},
As it shows the results are grouped by the values Genre and Author stated within the GenreAuthorGroup IndexName, items are also displayed with the max and min price of the items it has grouped and sorts those items from the highest to lowest max price, skipping the first item and only showing 23.
# Example Two
# Code
groupby=GenreAuthorGroup|Price,Year,PhotoCount|~Range.PhotoCount.Max|0|15
The following is one of the results produced by the above code.
{
"GroupBy":{
"Groups":[
{
"Values":{
"Genre":"Fantasy",
"Author":"J.K. Rowling",
},
"Ranges":{
"Price":{
"Min":10,
"Max":20,
},
"Year":{
"Min":1997,
"Max":2007,
},
"PhotoCount":{
"Min":1,
"Max":5,
}
},
"Count":7,
"SelectedCount":7,
},
{
"Values":{
"Genre":"Biography",
"Author":"Jack Stratton",
},
"Ranges":{
"Price":{
"Min":250000,
"Max":250000,
},
"Year":{
"Min":2017,
"Max":2017,
},
"PhotoCount":{
"Min":1,
"Max":1,
}
},
"Count":1,
"SelectedCount":1,
}
In this example, it is still grouped by the same two aspects however this time Price, Year, and PhotoCount are all shown with max and min values and the items are sorted by the number of photos they have in descending order. No items are skipped and 15 are shown.
