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:
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" />
Now, let's index the following sample data:
<add> <doc> <field name="id">1</field> <field name="name"...