Book Image

Solr Cookbook - Third Edition

By : Rafal Kuc
Book Image

Solr Cookbook - Third Edition

By: Rafal Kuc

Overview of this book

Table of Contents (18 chapters)
Solr Cookbook Third Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Grouping documents by the field value


Imagine a situation where your dataset 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 groups (with the use of faceting), but you would only like to show the most relevant document in each of the groups. In such cases, a Solr grouping mechanism comes in handy. This recipe will show you how to group your documents on the basis of the value of the field.

How to do it...

  1. Let's start with the index structure. Let's assume that we have the following fields in our index (just add the following section to the schema.xml file):

    <field name="id" type="string" indexed="true" stored="true" required="true" />
    <field name="name" type="text_general" indexed="true" stored="true" />
    <field name="category" type="string" indexed="true" stored="true" />
    <field name="price" type="tfloat" indexed="true" stored="true" />
  2. The example data, which...