The main purpose of grouping is to remove duplicates so search results are easier for users to read.
With grouping, your results only retains a hit (or N hits) for each group. The particular hit that displays for each group is determined by how you sort the hits within the group. Within these groups, you can nest additional grouping clauses.
Important: As with other search-time manipulations like facets and sorting, you can only define group or group sorting expressions on fields that are stored in RAM.
While grouping in Exalead CloudView works similar to the SQL GroupBy in that you can use multiple clauses and create aggregations, keep in mind that it is not identical to database grouping.
For search results, the ultimate purpose to collapse several hits into one (or several) "representative" hit. The following examples demonstrate how grouping works.
Simple Grouping Example
Say that you are sporting gear retailer. Spring is coming and you want to find out what kind of bike merchandise you have in stock.
Without using any grouping, here are the results for a query on bike:
Hit rank in results
Name
Quantity
Warehouse distance (km)
1
Bike
10
100
2
Bike helmet
100
1
3
Bike seat
50
12
4
Bike shoes
20
28
5
Biking jersey
500
5
You want to reduce this list by grouping the results on which the quantity is higher than 50. To do so, define a group where quantity > 50.
How Many Search Results Do You Have?
Two, because defining a group creates 2 groups:
• More than 50: Bike helmet, Biking jersey
• 50 or fewer (the "other" group): Bike, Bike seat, Bike shoes.
Which hits Do Display for the Group?
This is defined by:
• The number of hits to represent the group. Let us keep the default, 1. This means that 2 hits are displayed in the search results, one for each group.
• The sorting expression for the group. In our example, you want to know what's close by, so let us sort on the distance field in ascending order. This means the hit with the lowest distance value in the group represents the group.
In the grouped search results, this returns:
• One hit from More than 50, Biking helmet (because distance = 1 km, less than for Biking jersey).
• One hit from 50 or fewer, Bike seat (because distance = 12 km, less than for Bike or Bike shoes).
Which Group Displays First in the Search Results?
The group sorting determines which hit represents the group. But ultimately it is the representative hit's relevance score before grouping that determines the group’s rank (display order) in the search results.
In this case, Bike seat ranked higher than Biking jersey before grouping. So the grouped results look like this:
Grouped hit rank
Name
Quantity
Warehouse distance (km)
1
Bike seat
50
1 km
2
Biking jersey
500
5 km
Multicriteria Grouping Example
You can add additional clauses to group on multiple criteria.
Without using any grouping, here are the results for your bike query, this time with country information.
Hit ranking
Name
Quantity
Warehouse distance (km)
Country
1
Bike
10
100
Germany
2
Bike helmet
100
1
France
3
Bike seat
50
12
Germany
4
Bike shoes
20
28
France
5
Biking jersey
500
5
France
In addition to grouping by quantity, you also want to group by country.
This means you now have three groups:
• More than 50 in France: Bike helmet, Biking jersey.
• 50 or fewer in France: Bike shoes
• 50 or fewer in Germany: Bike, Bike seat.
Still displaying only one hit from each group, and sorting in ascending order on distance, this will return three hits:
• Bike helmet from More than 50 in France
• Bike shoes from 50 or fewer in France
• Bike seat from 50 or fewer in Germany
Since CloudView ranks these "representative" hits to their initial rank before being grouped, the hits display in this order:
Grouped hit rank
Name
Quantity
Warehouse distance (km)
Country
1
Bike helmet
100
1
France
2
Bike seat
50
12
Germany
3
Bike shoes
20
28
France
Displaying an Aggregation Example
You can also calculate an aggregation for group and display it in the grouped hit. Note that the aggregation is based on all hits within the group, regardless how many hits display in the grouped hit.
Available aggregations:
• Sum
• Max
• Min
• Average
• Standard deviation
• Concatenation - this lists all the values for a field within the group. Unlike other aggregations, it needs an alphanumeric field.
Say that you want to display the total quantity in stock for all hits within a group. Let us go back to the simple grouping example with only two groups.
Group
Name
Quantity
More than 50
Biking jersey
500
Bike helmet
100
50 or fewer
Bike seat
50
Bike
10
Biking shoes
20
By creating a sum aggregation on the quantity field, you can display the aggregation in your grouped hit:
Grouped hit rank
Name
Quantity
Total quantity for group
1
Bike seat
50
80
2
Biking jersey
500
600
Setting Up Grouping
Add a Group
1. In the Administration Console, go to Search > Search Logics > Your search logic > Sort & Relevance.
2. Under Group, click Enable.
3. Define your grouping and sorting criteria by clicking Edit.
For our example, specify:
a. Group by: quantity > 50.
b. Sort hits in group by: distance.
When in the Expression builder, if you do not see the field that you want on the list of Index fields, it is because the field is not being stored in RAM. You need to enable that field's RAM-based option, apply your changes, then clear your build group & reindex.
4. (Optional) Specify an additional clause to your Group by expression by clicking Add clause.