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 function value


Imagine that you would like to group results not by using queries or field contents, but instead you would like to use a value returned by a function query. An example use case can be grouping documents on the basis of their distance from a point. Sounds nice right? Solr allows that and in this recipe, we will see how we can use a simple function query to group results.

Getting ready

In this recipe, we will use the knowledge that we've gained in the Grouping documents by the field value recipe in this chapter. Read the mentioned recipe before we continue.

How to do it...

  1. Let's start with the following index structure (just add the following fields definition to your 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="geo" type="location" indexed="true" stored="true" />
    <dynamicField name="*_coordinate"  type...