Grouping
Orama supports groupBy
operations.
That allows you to group results in groups calculating an aggregation on the item that belongs to the same bucket.
By default, Orama doesn’t limit the number of items inside a group.
By default, Orama groups all the matched documents into an array.
Simple usage
If we consider the following schema:
We will be able to have the documents per design
ordered by rank
:
If you want only the top-ranked document per design
, you can specify the maxResult
:
The above query returns something like this:
You can group on multiple properties as follows:
Custom reducer
Orama supports custom aggregator as follows:
Where the accumulator function receives the following parameters:
- the value of the current groups
- the accumulator returned by the previous invocation
- the item to accumulate
The reducer is called for every item for every group.