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

Getting the number of documents matching the query and subquery


Imagine a situation where you have an application that has a search feature for cars. One of the requirements is not only to show the search results, but also to show the number of cars with the price period chosen by the user. There is also another thing—these queries must be fast because of the number of queries that will be running. Can Solr handle this? The answer is yes. This recipe will show you how to do it.

How to do it...

Let's start with creating an index with a very simple index structure that looks as follows:

  1. Add the following definition to your schema.xml:

    <field name="id" type="string" indexed="true" stored="true" required="true" />
    <field name="name" type="text_general" indexed="true" stored="true" />
    <field name="price" type="float" indexed="true" stored="true" />
  2. Now, let's index the following sample data:

    <add>
     <doc>
      <field name="id">1</field>
      <field name="name"...