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

Configuring numerical fields for high-performance sorting and range queries


Let's assume we have Apache Solr deployment where we use range queries. Some of those are run against string fields, while others are run against numerical fields. We identified that our numerical range queries are executing slower than we would like them to run. The usual question arises—is there something that we can do? Of course there is, and this recipe will show you what.

How to do it...

  1. Let's begin with the definition of a field that we use to run our numerical range queries (we add it to the schema.xml file):

    <field name="price" type="float" indexed="true" stored="true"/>
  2. The second step is to define the float field type (again, we add this to the schema.xml file):

    <fieldType name="float" class="solr.TrieFloatField" precisionStep="8" />
  3. And now the usual query that is run against the preceding field:

    q=*:*&fq=price:[10.0+TO+59.00]&facet=true&facet.field=price
  4. In order to have your numerical...