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" ...

Get Solr Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.