Imagine a situation where your data set is divided into different categories, subcategories, price ranges, and things like that. What if you would like to not only get information about counts in such a group (with the use of faceting), but would also like to show the most relevant documents in each of the groups? Is there a grouping mechanism of some kind in Solr? Yes there is, and this recipe will show you how to use this functionality in order to divide documents into groups on the basis of field values.
Let's start with the index structure. Let's assume that we have the following fields in our index (just add this to the
schema.xml
file to thefield
section):<field name="id" type="string" indexed="true" stored="true" required="true" /> <field name="name" type="text" indexed="true" stored="true" /> <field name="category" type="string" indexed="true" stored="true" /> <field name="price" type="tfloat" indexed="true...