Implementing the autocomplete functionality for categories

Sometimes, we are interested not in our product's name for autocomplete, but in something else. Imagine that we want to show the category of our products in the autocomplete box along with the number of products in each category. Let's see how we can use faceting to achieve such functionality.

How to do it...

  1. Let's start with the example data, which is going to be indexed and looks as follows:
    <add> <doc> <field name="id">1</field> <field name="name">First Solr Cookbook</field> <field name="category">Books</field> </doc> <doc> <field name="id">2</field> <field name="name">Second Solr Cookbook</field> <field name="category">Books And Tutorials</field> </doc> <doc> <field name="id">3</field> ...

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.