concept group in category solr

appears as: group, groups, group, groups
Solr in Action

This is an excerpt from Manning's book Solr in Action.

Although Solr requires a flat, denormalized document, Solr allows you to treat multiple documents as a group based on some common property shared by all documents in the group. Result grouping, also referred to as field collapsing, allows you to return unique groups instead of individual documents in the results.

In addition to collapsing search results to remove duplicate documents, the result grouping functionality in Solr provides other useful features. In many ways, you can view result grouping in Solr as a more verbose form of faceting. Instead of only returning separate facet sections along with the counts for each value, result grouping returns the unique values and their counts (like faceting) plus some number of documents that contain each of the specified values. One way in which grouping is different than faceting is that it returns the requested groups within the search results section, which means the groups and values within the groups are sorted based on the sorts specified for the documents in the query. Grouping can be performed based upon field values, functions, or queries, making its applications numerous. Although this may sound complex initially, we will cover several use cases to demonstrate this incredibly useful and (mostly) straightforward feature. Before jumping in, it will be useful to clarify the sometimes confusing distinction between the terms result grouping and field collapsing.

Figure 11.2. Returning multiple documents per group by setting group.limit > 1.

The example documents that were indexed in listing 11.1 contain a type field that we can group upon, requesting a limit of three documents per group. Additionally, let’s request that a maximum of five total groups be returned. This listing demonstrates such a query.

Listing 11.6. Returning multiple values per group